phoneAuth() plugin export.
Setup
lib/theauth.ts
theauth.phone is null unless the phone key is passed and auth.session is configured (a session is issued on verification). Forward matching requests to it from a catch-all route:
Mount the handler
handleRequest handles POST only and matches the literal pathnames below. If you mount it under a prefix such as /api/theauth, strip the prefix from the URL first. See adapters.
Send code
POST /auth/phone/send-code
Sends a one-time code to the given phone number, replacing any earlier code for that number.
Send code (client)
+ prefix, country code, number). theAuth only strips whitespace and does not validate or reformat the number, so normalize it before you call. A missing phoneNumber returns 400. The module has no built-in rate limit for sending, so add one in front of this route (see rate limiting) to limit SMS cost and abuse.
Verify code
POST /auth/phone/verify
Submits the code the user received. Returns the user and a session token on success. The user account is created on the first successful verification.
Verify code (client)
The handler does not set a cookie, so your app stores the session token.
Configuration reference
Callback invoked to deliver the code. Receives the phone number and the numeric code as a string.
Related
Email OTP
OTP via email instead of SMS.
Magic link
Passwordless sign-in via email link.
Passkey
Device biometric auth as a phone-free alternative.
Authentication overview
All sign-in methods available in theAuth.