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
onSuccess?: (data: CallbackResult) => void
onError?: (error: OpenfortError) => void
onSettled?: (data: CallbackResult | undefined | null, error: OpenfortError | null) => void
throwOnError?: boolean
logoutOnError?: boolean
recoverWalletAutomatically?: boolean
}
type CallbackResult =
| (StoreCredentialsResult & { type: 'storeCredentials' })
| (EmailVerificationResult & { type: 'verifyEmail' })
type OpenfortError = {
message: string
type: OpenfortErrorType
data: { [key: string]: any }
name: string
}
enum OpenfortErrorType {
AUTHENTICATION_ERROR = "AUTHENTICATION_ERROR",
WALLET_ERROR = "WALLET_ERROR",
CONFIGURATION_ERROR = "CONFIGURATION_ERROR",
VALIDATION_ERROR = "VALIDATION_ERROR",
}Response
type Response = UseAuthCallbackReturn
type UseAuthCallbackReturn = {
provider: AuthProvider | null
email: string | null
verifyEmail: (options: VerifyEmailOptions) => Promise<EmailVerificationResult>
storeCredentials: (options: StoreCredentialsOptions) => Promise<StoreCredentialsResult>
isLoading: boolean
isError: boolean
isSuccess: boolean
error?: OpenfortError | null
}
type StoreCredentialsResult = {
user?: AuthPlayerResponse
wallet?: UserWallet
error?: OpenfortError
}
type EmailVerificationResult = {
email?: string
error?: OpenfortError
}
type StoreCredentialsOptions = {
player: string
accessToken: string
refreshToken: string
onSuccess?: (data: StoreCredentialsResult) => void
onError?: (error: OpenfortError) => void
onSettled?: (data: StoreCredentialsResult | undefined | null, error: OpenfortError | null) => void
throwOnError?: boolean
logoutOnError?: boolean
recoverWalletAutomatically?: boolean
}
type VerifyEmailOptions = {
email: string
state: string
onSuccess?: (data: EmailVerificationResult) => void
onError?: (error: OpenfortError) => void
onSettled?: (data: EmailVerificationResult | undefined | null, error: OpenfortError | null) => void
throwOnError?: boolean
}
enum AuthProvider {
EMAIL = "EMAIL",
WALLET = "WALLET",
GOOGLE = "GOOGLE",
FACEBOOK = "FACEBOOK",
DISCORD = "DISCORD",
TWITTER = "TWITTER",
EPIC_GAMES = "EPIC_GAMES",
APPLE = "APPLE",
CUSTOM = "CUSTOM",
}
type UserWallet = {
address: `0x${string}`
connectorType?: string
walletClientType?: string
id: string
isAvailable: boolean
isActive?: boolean
isConnecting?: boolean
recoveryMethod?: RecoveryMethod
accountId?: string
accountType?: AccountTypeEnum
ownerAddress?: `0x${string}`
implementationType?: string
createdAt?: number
salt?: string
}
type AuthPlayerResponse = {
player?: {
id: string
object: 'player'
name: string
description?: string
createdAt: number
metadata?: { [key: string]: any }
transactionIntents?: any[]
accounts?: any[]
}
id: string
object: 'player'
createdAt: number
linkedAccounts: LinkedAccount[]
}
type LinkedAccount = {
provider: string
email?: string
address?: string
externalUserId?: string
verified?: boolean
disabled: boolean
walletClientType?: string
connectorType?: string
updatedAt?: number
metadata?: { [key: string]: any }
}
enum RecoveryMethod {
AUTOMATIC = "automatic",
PASSWORD = "password",
PASSKEY = "passkey",
}
enum AccountTypeEnum {
SMART_ACCOUNT = "Smart Account",
EOA = "Externally Owned Account",
}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
}