-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: centralize JWT verification
- Loading branch information
1 parent
1973105
commit dfe2383
Showing
5 changed files
with
13 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
import { JWT_SECRET } from '$env/static/private' | ||
import { redirect } from '@sveltejs/kit' | ||
import jwt from 'jsonwebtoken' | ||
|
||
export const load = async ({ locals: { getSession } }) => { | ||
const session = await getSession() | ||
|
||
if (!session) redirect(307, '/auth') | ||
|
||
/* Ensures the session, sourced from a cookie, is not fake. See README for details. */ | ||
jwt.verify(session.access_token, JWT_SECRET, (err) => { if (err) redirect(307, '/auth') }) | ||
} |
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,14 +1,9 @@ | ||
import { JWT_SECRET } from '$env/static/private' | ||
import { redirect } from '@sveltejs/kit' | ||
import jwt from 'jsonwebtoken' | ||
|
||
export const load = async ({ locals: { getSession } }) => { | ||
const session = await getSession() | ||
|
||
if (!session) redirect(307, '/auth') | ||
|
||
/* Ensures the session, sourced from a cookie, is not fake. See README for details. */ | ||
jwt.verify(session.access_token, JWT_SECRET, (err) => { if (err) redirect(307, '/auth') }) | ||
|
||
return { session } | ||
} |
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,12 +1,7 @@ | ||
import { JWT_SECRET } from '$env/static/private' | ||
import { redirect } from '@sveltejs/kit' | ||
import jwt from 'jsonwebtoken' | ||
|
||
export const load = async ({ locals: { getSession } }) => { | ||
const session = await getSession() | ||
|
||
if (!session) redirect(307, '/auth') | ||
|
||
/* Ensures the session, sourced from a cookie, is not fake. See README for details. */ | ||
jwt.verify(session.access_token, JWT_SECRET, (err) => { if (err) redirect(307, '/auth') }) | ||
} |
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,14 +1,9 @@ | ||
import { JWT_SECRET } from '$env/static/private' | ||
import { redirect } from '@sveltejs/kit' | ||
import jwt from 'jsonwebtoken' | ||
|
||
export const load = async ({ locals: { getSession } }) => { | ||
const session = await getSession() | ||
|
||
if (!session) redirect(307, '/auth') | ||
|
||
/* Ensures the session, sourced from a cookie, is not fake. See README for details. */ | ||
jwt.verify(session.access_token, JWT_SECRET, (err) => { if (err) redirect(307, '/auth') }) | ||
|
||
return { session } | ||
} |