-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61c19b8
commit 50846ce
Showing
96 changed files
with
814 additions
and
847 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,40 +1,40 @@ | ||
import { env as privateEnv } from "$env/dynamic/private"; | ||
import { env as publicEnv } from "$env/dynamic/public"; | ||
import { type Handle, error } from "@sveltejs/kit"; | ||
import jwt from "jsonwebtoken"; | ||
import type { IProfile } from "$lib/types"; | ||
import { env as privateEnv } from "$env/dynamic/private" | ||
import { env as publicEnv } from "$env/dynamic/public" | ||
import type { IProfile } from "$lib/types" | ||
import { type Handle, error } from "@sveltejs/kit" | ||
import jwt from "jsonwebtoken" | ||
|
||
export const handle: Handle = async ({ event, resolve }) => { | ||
const cookieKey = publicEnv.PUBLIC_COOKIE_KEY | ||
const jwtSecret = privateEnv.PRIVATE_JWT_SECRET_KEY | ||
|
||
if (jwtSecret && cookieKey && event.cookies.get(cookieKey)) { | ||
const token = event.cookies.get(cookieKey); | ||
const token = event.cookies.get(cookieKey) | ||
if (!token) { | ||
event.locals.profile = null; | ||
return resolve(event); | ||
event.locals.profile = null | ||
return resolve(event) | ||
} | ||
|
||
try { | ||
const payload = jwt.verify(token, jwtSecret); | ||
const payload = jwt.verify(token, jwtSecret) | ||
if (typeof payload === "string") { | ||
error(400, "Something went wrong"); | ||
error(400, "Something went wrong") | ||
} | ||
if (!payload.profile) { | ||
error(400, "Token is not valid"); | ||
error(400, "Token is not valid") | ||
} | ||
|
||
const profile = payload.profile as IProfile | ||
|
||
event.locals.profile = { | ||
...profile | ||
}; | ||
...profile, | ||
} | ||
} catch (error) { | ||
if (error instanceof jwt.TokenExpiredError) { | ||
event.cookies.delete(cookieKey, { path: "/" }) | ||
} | ||
} | ||
} | ||
|
||
return resolve(event); | ||
}; | ||
return resolve(event) | ||
} |
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
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
Oops, something went wrong.