ReactHooks
useAuth
Convenience session snapshot built on useCurrentUser.
Overview
useAuth wraps useCurrentUser({ autoLoad: true }) and returns { isLoading, isSignedIn, isEmailVerified, user, error, refresh } for simple conditional UI and gates like Show.
Signature
export function useAuth()Parameters
This hook takes no parameters.
Returns
| Field | Type | Description |
|---|---|---|
isLoading | boolean | True while the initial me() (or a refresh) is in flight. |
isSignedIn | boolean | True when user is non-null. |
isEmailVerified | boolean | True when the signed-in user has emailVerified === true. |
user | ExternalUser | null | Current user from the last successful me() response. |
error | string | null | Error string from useCurrentUser when the session lookup fails. |
refresh | () => Promise<void> | Re-runs auth.me() (same as useCurrentUser). |
Example
"use client"
import { useAuth } from "@/components/simpleauth"
export function SessionBadge() {
const { isLoading, isSignedIn, isEmailVerified, user } = useAuth()
if (isLoading) return <p>Loading…</p>
if (!isSignedIn) return <p>Guest</p>
return (
<p>
{user?.email}
{isEmailVerified ? " (verified)" : " (unverified)"}
</p>
)
}How it works
- Delegates to
useCurrentUserwithautoLoad: trueso the first paint triggers a session read. - Derives
isEmailVerifiedfromuser?.emailVerified === true.
Shipped by
npx @simpleauthjs/react add sessionSource
components/simpleauth/hooks/use-auth.ts
"use client"
import type { ExternalUser } from "@simpleauthjs/core"
import { useCurrentUser } from "./use-current-user"
export function useAuth() {
const { data, isLoading, error, refresh } = useCurrentUser({ autoLoad: true })
const user: ExternalUser | null = data?.user ?? null
const isSignedIn = Boolean(user)
const isEmailVerified = user?.emailVerified === true
return {
isLoading,
isSignedIn,
isEmailVerified,
user,
error,
refresh,
}
}