import "server-only"; import { getCurrentUser } from "@/lib/pb/server"; import { AccessError, type Session } from "@/lib/auth/access"; /** The current session, or null when signed out. */ export async function getSession(): Promise { const user = await getCurrentUser(); if (!user) return null; return { userId: user.id, role: user.role, clientId: user.client || null, }; } /** The current session, or throw a 401. For route handlers. */ export async function requireSession(): Promise { const session = await getSession(); if (!session) throw new AccessError("Not signed in", 401); return session; }