-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
30 additions
and
49 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
VITE_ZOO_DEV_TOKEN="your-token-from-dev.zoo.dev" # A dev API token from dev.zoo.dev | ||
VITE_API_BASE_URL=https://api.dev.zoo.dev | ||
VITE_SITE_BASE_URL=https://dev.zoo.dev | ||
PLAYWRIGHT_SESSION_COOKIE="your-token-from-dev.zoo.dev" | ||
VITE_TOKEN="your-token-from-dev.zoo.dev" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,10 @@ | ||
import { AUTH_COOKIE_NAME } from '$lib/cookies.js' | ||
import { error, redirect } from '@sveltejs/kit' | ||
import type { Models } from '@kittycad/lib' | ||
import { redirect } from '@sveltejs/kit' | ||
|
||
export const load = async ({ cookies, url, fetch }) => { | ||
const token = import.meta.env.PROD | ||
? cookies.get(AUTH_COOKIE_NAME) | ||
: import.meta.env.VITE_ZOO_DEV_TOKEN | ||
export const load = async ({ cookies, url }) => { | ||
const token = import.meta.env.PROD ? cookies.get(AUTH_COOKIE_NAME) : import.meta.env.VITE_TOKEN | ||
|
||
const currentUser = await fetch(import.meta.env.VITE_API_BASE_URL + '/user', { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}` | ||
} | ||
}) | ||
.then(async (res) => (await res.json()) as Models['User_type'] | Models['Error_type']) | ||
.catch((e) => { | ||
throw error(500, e) | ||
}) | ||
|
||
// Redirect to the dashboard if the user is already logged in | ||
if (currentUser && 'email' in currentUser) { | ||
if (token) { | ||
throw redirect(302, '/dashboard' + (url.search || '')) | ||
} else if (import.meta.env.DEV) { | ||
console.warn( | ||
'You might be using an invalid or expired token for your VITE_ZOO_DEV_TOKEN environment variable. Please check your .env file.' | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters