Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 36x 454x 454x 2x 452x | // 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;
};
|