// Server-side auth helpers built on top of Clerk.

import { auth } from '@clerk/nextjs/server';
import { redirect } from 'next/navigation';

/** Get the current user's Clerk id. Redirects to /sign-in when absent. */
export async function requireUserId(): Promise<string> {
  const { userId } = await auth();
  if (!userId) redirect('/sign-in');
  return userId;
}

/** Get the current user's Clerk id, or null. Does NOT redirect. */
export async function getUserId(): Promise<string | null> {
  const { userId } = await auth();
  return userId;
}
