Skip to content
v2.7

Phone sign-in (SMS and WhatsApp)

Sign in with a code sent by SMS from Openwave, using @owbase/web; enablement, cost, limits, the errors your app shows and the code via WhatsApp.

The user types their phone number, receives a code by SMS and signs in with it. Openwave sends the SMS: you don’t contract an SMS provider or configure anything beyond turning the method on. The code is generated, sent, checked and expired by Openwave’s SMS provider, and your app uses the usual Account methods.

  1. Enablement. SMS sign-in is enabled per organization, by Openwave (it costs per send). Without enablement, Auth → Sign-in methods → Phone (SMS) appears disabled with “Contact Openwave to enable SMS login”, and the code request responds 403 owbase_phone_not_enabled.
  2. Method on. Once the organization is enabled, turn on Phone (SMS) in Auth → Sign-in methods. The row shows the cost, the project’s daily limit and how many codes went out today.
telefone.ts
import { Account, ID, OwbaseException } from '@owbase/web';
import { client } from './client';
const account = new Account(client);
// 1. The user types the phone number (international format): Owbase sends the code by SMS. A new number creates the user.
const token = await account.createPhoneToken({ userId: ID.unique(), phone: '+5511987654321' });
// 2. They type the code that arrived; the session opens with the userId from step 1.
try {
await account.createSession({ userId: token.userId, secret: '123456' });
} catch (e) {
if (!(e instanceof OwbaseException)) throw e;
if (e.type === 'owbase_phone_code_invalid') console.log('Incorrect code. Check it and try again.');
else if (e.type === 'owbase_phone_code_expired' || e.type === 'owbase_phone_code_blocked') console.log('Request a new code.');
else console.log(e.message); // the message is ready to show
}
  • The number goes in international format, with the country code: +5511987654321. Brazilian numbers only (+55); other countries need Openwave to enable them for your organization.
  • A number that doesn’t belong to any user yet creates the user (with the userId you pass). A number that belongs to an existing user signs in as that user.
  • The SMS arrives in Portuguese, with just the code. The code is valid for 10 minutes and allows 3 attempts: on the third wrong one it’s blocked and the user must request another.
  • Requesting another code for the same number has a wait of about 1 minute (the response says how many seconds are left).
  • Signing in with the code confirms the user’s phone (phoneVerification becomes true).
  • With an API key (on the server), the code request’s response has an empty secret: the code exists only in the SMS.

Each code sent costs US$ 0.08 and counts toward the organization’s usage (“SMS codes”), even if the SMS isn’t delivered. Checking the code costs nothing. Numbers outside Brazil only with Openwave’s approval, at the agreed price. See plan and pricing.

What Limit
Codes per project, per day (Brasília time) 1,000 (Openwave can change this for your organization)
Codes per number, per hour 5
Codes per number, per day 10
Wait before requesting another code for the same number about 1 minute

The per-number limits protect against anyone trying to fire off codes in bulk to other people’s numbers. An app that needs more codes per day should talk to Openwave.

All of them come in the usual SDK format (OwbaseException with code, type and message), with the message in Portuguese, ready to show to the user.

type Status When
owbase_phone_not_enabled 403 The organization isn’t enabled for SMS sign-in.
owbase_phone_invalid 400 Number not in international format, or one the provider refused.
owbase_phone_country 400 Number from outside Brazil with no enablement for the organization: “Números de fora do Brasil não estão liberados para esta organização. Fale com a Openwave.” (Portuguese message: numbers outside Brazil aren’t enabled for this organization; contact Openwave.)
owbase_phone_resend_wait 429 Requested another code too soon; the message says how many seconds to wait.
owbase_phone_limit 429 Over the number’s limit (hour or day) or the project’s (day).
owbase_phone_unavailable 503 The SMS didn’t go out right now (provider down or no response within 10 s). Try again in a moment.
owbase_phone_code_invalid 401 Wrong code (you can still try again).
owbase_phone_code_expired 401 The code expired, was already used, or never went out: request another.
owbase_phone_code_blocked 401 Too many wrong attempts: request another (repeating the same code stays blocked).
owbase_phone_body_invalid 400 The request body isn’t plain JSON (no compression, one value per field). The SDKs already send it this way.

The same code login can arrive via WhatsApp instead of SMS. The message goes out through your project’s WhatsApp provider (the account is yours, not Openwave’s): it doesn’t need the SMS approval and doesn’t count toward the SMS codes in usage.

  1. In Messaging → Providers, set up and turn on a WhatsApp provider: WhatsApp Cloud (Meta) (with an approved template in the Authentication category) or Twilio WhatsApp. Only one is active at a time.
  2. In Authentication → Sign-in methods, turn on Code via WhatsApp. Without an active provider, the switch is locked and the row links to Messaging.
  3. In the app, request the code at POST /v1/account/tokens/whatsapp, with the same body as the phone token (userId and phone). The session opens the usual way, account.createSession({ userId, secret }), and the code follows the same expiry and attempt rules as SMS.
whatsapp.ts
import { Account, ID, type Models } from '@owbase/web';
import { client } from './client';
const account = new Account(client);
// 1. Request the code via WhatsApp. It's an Owbase route (no SDK method): the same body as the phone token.
const response = await fetch('https://cloud.owbase.dev/v1/account/tokens/whatsapp', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Owbase-Project': '<PROJECT_ID>' },
body: JSON.stringify({ userId: ID.unique(), phone: '+5511987654321' }),
});
const body = (await response.json()) as Models.Token & { type?: string; message?: string };
if (!response.ok) throw new Error(body.message); // owbase_whatsapp_disabled, owbase_whatsapp_number, owbase_whatsapp_unavailable…
// 2. The user types the code that arrived on WhatsApp; the session opens the usual way.
await account.createSession({ userId: body.userId, secret: '123456' });

The SDKs don’t have a method for this route yet, and it isn’t in the generated reference (which comes from the server API): call it with fetch, as in the example.

type Status When
owbase_whatsapp_disabled 403 WhatsApp login is off in the project or there is no active WhatsApp provider.
owbase_whatsapp_number 400 The number can’t receive WhatsApp messages.
owbase_whatsapp_unavailable 503 The code didn’t go out right now (provider failure). Try again in a moment.
  • Code by email and by phone at the same time. For 16 minutes after a phone code request (even if the code was already used, blocked, or never went out), a numeric code typed by that user is always treated as the SMS code: the phone code in effect is checked; without one, the response is owbase_phone_code_expired or owbase_phone_code_blocked. Someone who requested a code by email and by phone at the same time signs in with the phone one, or waits for that period to pass.
  • Functions. A function that calls the API requests the code and opens the session the same way as the app: the enablement, cost, limits and errors above apply.
  • Confirming the phone of a signed-in user is also done by SMS and costs the same: see Verification and recovery.
  • SMS MFA (second factor by phone): refused with 403 owbase_phone_factor_unavailable. Use the authenticator app or email.
  • Team invitation by phone only: refused with 400 owbase_phone_invite_unavailable. Invite by email.
  • Test numbers (a phone with a fixed code): refused with 403 owbase_phone_mock_unavailable. Test with a real number.
Was this page helpful?