Password-based phone login
A mobile or web login form collects a user's phone number and password.
Better Auth · Module
signIn.phoneNumber authenticates an existing Better Auth user with a phone number and password. It accepts rememberMe to control session persistence.
With the phone-number plugin enabled, this client method authenticates an existing user by matching the supplied phone number and password. The rememberMe flag controls whether the resulting session is remembered.
authClient.signIn.phoneNumber({ phoneNumber, password, rememberMe })| Name | Type | Description |
|---|---|---|
phoneNumber | string | Phone number used to identify the user. |
password | string | Password used for authentication. |
rememberMe | boolean | Whether to remember the resulting session; required by the documented example. |
The client call yields an object containing data and error, as shown in the documentation example.
import { createAuthClient } from "better-auth/client";
const authClient = createAuthClient();
const { data, error } = await authClient.signIn.phoneNumber({
phoneNumber: "+1234567890",
password: "correct-horse-battery-staple",
rememberMe: true,
});
if (error) console.error(error);
else console.log(data);
Signs in an existing user with a phone number and password while requesting a remembered session.
A mobile or web login form collects a user's phone number and password.
An application wants a persistent session after successful authentication.
A backend needs to perform the same credential flow without the client helper.
The method is authClient.signIn.phoneNumber and it accepts a phone number, password, and rememberMe. It returns the same data-and-error style shown for Better Auth client calls.
Follow-up: How would you support server-side usage? Call auth.api.signInPhoneNumber with the same values inside its body.
It signs in using phone number as the user identifier rather than an email address. The phone-number plugin provides this capability.
Follow-up: What additional authentication flow does the plugin support? It can also send an OTP for phone verification.
The corresponding server API is auth.api.signInPhoneNumber. Its request places phoneNumber, password, and rememberMe under body.
Follow-up: What must exist before password authentication succeeds? A matching credential account record must be present for the user.
phoneNumberauth.api.signInPhoneNumberphoneNumber.sendOtpphoneNumber.verifysignUpOnVerification