-
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.
Revert "Try getting token from headers more directly, use locals for …
- Loading branch information
1 parent
0de04e1
commit 0100257
Showing
5 changed files
with
16 additions
and
11 deletions.
There are no files selected for viewing
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,7 +1,14 @@ | ||
import { AUTH_COOKIE_NAME } from '$lib/cookies.js' | ||
|
||
/** @type {import('./$types').LayoutData} */ | ||
export const load = async ({ locals }) => { | ||
export const load = async ({ locals, cookies }) => { | ||
const token = | ||
import.meta.env.MODE === 'production' | ||
? cookies.get(AUTH_COOKIE_NAME) | ||
: import.meta.env.VITE_TOKEN | ||
|
||
return { | ||
user: !locals.user || 'error_code' in locals.user ? undefined : locals.user, | ||
token: locals.token | ||
token | ||
} | ||
} |
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,8 +1,10 @@ | ||
import { paths } from '$lib/paths.js' | ||
import { AUTH_COOKIE_NAME } from '$lib/cookies.js' | ||
import { redirect } from '@sveltejs/kit' | ||
|
||
export const load = async ({ url, locals }) => { | ||
if (locals.token && locals.user) { | ||
throw redirect(302, paths.DASHBOARD + (url.search || '')) | ||
export const load = async ({ cookies, url }) => { | ||
const token = import.meta.env.PROD ? cookies.get(AUTH_COOKIE_NAME) : import.meta.env.VITE_TOKEN | ||
|
||
if (token) { | ||
throw redirect(302, '/dashboard' + (url.search || '')) | ||
} | ||
} |