Skip to main content

useEmailOtpLogin

This hook manages email-based OTP (One-Time Password) login flow, including sending, verifying, and resending OTP codes.

Import

import { useEmailOtpLogin } from '@appmaker-xyz/shopify';

Basic Usage

const {
currentStep,
sendCode,
verifyCode,
resendCode,
reset,
sendStatus,
verifyStatus,
verifyErrorMessage,
resendStatus,
failedAttemptCount,
otpDigitCount,
} = useEmailOtpLogin({ handleAction, redirectAction });

Parameters

ParameterTypeDescription
handleActionFunctionAction handler for navigation and displaying messages.
redirectActionObjectOptional action to execute after successful login.
ignoreLoginRedirectbooleanIf true, skips the default post-login redirect. Default: false.
initialDataObjectOptional additional data to send with the OTP request.

Return Value

PropertyTypeDescription
currentStepstringCurrent step in the OTP flow: 'send', 'verify', or 'done'.
sendCodeFunctionSends an OTP to the provided email. Signature: sendCode(email).
verifyCodeFunctionVerifies the OTP code. Signature: verifyCode(otpCode).
resendCodeFunctionResends the OTP to the email. Signature: resendCode(email).
resetFunctionResets the OTP flow back to the 'send' step.
sendStatusstringStatus of the send request: 'idle', 'loading', 'success', or 'error'.
sendErrorMessagestring \| nullError message from the send request, if any.
verifyStatusstringStatus of the verify request: 'idle', 'loading', 'success', or 'error'.
verifyErrorMessagestring \| nullError message from the verify request, if any.
resendStatusstringStatus of the resend request: 'idle', 'loading', 'success', or 'error'.
resendErrorMessagestring \| nullError message from the resend request, if any.
failedAttemptCountnumberNumber of failed verification attempts.
otpDigitCountnumberExpected number of OTP digits (default: 4).
emailstring \| nullThe email address the OTP was sent to.
canResendbooleanWhether the OTP can be resent.