Ir al contenido
v2.7

Verificación y recuperación

Confirmar el correo (por enlace) y el teléfono (por código SMS) del usuario y cambiar la contraseña olvidada.

Los flujos de correo tienen la misma forma: Owbase envía un correo con un enlace a una página de tu app, y esa página concluye el proceso con el userId y el secret que vienen en la dirección. El dominio de la página debe estar en Plataformas.

Los textos de los correos están en Autenticación → Correos, en la consola. Para editarlos, activa antes Usar SMTP propio (servidor de correo del propio proyecto); sin él, los correos salen con el texto predeterminado de Owbase.

verificacao.ts
import { Account } from '@owbase/web';
import { client } from './client';
const account = new Account(client);
// 1. With the user signed in: sends the email with the confirmation link to this page of your app.
await account.createEmailVerification({ url: 'https://app.example.com/confirm' });
// 2. On the /confirm page: the link arrives with ?userId=…&secret=…
const params = new URLSearchParams(window.location.search);
await account.updateEmailVerification({ userId: params.get('userId') ?? '', secret: params.get('secret') ?? '' });

Una vez confirmado, user.emailVerification pasa a true, y el rol Role.users('verified') pasa a valer para ese usuario en los permisos.

El teléfono de la cuenta se confirma con un código por SMS, enviado por Openwave, igual que el inicio de sesión por teléfono: la organización debe estar habilitada para el SMS y cada código enviado cuesta lo mismo (US$ 0,08, en el consumo; solo números de Brasil, otros países con habilitación de Openwave). El usuario debe tener sesión iniciada y un teléfono en la cuenta (por ejemplo, quien se registró por correo y después indicó el teléfono con account.updatePhone). Quien entra con el inicio de sesión por teléfono ya queda con el teléfono confirmado: pedir la verificación de nuevo responde 409 user_phone_already_verified.

verificacao-telefone.ts
import { Account } from '@owbase/web';
import { client } from './client';
const account = new Account(client);
// 1. With the user signed in (and a phone number on the account): sends the code by SMS to the account's phone.
const token = await account.createPhoneVerification();
// 2. The user types the code they received.
await account.updatePhoneVerification({ userId: token.userId, secret: '123456' });

Una vez confirmado, user.phoneVerification pasa a true. El código vale 10 minutos y acepta 3 intentos; los errores son los mismos del inicio de sesión por teléfono.

recuperacao.ts
import { Account } from '@owbase/web';
import { client } from './client';
const account = new Account(client);
// 1. On the "forgot password" screen: sends the email with the link to this page of your app.
await account.createRecovery({ email: '[email protected]', url: 'https://app.example.com/new-password' });
// 2. On the /new-password page: the link arrives with ?userId=…&secret=…
const params = new URLSearchParams(window.location.search);
await account.updateRecovery({ userId: params.get('userId') ?? '', secret: params.get('secret') ?? '', password: 'another-strong-password' });

El enlace de recuperación vale por tiempo limitado y se usa una sola vez; si expira, pide otro con createRecovery.

¿Te ayudó esta página?