Skip to main content
The phone number plugin lets users sign in and sign up using their phone number. It sends a one-time password (OTP) via SMS for verification.

Installation

1

Add the server plugin

Import phoneNumber and provide a sendOTP function that delivers the code via SMS:
auth.ts
Do not await the sendOTP call. Awaiting it slows down the request and can cause timing attacks. On serverless platforms, use waitUntil to ensure the SMS is sent before the function exits.
2

Run the database migration

The plugin adds phoneNumber and phoneNumberVerified columns to the user table:
3

Add the client plugin

auth-client.ts

Usage

Send an OTP

Call phoneNumber.sendOtp on the client to trigger the sendOTP callback on the server:
send-otp.ts

Verify the OTP

After the user enters the code, call phoneNumber.verify:
verify-otp.ts
By default, verifying a phone number creates a session and signs the user in.

Sign up on first verification

To automatically create a new user when a previously unseen phone number is verified, configure signUpOnVerification:
auth.ts

Sign in with phone number and password

If users have a password, they can sign in directly without an OTP:
sign-in.ts

Update phone number

To change a user’s phone number, send an OTP to the new number and then verify it with updatePhoneNumber: true:
update-phone.ts

Password reset via phone number

1

Request a reset OTP

request-reset.ts
2

Reset the password

reset-password.ts

Configuration options

Database schema

The plugin adds two optional columns to the user table: