import type { OAuthProvider, User } from '@openfort/openfort-js'; import { OpenfortError } from '../../../core/errors'; import type { OpenfortHookOptions } from '../../../types'; import type { EthereumUserWallet, SolanaUserWallet } from '../walletTypes'; import { type CreateWalletPostAuthOptions } from './useConnectToWalletPostAuth'; type InitializeOAuthOptions = { provider: OAuthProvider; redirectTo?: string; } & OpenfortHookOptions; type InitOAuthReturnType = { error?: OpenfortError; }; export type StoreCredentialsResult = { user?: User; wallet?: EthereumUserWallet | SolanaUserWallet; error?: OpenfortError; }; type StoreCredentialsOptions = { userId: string; token: string; } & OpenfortHookOptions & CreateWalletPostAuthOptions; type AuthHookOptions = { redirectTo?: string; } & OpenfortHookOptions & CreateWalletPostAuthOptions; /** * Hook for OAuth-based authentication operations * * This hook manages OAuth authentication flows including provider initialization, * credential storage, and wallet connection after successful OAuth authentication. * It supports multiple OAuth providers and handles the complete authentication lifecycle * from provider selection to wallet setup. * * @param hookOptions - Optional configuration with callback functions and authentication options * @returns Current OAuth authentication state and actions * * @example * ```tsx * const oauth = useOAuth({ * onInitializeOAuthSuccess: (result) => console.log('OAuth initialized'), * onInitializeOAuthError: (error) => console.error('OAuth init failed:', error), * onStoreCredentialsSuccess: (result) => console.log('Authenticated:', result.user), * redirectTo: 'https://yourapp.com/auth/callback', * recoverWalletAutomatically: true, * }); * * // Initialize OAuth with a provider * const handleGoogleAuth = async () => { * await oauth.initOAuth({ * provider: OAuthProvider.GOOGLE, * redirectTo: 'https://yourapp.com/auth/callback', * }); * }; * * const handleDiscordAuth = async () => { * await oauth.initOAuth({ * provider: OAuthProvider.DISCORD, * }); * }; * * // Store OAuth credentials (typically called from callback handler) * const handleStoreCredentials = async () => { * await oauth.storeCredentials({ * player: 'player-id-from-callback', * accessToken: 'access-token-from-callback', * refreshToken: 'refresh-token-from-callback', * }); * }; * * // Link OAuth provider to existing authenticated account * const handleLinkOAuth = async () => { * await oauth.linkOauth({ * provider: OAuthProvider.GOOGLE, * redirectTo: 'https://yourapp.com/auth/callback', * }); * }; * * // Check authentication state * if (oauth.isLoading) { * console.log('Processing OAuth authentication...'); * } else if (oauth.isError) { * console.error('OAuth error:', oauth.error); * } else if (oauth.isSuccess) { * console.log('OAuth authentication successful'); * } * * // Example usage in component with multiple providers * return ( *
* * *
* ); * ``` */ export declare const useOAuth: (hookOptions?: AuthHookOptions) => { isLoading: boolean; isError: boolean; isSuccess: boolean; error: OpenfortError | null | undefined; initOAuth: (options: InitializeOAuthOptions) => Promise; linkOauth: (options: InitializeOAuthOptions) => Promise; storeCredentials: ({ userId, token, ...options }: StoreCredentialsOptions) => Promise; }; export {};