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
| Parameter | Type | Description |
|---|---|---|
handleAction | Function | Action handler for navigation and displaying messages. |
redirectAction | Object | Optional action to execute after successful login. |
ignoreLoginRedirect | boolean | If true, skips the default post-login redirect. Default: false. |
initialData | Object | Optional additional data to send with the OTP request. |
Return Value
| Property | Type | Description |
|---|---|---|
currentStep | string | Current step in the OTP flow: 'send', 'verify', or 'done'. |
sendCode | Function | Sends an OTP to the provided email. Signature: sendCode(email). |
verifyCode | Function | Verifies the OTP code. Signature: verifyCode(otpCode). |
resendCode | Function | Resends the OTP to the email. Signature: resendCode(email). |
reset | Function | Resets the OTP flow back to the 'send' step. |
sendStatus | string | Status of the send request: 'idle', 'loading', 'success', or 'error'. |
sendErrorMessage | string \| null | Error message from the send request, if any. |
verifyStatus | string | Status of the verify request: 'idle', 'loading', 'success', or 'error'. |
verifyErrorMessage | string \| null | Error message from the verify request, if any. |
resendStatus | string | Status of the resend request: 'idle', 'loading', 'success', or 'error'. |
resendErrorMessage | string \| null | Error message from the resend request, if any. |
failedAttemptCount | number | Number of failed verification attempts. |
otpDigitCount | number | Expected number of OTP digits (default: 4). |
email | string \| null | The email address the OTP was sent to. |
canResend | boolean | Whether the OTP can be resent. |