import type { 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 EmailAuthResult = { error?: OpenfortError; user?: User; wallet?: EthereumUserWallet | SolanaUserWallet; requiresEmailVerification?: boolean; }; type SignInEmailOptions = { email: string; password: string; emailVerificationRedirectTo?: string; } & OpenfortHookOptions & CreateWalletPostAuthOptions; type SignUpEmailOptions = { email: string; password: string; name?: string; emailVerificationRedirectTo?: string; } & OpenfortHookOptions & CreateWalletPostAuthOptions; type RequestResetPasswordOptions = { email: string; emailVerificationRedirectTo?: string; } & OpenfortHookOptions; type ResetPasswordOptions = { email: string; password: string; state: string; } & OpenfortHookOptions; type LinkEmailOptions = { email: string; emailVerificationRedirectTo?: string; } & OpenfortHookOptions; type VerifyEmailOptions = { email: string; state: string; } & OpenfortHookOptions; export type EmailVerificationResult = { email?: string; error?: OpenfortError; }; type UseEmailHookOptions = { emailVerificationRedirectTo?: string; } & OpenfortHookOptions & CreateWalletPostAuthOptions; /** * Hook for email-based authentication operations * * This hook manages email authentication flows including sign-in, sign-up, password reset, * email verification, and email linking. It handles both password and passwordless authentication * and automatically manages wallet connection after successful authentication. * * @param hookOptions - Optional configuration with callback functions and authentication options * @returns Current authentication state with email auth actions * * @example * ```tsx * const emailAuth = useEmailAuth({ * onSignInEmailSuccess: (result) => console.log('Signed in:', result.user), * onSignInEmailError: (error) => console.error('Sign-in failed:', error), * emailVerificationRedirectTo: 'https://yourapp.com/verify', * recoverWalletAutomatically: true, * }); * * // Sign up with email and password * await emailAuth.signUpEmail({ * email: 'user@example.com', * password: 'securePassword123', * name: 'John Doe', * }); * * // Sign in with email and password * await emailAuth.signInEmail({ * email: 'user@example.com', * password: 'securePassword123', * }); * * // Request password reset * await emailAuth.requestResetPassword({ * email: 'user@example.com', * }); * * // Reset password with state token * await emailAuth.resetPassword({ * email: 'user@example.com', * password: 'newPassword123', * state: 'reset-token-from-email', * }); * * // Verify email with state token * await emailAuth.verifyEmail({ * email: 'user@example.com', * state: 'verification-token-from-email', * }); * * // Link email to existing authenticated account * await emailAuth.linkEmail({ * email: 'secondary@example.com', * password: 'password123', * }); * * // Check authentication state * if (emailAuth.isLoading) { * console.log('Processing authentication...'); * } else if (emailAuth.isError) { * console.error('Authentication error:', emailAuth.error); * } else if (emailAuth.isSuccess) { * console.log('Authentication successful'); * } * * // Handle email verification requirement * if (emailAuth.requiresEmailVerification) { * console.log('Please check your email to verify your account'); * } * ``` */ export declare const useEmailAuth: (hookOptions?: UseEmailHookOptions) => { requiresEmailVerification: boolean; isAwaitingInput: boolean; isLoading: boolean; isError: boolean; isSuccess: boolean; error: OpenfortError | null | undefined; signInEmail: (options: SignInEmailOptions) => Promise; signUpEmail: (options: SignUpEmailOptions) => Promise; verifyEmail: (options: VerifyEmailOptions) => Promise; linkEmail: (options: LinkEmailOptions) => Promise; requestResetPassword: (options: RequestResetPasswordOptions) => Promise; resetPassword: (options: ResetPasswordOptions) => Promise; reset: () => void; }; export {};