mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 05:05:38 -04:00
- Overhaul `lib/auth/server.ts` and `lib/auth/session.ts`; update all API routes and server actions to use the revised session pattern - Refactor server actions (settings, titles, watchlist, setup) for consistency with new auth layer - Extract `SetupForm` into its own client component with `useActionState`, animated steps, and copyable env snippets - Move landing page redirect logic into `app/page.tsx`; slim down `LandingPage` component - Add `proxy.ts` for local dev proxying - Minor cleanup to `NavBar`, `MobileTabBar`, and `TitleCard`
26 lines
803 B
TypeScript
26 lines
803 B
TypeScript
import { headers } from "next/headers";
|
|
import { cache } from "react";
|
|
import { auth } from "./server";
|
|
|
|
/**
|
|
* Cached session getter — deduplicated per request via React.cache().
|
|
* Use this instead of calling auth.api.getSession() directly in server
|
|
* components, route handlers, and server actions to avoid redundant
|
|
* session lookups within a single render pass.
|
|
*/
|
|
export const getSession = cache(async () => {
|
|
return auth.api.getSession({ headers: await headers() });
|
|
});
|
|
|
|
export async function requireSession() {
|
|
const session = await getSession();
|
|
if (!session) throw new Error("Unauthorized");
|
|
return session;
|
|
}
|
|
|
|
export async function requireAdmin() {
|
|
const session = await requireSession();
|
|
if (session.user.role !== "admin") throw new Error("Forbidden");
|
|
return session;
|
|
}
|