useEmailAuth
Handle email/password authentication: sign in, sign up, password reset, and email verification.
Usage
import { useEmailAuth } from '@openfort/react';
function LoginForm() {
const { signInEmail, signUpEmail, isLoading } = useEmailAuth();
const handleLogin = async (email: string, password: string) => {
const { error, user, requiresEmailVerification } = await signInEmail({ email, password });
if (requiresEmailVerification) {
// Show a message asking the user to verify their email.
}
};
return null;
}Return type
type UseEmailAuthReturn = {
signInEmail(options: SignInEmailOptions): Promise<EmailAuthResult>
signUpEmail(options: SignUpEmailOptions): Promise<EmailAuthResult>
verifyEmail(options: VerifyEmailOptions): Promise<EmailVerificationResult>
linkEmail(options: LinkEmailOptions): Promise<EmailAuthResult>
requestResetPassword(options: RequestResetPasswordOptions): Promise<EmailAuthResult>
resetPassword(options: ResetPasswordOptions): Promise<EmailAuthResult>
reset(): void
requiresEmailVerification: boolean
isAwaitingInput: boolean
isLoading: boolean
isError: boolean
isSuccess: boolean
error?: OpenfortError | null
}
type EmailAuthResult = {
user?: User
wallet?: UserWallet
requiresEmailVerification?: boolean
error?: OpenfortError
}Hook options
Configure default behavior when initializing the hook.
type UseEmailHookOptions = {
// Default redirect URL for email verification.
emailVerificationRedirectTo?: string
// Log out the user if wallet recovery fails. Defaults to true.
logoutOnError?: boolean
// Automatically recover the wallet after authentication. Defaults to true.
recoverWalletAutomatically?: boolean
onSuccess?: (data: EmailAuthResult | EmailVerificationResult) => void
onError?: (error: OpenfortError) => void
}Parameters
signInEmail
type SignInEmailOptions = {
email: string
password: string
emailVerificationRedirectTo?: string
// Overrides the hook-level default.
logoutOnError?: boolean
// Overrides the hook-level default.
recoverWalletAutomatically?: boolean
onSuccess?: (data: EmailAuthResult) => void
onError?: (error: OpenfortError) => void
}signUpEmail
type SignUpEmailOptions = {
email: string
password: string
name?: string
emailVerificationRedirectTo?: string
// Overrides the hook-level default.
logoutOnError?: boolean
// Overrides the hook-level default.
recoverWalletAutomatically?: boolean
onSuccess?: (data: EmailAuthResult) => void
onError?: (error: OpenfortError) => void
}verifyEmail
type VerifyEmailOptions = {
email: string
// Verification code from the email.
state: string
onSuccess?: (data: EmailVerificationResult) => void
onError?: (error: OpenfortError) => void
}linkEmail
Link an email/password to an existing account.
type LinkEmailOptions = {
email: string
password: string
emailVerificationRedirectTo?: string
// Overrides the hook-level default.
logoutOnError?: boolean
// Overrides the hook-level default.
recoverWalletAutomatically?: boolean
onSuccess?: (data: EmailAuthResult) => void
onError?: (error: OpenfortError) => void
}requestResetPassword
type RequestResetPasswordOptions = {
email: string
emailVerificationRedirectTo?: string
onSuccess?: (data: EmailAuthResult) => void
onError?: (error: OpenfortError) => void
}resetPassword
type ResetPasswordOptions = {
email: string
password: string
// Reset code from the email.
state: string
onSuccess?: (data: EmailAuthResult) => void
onError?: (error: OpenfortError) => void
}