Nest Authbeta

Phone + Password

Phone-number-as-username sign-up and sign-in.

For mobile-first regions and apps where a phone number is the primary identifier.

Server config

NestAuthModule.forRoot({
  emailAuth: { enabled: false },         // optional: turn off email
  phoneAuth: { enabled: true },
  registration: { enabled: true },
});

You can have both emailAuth and phoneAuth enabled simultaneously — users may sign up with whichever they prefer.

Endpoints

MethodPathPurpose
POST/auth/signupCreate a user with { phone, password, … }
POST/auth/loginLogin with { providerName: 'phone', credentials: { phone, password } }

Client call

await client.signup({
  phone: '+15551234567',
  password: 'correct horse battery staple',
});
 
await client.login({
  providerName: 'phone',
  credentials: { phone: '+15551234567', password: 'correct horse battery staple' },
});

Phone format & normalization

Use E.164 (+<country><number>). The library exports normalizedPhone(phone) for consistent handling — call it everywhere you accept user-entered numbers, so (555) 123-4567 and +15551234567 resolve to the same identity. See the normalize-email-phone recipe.

Phone verification

Distinct from login. After signup, the user's phone is unverified until they confirm it.

await client.sendPhoneVerification();   // emits PhoneVerificationRequestedEvent — your listener sends SMS
await client.verifyPhone({ code: '123456' });

The user record's phoneVerifiedAt is set on success.

On this page