/**
 * The Hearth Auth Guard
 * Ensures all DF API routes require an authenticated session
 */

import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth/auth-options';
import { NextResponse } from 'next/server';

export async function requireDFAuth(): Promise<{ authorized: true; userId: string } | { authorized: false; response: NextResponse }> {
  const session = await getServerSession(authOptions);

  if (!session?.user?.id) {
    return {
      authorized: false,
      response: NextResponse.json(
        { error: 'Authentication required. Please log in to access The Hearth.' },
        { status: 401 }
      ),
    };
  }

  return { authorized: true, userId: session.user.id };
}
