Organize/lib/auth-helpers.ts

13 lines
317 B
TypeScript

import "server-only";
import { auth } from "@/auth";
/** Returns the current session's user id, or throws if unauthenticated. */
export async function requireUserId(): Promise<string> {
const session = await auth();
if (!session?.user?.id) {
throw new Error("Unauthorized");
}
return session.user.id;
}