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') {
        // OAuth completed
      } else if (result.type === 'verifyEmail') {
        // Email verified
      }
    },
  });
 
  if (isLoading) return <div>Processing...</div>;
  if (isSuccess) return <div>Success!</div>;
 
  return null;
}

Return type

type UseAuthCallbackReturn = {
  provider: AuthProvider | null  // Detected OAuth provider from URL
  email: string | null           // Email from verification URL
  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 AuthProvider {
  EMAIL = "EMAIL",
  WALLET = "WALLET",
  GOOGLE = "GOOGLE",
  FACEBOOK = "FACEBOOK",
  DISCORD = "DISCORD",
  TWITTER = "TWITTER",
  EPIC_GAMES = "EPIC_GAMES",
  APPLE = "APPLE",
  CUSTOM = "CUSTOM",
}

Parameters

Hook options

type UseAuthCallbackOptions = {
  enabled?: boolean  // Auto-process URL params (default: true)
  onSuccess?: (data: CallbackResult) => void
  onError?: (error: OpenfortError) => void
}