first commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { getMe, safe } from "./api";
|
||||
import { AUTH_TOKEN_COOKIE } from "./config";
|
||||
import type { AuthUser } from "./types";
|
||||
|
||||
export { displayName, isAdmin } from "./authUser";
|
||||
|
||||
// Server-side "am I logged in" check for the header/account menu. See the
|
||||
// AUTH_TOKEN_COOKIE comment in config.ts for the one external dependency
|
||||
// this relies on. Resolves to null whenever the cookie is absent or /auth/me
|
||||
// fails — never throws, so a missing session degrades to the anonymous view.
|
||||
export async function getSession(): Promise<AuthUser | null> {
|
||||
const store = await cookies();
|
||||
const token = store.get(AUTH_TOKEN_COOKIE)?.value;
|
||||
if (!token) return null;
|
||||
|
||||
const result = await safe(getMe(token), null);
|
||||
return result?.user ?? null;
|
||||
}
|
||||
Reference in New Issue
Block a user