import React from 'react';
import { useAuth } from '@/context/AuthContext';
import SignIn from '@/pages/SignIn';

/**
 * Blocks the app until the user has a valid Google session.
 * API routes remain protected server-side; this prevents browsing the UI while signed out.
 */
export default function RequireAuth({ children }) {
    const { phase, signedIn } = useAuth();

    if (phase === 'loading') {
        return <SignIn />;
    }

    if (!signedIn) {
        return <SignIn />;
    }

    return children;
}
