Installation
Add the server plugin
Import
phoneNumber and provide a sendOTP function that delivers the code via SMS:auth.ts
Run the database migration
The plugin adds
phoneNumber and phoneNumberVerified columns to the user table:- migrate
- generate
Usage
Send an OTP
CallphoneNumber.sendOtp on the client to trigger the sendOTP callback on the server:
send-otp.ts
Verify the OTP
After the user enters the code, callphoneNumber.verify:
verify-otp.ts
Sign up on first verification
To automatically create a new user when a previously unseen phone number is verified, configuresignUpOnVerification:
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 withupdatePhoneNumber: true:
update-phone.ts
Password reset via phone number
Configuration options
| Option | Type | Default | Description |
|---|---|---|---|
sendOTP | function | — | Required. Sends the OTP code. Receives { phoneNumber, code } and a context object. |
otpLength | number | 6 | Number of digits in the OTP. |
expiresIn | number | 300 | OTP lifetime in seconds. |
allowedAttempts | number | 3 | Max verification attempts before the OTP is deleted. |
requireVerification | boolean | false | Block sign-in until phone number is verified. |
signUpOnVerification | object | — | Auto-create users on first verification. Requires getTempEmail. |
callbackOnVerification | function | — | Called after a successful verification. Receives { phoneNumber, user }. |
phoneNumberValidator | function | — | Custom phone number validation function. Returns a boolean. |
verifyOTP | function | — | Override the default OTP verification logic (e.g. to use Twilio Verify). |
sendPasswordResetOTP | function | — | Custom OTP sender for password reset flow. |
Database schema
The plugin adds two optional columns to theuser table:
| Column | Type | Description |
|---|---|---|
phoneNumber | string (unique) | The user’s phone number. |
phoneNumberVerified | boolean | Whether the phone number has been verified. |