Email OTP
The Email OTP plugin allows user to sign-in, verify their email, or reset their password using a one-time password (OTP) sent to their email address.
Installation
Add the plugin to your auth config
To enable email otp in your app, you need to add the emailOTP
plugin to your auth config.
Add the client plugin
Usage
Send OTP
First, send an OTP to the user's email address.
SignIn with OTP
Once the user provides the OTP, you can sign in the user using the signIn.emailOTP()
method.
If the user is not registered, they'll be automatically registered. If you want to prevent this, you can pass disableSignUp
as true
in the options.
Verify Email
To verify the user's email address, use the verifyEmail()
method.
Reset Password
To reset the user's password, use the resetPassword()
method.
Options
sendVerificationOTP
: A function that sends the OTP to the user's email address. The function receives an object with the following properties:email
: The user's email address.otp
: The OTP to send.type
: The type of OTP to send. Can be "sign-in", "email-verification", or "forget-password".
Example
otpLength
: The length of the OTP. Defaults to6
.expiresIn
: The expiry time of the OTP in seconds. Defaults to300
seconds.
-
sendVerificationOnSignUp
: A boolean value that determines whether to send the OTP when a user signs up. Defaults tofalse
. -
disableSignUp
: A boolean value that determines whether to prevent automatic sign-up when the user is not registered. Defaults tofalse
. -
generateOTP
: A function that generates the OTP. Defaults to a random 6-digit number.