web / lib/hooks/use-auth-queries
lib/hooks/use-auth-queries
React Query hooks for authentication state.
Provides the current user query and derived auth state booleans. Separated from mutation hooks to enforce clear module boundaries.
Interfaces
CurrentUserResponse
Payload CMS /api/users/me response shape.
Properties
user
user:
User|null
Variables
authKeys
constauthKeys:object
Type Declaration
currentUser
currentUser: readonly [
"auth","current-user"]
Functions
fetchCurrentUser()
fetchCurrentUser():
Promise<CurrentUserResponse>
Fetch the current user from /api/users/me.
Swallows expected auth failures (401/403) as { user: null }.
Rethrows transport and server errors so React Query surfaces them.
Returns
Promise<CurrentUserResponse>
useCurrentUserQuery()
useCurrentUserQuery(
options?):UseQueryResult<CurrentUserResponse,Error>
Query hook for the current authenticated user.
Disabled by default — callers opt in via enabled.
Parameters
options?
enabled?
boolean
Returns
UseQueryResult<CurrentUserResponse, Error>
useAuthState()
useAuthState():
object
Derive auth booleans from the current user query.
Single source of truth for client-side auth state. Components should use this instead of maintaining their own auth state copies.
Returns
object
isAuthenticated
isAuthenticated:
boolean
isEmailVerified
isEmailVerified:
boolean
userId
userId:
number|null
isLoading
isLoading:
boolean
user
user:
User|null