import { useContext } from 'react';
import { AuthContext, type AuthContextValue } from './AuthProvider';

/** Consume the auth context. Must be used inside an <AuthProvider>. */
export function useAuth(): AuthContextValue {
	const value = useContext( AuthContext );
	if ( ! value ) {
		throw new Error( 'useAuth must be used within an <AuthProvider>' );
	}
	return value;
}
