Function: useAuth()¶
useAuth():
Ctx
Defined in: src/auth/AuthContext.tsx:169
useAuth Hook
React hook for accessing authentication state and methods from any component within the AuthProvider tree. Provides current user, login/logout functions, and reload capability.
Returns¶
Ctx
Auth context value with state and methods
Throws¶
Error if called outside AuthProvider
Example¶
function MyComponent() {
const { state, login, logout } = useAuth();
if (state.status === 'authenticated') {
return <div>Welcome {state.user.email}</div>;
}
return <LoginForm onSubmit={login} />;
}