Skip to content
SupportDashboard

Email OTP

Learn how to sign in users with one-time passwords delivered via email.

OTP one-time password passwordless email verification temporary code 2FA authentication code

One-Time Passwords (OTPs) are temporary codes for single use that can be delivered to users via email. OTPs expire after 10 minutes and can only be used once. OTPs can provide a more secure and convenient alternative to regular passwords.

To use One-Time Passwords, they need to be enabled in the configuration:

[auth.method.otp.email]
enabled = true

Signing in with an email OTP is a two-step process:

The user requests an OTP, which is sent to their email address:

await nhost.auth.signInOTPEmail({
email: 'user@example.com',
});

The user enters the OTP code received via email:

await nhost.auth.verifySignInOTPEmail({
email: 'user@example.com',
otp: '123456',
});

When email OTP is enabled, signed-in users with a verified email address can also use it to elevate their session before performing sensitive actions. Email verification is required for elevation even if it is optional for sign-in. The code is sent to the email address of the signed-in user using the elevate-otp template, rather than the signin-otp template.

Neither call takes an email address; both use the user’s existing authenticated session:

await nhost.auth.elevateOTPEmail();
await nhost.auth.verifyElevateOTPEmail({
otp: '123456',
});