import { UIAuthProvider } from '../../../components/Openfort/types.js'; import { type OpenfortError } from '../../../errors/base.js'; import type { OpenfortHookOptions } from '../../../types.js'; import type { CreateWalletPostAuthOptions } from './useConnectToWalletPostAuth.js'; import { type EmailVerificationResult } from './useEmailAuth.js'; import { type StoreCredentialsResult } from './useOAuth.js'; type CallbackResult = (StoreCredentialsResult & { type: 'storeCredentials'; }) | (EmailVerificationResult & { type: 'verifyEmail'; /** * Whether the SDK confirmed the verification itself. * * `true` when the callback carried a `state` token the SDK exchanged. * `false` when the link arrived with no token at all — the endpoint * signals success by the *absence* of an `error` parameter, which anyone * who can open a URL can reproduce. Re-check server-side before granting * anything on the strength of a `false` result. */ confirmed: boolean; }); type UseAuthCallbackOptions = { enabled?: boolean; } & OpenfortHookOptions & CreateWalletPostAuthOptions; /** * Hook for handling authentication callbacks from OAuth providers and email verification * * This hook automatically processes authentication callbacks when the page loads with * authentication parameters in the URL. It handles both OAuth provider callbacks * (with access tokens) and email verification callbacks (with state tokens). * The hook captures and removes callback parameters from the URL before it calls the * appropriate authentication method. * * @param options - Optional configuration with callback functions and authentication options * @returns Current callback processing state and extracted information * * @example * ```tsx * const authCallback = useAuthCallback({ * enabled: true, * onSuccess: (result) => { * if (result.type === 'storeCredentials') { * console.log('OAuth callback processed:', result.user); * } else if (result.type === 'verifyEmail') { * console.log('Email verified:', result.email); * } * }, * onError: (error) => console.error('Callback processing failed:', error), * recoverWalletAutomatically: true, * }); * * // Check callback processing state * if (authCallback.isLoading) { * console.log('Processing authentication callback...'); * } else if (authCallback.isError) { * console.error('Callback error:', authCallback.error); * } else if (authCallback.isSuccess) { * console.log('Callback processed successfully'); * } * * // Access extracted information * if (authCallback.provider) { * console.log('Authentication provider:', authCallback.provider); * } * * if (authCallback.email) { * console.log('Email from callback:', authCallback.email); * } * * // Manually trigger verification (if needed) * const handleManualVerification = async () => { * await authCallback.verifyEmail({ * email: 'user@example.com', * state: 'verification-token', * }); * }; * // Manually trigger storing credentials (if needed) * const handleManualStoreCredentials = async () => { * await authCallback.storeCredentials({ * userId: 'player-id', * token: 'access-token', * }); * }; * ``` */ export declare const useAuthCallback: ({ enabled, ...hookOptions }?: UseAuthCallbackOptions) => { email: string | null; provider: UIAuthProvider | null; verifyEmail: (options: { email: string; state: string; } & OpenfortHookOptions) => Promise; storeCredentials: ({ userId, token, ...options }: { userId: string; token: string; } & OpenfortHookOptions & CreateWalletPostAuthOptions) => Promise; isLoading: boolean; isError: boolean; isSuccess: boolean; error: OpenfortError | null | undefined; }; export {};