Skip to content

Commit

Permalink
Add auth logging
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock committed Sep 18, 2024
1 parent cecc8f0 commit 092b40e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/vike-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ export async function vikeHandler<
Context extends Record<string | number | symbol, unknown>
>(request: Request, context?: Context): Promise<Response> {
const cookies = getCookies(request);

console.log(cookies);

const user = await getUserFromCookie(cookies);

console.log(user);

const pageContextInit = {
...context,
urlOriginal: request.url,
Expand Down Expand Up @@ -41,10 +46,13 @@ async function getUserFromCookie(cookies: Record<string, string>) {
const authHeader = cookies?.Authorization;
const secret = new TextEncoder().encode(process.env.SECRET_KEY);
const jwt = authHeader.substring(7, authHeader.length);

console.log(cookies, jwt);
// We probably don't need to verify the JWT on each request
user = (await jose.jwtVerify(jwt, secret)).payload;
} catch (e) {
// I don't care if it fails, it just means the user isn't logged in
console.log(e);
}

if (!isProduction && process.env.DEV_ENABLE_AUTH !== "true") {
Expand Down

0 comments on commit 092b40e

Please sign in to comment.