Skip to Content
⚠️Active Development Notice: TimeTiles is under active development. Information may be placeholder content or not up-to-date.

web


web / lib/hooks/use-auth-mutations

lib/hooks/use-auth-mutations

React Query hooks for authentication operations.

Provides request functions and React Query mutations for authentication operations, plus a query for the current user session.

Interfaces

CurrentUserResponse

Payload CMS /api/users/me response shape.

Properties

user

user: { \[key: string\]: unknown; id: number; email: string; _verified?: boolean; } | null


LoginInput

Input for the login mutation.

Properties

email

email: string

password

password: string


RegisterInput

Input for the register mutation.

Properties

email

email: string

password

password: string


ForgotPasswordInput

Input for the forgot-password mutation.

Properties

email

email: string


ResetPasswordInput

Input for the reset-password mutation.

Properties

token

token: string

password

password: string

Variables

authKeys

const authKeys: object

Type Declaration

currentUser

currentUser: readonly ["auth", "current-user"]

Functions

useCurrentUserQuery()

useCurrentUserQuery(options?): UseQueryResult<CurrentUserResponse, Error>

Fetch the current authenticated user via /api/users/me.

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: { \[key: string\]: unknown; id: number; email: string; _verified?: boolean; } | null


loginRequest()

loginRequest(input): Promise<LoginResponse>

Login via Payload CMS /api/users/login.

Uses raw fetch instead of fetchJson because the component inspects the response body for both success and error cases (Payload returns 4xx with a JSON body containing errors or message).

Parameters

input

LoginInput

Returns

Promise<LoginResponse>


registerRequest()

registerRequest(input): Promise<RegisterResponse>

Register a new user via /api/auth/register.

Uses raw fetch because the response shape differs from the standard fetchJson error-handling convention (uses error field, not HTTP status for some validation errors).

Parameters

input

RegisterInput

Returns

Promise<RegisterResponse>


forgotPasswordRequest()

forgotPasswordRequest(input): Promise<void>

Request a password-reset email via Payload CMS /api/users/forgot-password.

Always succeeds from the caller’s perspective to prevent email enumeration.

Parameters

input

ForgotPasswordInput

Returns

Promise<void>


resetPasswordRequest()

resetPasswordRequest(input): Promise<void>

Reset password via Payload CMS /api/users/reset-password.

Parameters

input

ResetPasswordInput

Returns

Promise<void>


logoutRequest()

logoutRequest(): Promise<void>

Logout via Payload CMS /api/users/logout.

Returns

Promise<void>


useLogoutMutation()

useLogoutMutation(): UseMutationResult<void, Error, void, unknown>

Returns

UseMutationResult<void, Error, void, unknown>


verifyEmailRequest()

verifyEmailRequest(token): Promise<void>

Verify email via Payload CMS /api/users/verify/:token.

Parameters

token

string

Returns

Promise<void>


useVerifyEmailMutation()

useVerifyEmailMutation(): UseMutationResult<void, Error, string, unknown>

Returns

UseMutationResult<void, Error, string, unknown>

Last updated on