import { createContext, useContext, useEffect, useState, type ReactNode } from 'react'; import type { Session } from '@supabase/supabase-js'; import { supabase } from '../lib/supabase'; type AuthContextValue = { session: Session | null; loading: boolean; }; const AuthContext = createContext({ session: null, loading: true }); export function AuthProvider({ children }: { children: ReactNode }) { const [session, setSession] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const { data } = supabase.auth.onAuthStateChange((_event, s) => { setSession(s); setLoading(false); }); return () => { data.subscription.unsubscribe(); }; }, []); return {children}; } export function useAuth() { return useContext(AuthContext); }