Skip to content

useAuthCallback

Handle OAuth and email verification redirects by parsing query parameters and delegating to useOAuth / useEmailAuth automatically.

Request

type Request = {
  hook: 'useAuthCallback',
  params: [options?: UseAuthCallbackOptions]
}
 
type UseAuthCallbackOptions = {
  enabled?: boolean
} & OpenfortHookOptions<CallbackResult> & CreateWalletPostAuthOptions
 
type CallbackResult =
  | (StoreCredentialsResult & { type: 'storeCredentials' })
  | (EmailVerificationResult & { type: 'verifyEmail' })
 
type CreateWalletPostAuthOptions = {
  logoutOnError?: boolean
  recoverWalletAutomatically?: boolean
}
 
type OpenfortHookOptions<T> = {
  onSuccess?: (data: T) => void
  onError?: (error: import("@openfort/react").OpenfortError) => void
  onSettled?: (data: T | undefined | null, error: import("@openfort/react").OpenfortError | null) => void
  throwOnError?: boolean
}

Response

type Response = UseAuthCallbackReturn
 
type UseAuthCallbackReturn = {
  provider: import("@openfort/react").AuthProvider | null
  email: string | null
  verifyEmail: (options: VerifyEmailOptions) => Promise<EmailVerificationResult>
  storeCredentials: (options: StoreCredentialsOptions) => Promise<StoreCredentialsResult>
  isLoading: boolean
  isError: boolean
  isSuccess: boolean
  error?: import("@openfort/react").OpenfortError | null
}
 
type StoreCredentialsResult = {
  user?: import("@openfort/openfort-js").AuthPlayerResponse
  wallet?: import("@openfort/react").UserWallet
  error?: import("@openfort/react").OpenfortError
}
 
type EmailVerificationResult = {
  email?: string
  error?: import("@openfort/react").OpenfortError
}
 
type StoreCredentialsOptions = {
  player: string
  accessToken: string
  refreshToken: string
} & OpenfortHookOptions<StoreCredentialsResult> & CreateWalletPostAuthOptions
 
type VerifyEmailOptions = {
  email: string
  state: string
} & OpenfortHookOptions<EmailVerificationResult>

Example

import { useAuthCallback } from "@openfort/react"
 
function OAuthCallbackPage() {
  const {
    provider,
    email,
    verifyEmail,
    storeCredentials,
    isLoading,
    isError,
    isSuccess,
    error,
  } = useAuthCallback({
    enabled: true,
    throwOnError: true,
    onSuccess: () => {},
    onError: () => {},
    onSettled: () => {},
  })
 
  // When `enabled` is true the hook automatically inspects the URL.
  // You can call `verifyEmail` or `storeCredentials` manually as well.
 
  return null
}