Installation
1
Add the server plugin
Import
phoneNumber and provide a sendOTP function that delivers the code via SMS:auth.ts
2
Run the database migration
The plugin adds
phoneNumber and phoneNumberVerified columns to the user table:- migrate
- generate
3
Add the client plugin
auth-client.ts
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
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 theuser table: