first commit

This commit is contained in:
amirhosein.ashourloo
2026-09-02 17:03:23 +03:30
commit 1bd131e9d8
91 changed files with 11211 additions and 0 deletions
+19
View File
@@ -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;
}