Skip to content

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) {
      // Prompt user to check inbox
    }
  };
 
  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?: AuthPlayerResponse
  wallet?: UserWallet
  requiresEmailVerification?: boolean
  error?: OpenfortError
}

Parameters

signInEmail

type SignInEmailOptions = {
  email: string
  password: string
  emailVerificationRedirectTo?: string
  onSuccess?: (data: EmailAuthResult) => void
  onError?: (error: OpenfortError) => void
}

signUpEmail

type SignUpEmailOptions = {
  email: string
  password: string
  name?: string
  emailVerificationRedirectTo?: string
  onSuccess?: (data: EmailAuthResult) => void
  onError?: (error: OpenfortError) => void
}

verifyEmail

type VerifyEmailOptions = {
  email: string
  state: string  // Verification code from email
  onSuccess?: (data: EmailVerificationResult) => void
  onError?: (error: OpenfortError) => void
}

linkEmail

Links an email/password to an existing account.

type LinkEmailOptions = {
  email: string
  password: string
  emailVerificationRedirectTo?: string
  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
  state: string  // Reset code from email
  onSuccess?: (data: EmailAuthResult) => void
  onError?: (error: OpenfortError) => void
}