// src/hooks/useAuth.tsx
import { useContext } from 'react';
import { AuthContext, AuthContextType, AuthStatus } from '../contexts/AuthContext';

// Re-export the AuthStatus type so other components can import it from this hook file.
export type { AuthStatus };

/**
 * Custom hook to access the authentication context.
 * This is what components will use to get auth state and methods.
 * It also ensures that it's used within an AuthProvider.
 */
export const useAuth = (): AuthContextType => {
  const context = useContext(AuthContext);
  if (context === undefined) {
    throw new Error('useAuth must be used within an AuthProvider');
  }
  return context;
};