Update user routing, added user authorization with JWT cookie management
This commit is contained in:
parent
662b26ad47
commit
f055e77eea
7 changed files with 97 additions and 10 deletions
23
lib/server_functions/dataAccessLayer.ts
Normal file
23
lib/server_functions/dataAccessLayer.ts
Normal 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,
|
||||
};
|
||||
});
|
||||
Loading…
Reference in a new issue