Update user routing, added user authorization with JWT cookie management

This commit is contained in:
Hannah dagemark 2026-09-14 23:09:11 +02:00
commit f055e77eea
7 changed files with 97 additions and 10 deletions

View file

@ -0,0 +1,23 @@
import { cookies } from "next/headers";
import { cache } from "react";
import "server-only";
import { getCurrentUser } from "../api/helpers/users";
import { User } from "../api/types";
export const verifySession = cache(async () => {
const cookie = (await cookies()).get("access_token")?.value;
if (!cookie) {
return { isAuthed: false };
}
const response = await getCurrentUser();
if (response.status == 401) {
return { isAuthed: false };
}
const user = (await response.json()) as User;
return {
isAuthed: true,
surface_auth_level: user.authority,
username: user.username,
};
});