Phone (SMS) login
Enhance security with SMS and phone authentication in Nuvix. Add multi-factor authentication via SMS, verify phone numbers, and protect user accounts.
Phone authentication lets users create accounts using their phone numbers and log in through SMS messages.
Create and use mock phone numbers to initiate a phone authentication process without an actual phone number.
Send SMS message
Phone authentication is done using a two-step authentication process. When using phone authentication, the authentication request is initiated from the client application and an SMS message is sent to the user's phone. The SMS message will contain a secret the user can use to log in.
Send an SMS message to initiate the authentication process. If the phone number has never been used, a new account is created using the provided userId, then the user will receive an SMS. If the phone number is already attached to an account, the user ID is ignored and the user will receive an SMS with the authentication code.
import { Client, ID } from "@nuvix/client";
const nx = new Client()
    .setEndpoint('https://api.nuvix.in/v1')
    .setProject('<PROJECT_ID>');
const token = await nx.account.createPhoneToken({
    userId: ID.unique(),
    phone: '+14255550123'
});
const userId = token.userId;Login
After initiating the phone authentication process, the returned user ID and secret are used to confirm the user. The secret will usually be a 6-digit number in the SMS message sent to the user.
import { Client, ID } from "@nuvix/client";
const nx = new Client()
    .setEndpoint('https://api.nuvix.in/v1')
    .setProject('<PROJECT_ID>');
const session = await nx.account.createSession({
    userId: userId,
    secret: '<SECRET>'
});After the secret is verified, a session will be created.
How is this guide?
Last updated on
Magic URL login
One-click login sent to email - users click a link and they're authenticated, no passwords, no codes, just magic.
OAuth 2 login
Integrate OAuth2 authentication seamlessly with Nuvix. Learn how to connect your application with third-party OAuth2 providers for secure user login and access.