23 lines
620 B
TypeScript
23 lines
620 B
TypeScript
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,
|
|
};
|
|
});
|