Skip to content

Commit

Permalink
Add debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock committed Sep 18, 2024
1 parent c68f039 commit ad9ded1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pages/dev/security/+guard.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { render, redirect } from "vike/abort";
import { ingestPrefix } from "@macrostrat-web/settings";
import { GuardAsync } from "vike/dist/esm/shared/page-configs/Config";

export const guard = (pageContext) => {
export const guard: GuardAsync = async (
pageContext
): ReturnType<GuardAsync> => {
const { user } = pageContext;

console.log(user);

if (user === undefined) {
// Render the login page while preserving the URL. (This is novel technique
// which we explain down below.)
Expand Down
4 changes: 4 additions & 0 deletions server/vike-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ async function getUserFromCookie(request: Request) {
const authHeader = request.cookies?.Authorization;
const secret = new TextEncoder().encode(process.env.SECRET_KEY);
const jwt = authHeader.substring(7, authHeader.length);

console.log(authHeader, jwt, request.cookies);
// We probably don't need to verify the JWT on each request
user = (await jose.jwtVerify(jwt, secret)).payload;

console.log(user);
} catch (e) {
// I don't care if it fails, it just means the user isn't logged in
}
Expand Down

0 comments on commit ad9ded1

Please sign in to comment.