Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

useAuthCallback

Handle OAuth and email verification redirects by parsing query parameters automatically.

Usage

import { useAuthCallback } from '@openfort/react';
 
function CallbackPage() {
  const { provider, email, isLoading, isSuccess, error } = useAuthCallback({
    enabled: true,
    onSuccess: (result) => {
      if (result.type === 'storeCredentials') {
        // Handle successful OAuth authentication.
      } else if (result.type === 'verifyEmail') {
        // Handle successful email verification.
      }
    },
  });
 
  if (isLoading) return <div>Processing...</div>;
  if (isSuccess) return <div>Success!</div>;
 
  return null;
}

Return type

type UseAuthCallbackReturn = {
  // Detected auth provider from URL.
  provider: UIAuthProvider | null
  // Email from verification URL.
  email: string | null
  verifyEmail(options: VerifyEmailOptions): Promise<EmailVerificationResult>
  storeCredentials(options: StoreCredentialsOptions): Promise<StoreCredentialsResult>
  isLoading: boolean
  isError: boolean
  isSuccess: boolean
  error?: OpenfortError | null
}
 
type CallbackResult =
  | (StoreCredentialsResult & { type: 'storeCredentials' })
  | (EmailVerificationResult & { type: 'verifyEmail' })
 
enum UIAuthProvider {
  GOOGLE = 'google',
  TWITTER = 'twitter',
  FACEBOOK = 'facebook',
  DISCORD = 'discord',
  APPLE = 'apple',
  EMAIL_PASSWORD = 'emailPassword',
  EMAIL_OTP = 'emailOtp',
  PHONE = 'phone',
  WALLET = 'wallet',
  GUEST = 'guest',
}

Parameters

Hook options

type UseAuthCallbackOptions = {
  // Automatically process URL parameters. Defaults to true.
  enabled?: boolean
  // Log out the user if wallet recovery fails. Defaults to true.
  logoutOnError?: boolean
  // Automatically recover the wallet after authentication. Defaults to true.
  recoverWalletAutomatically?: boolean
  onSuccess?: (data: CallbackResult) => void
  onError?: (error: OpenfortError) => void
}
Copyright © 2023-present Alamas Labs, Inc