useEmailAuth
Handle the entire email/password lifecycle: sign in, sign up, link email addresses, reset passwords, and verify one-time codes.
Request
type Request = {
hook: 'useEmailAuth',
params: [options?: UseEmailHookOptions]
}
type UseEmailHookOptions = {
emailVerificationRedirectTo?: string
logoutOnError?: boolean
recoverWalletAutomatically?: boolean
onSuccess?: (data: EmailAuthResult | EmailVerificationResult) => void
onError?: (error: import("@openfort/react-native").OpenfortError) => void
onSettled?: (data: EmailAuthResult | EmailVerificationResult | undefined | null, error: import("@openfort/react-native").OpenfortError | null) => void
throwOnError?: boolean
}
Response
type Response = UseEmailAuthReturn
type UseEmailAuthReturn = PasswordStatusFlags & {
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
}
type PasswordStatusFlags = {
isLoading: boolean
isError: boolean
isSuccess: boolean
error?: import("@openfort/react-native").OpenfortError | null
}
type EmailAuthResult = {
error?: import("@openfort/react-native").OpenfortError
user?: import("@openfort/openfort-js").AuthPlayerResponse
wallet?: import("@openfort/react-native").UserWallet
requiresEmailVerification?: boolean
}
type EmailVerificationResult = {
email?: string
error?: import("@openfort/react-native").OpenfortError
}
Example
import { useEmailAuth } from "@openfort/react-native"
function EmailFlows() {
const {
signInEmail,
signUpEmail,
linkEmail,
verifyEmail,
requestResetPassword,
resetPassword,
reset,
isLoading,
isError,
isSuccess,
isAwaitingInput,
requiresEmailVerification,
error,
} = useEmailAuth({
emailVerificationRedirectTo: "https://app.example.com/auth/callback",
throwOnError: true,
onSuccess: () => {},
onError: () => {},
onSettled: () => {},
})
const handleSignIn = async (email: string, password: string) => {
const result = await signInEmail({ email, password })
if (result.requiresEmailVerification) {
// prompt user to check inbox for the verification code
}
}
return null
}