ui-calling

Ask for a PIN or code before showing personal data

Use it when a screen shows what only that person should see: a payslip, a contract, an ID document, a rota. A link is a bearer token, and phones get shared, lent and changed. With verify: true, nothing loads until the user types a PIN they know or a code you send them.

Full example: the demo's shift picker asks for a PIN (verify: true in shift-picker.surface.ts, demoVerifier in server/identity.ts).

Contract

export const payslip = defineSurface({
  name: "payslip",
  description: "The worker's payslip for a month…",
  input: z.object({ month: z.string() }),
  data: z.object({ /* … */ }),
  events: {},
  verify: true,          // resolve doesn't run until the user proves who they are
  ttlSeconds: 15 * 60,   // and keep the link short-lived
});

Server

Give createUiCalling a verifier. sqliteIdentity (see link-account) has two:

import { identity } from "./identity";

export const ui = createUiCalling({
  // ...
  verifier: identity.pinVerifier(),
  // or a fresh code each time, through a channel the user already controls:
  // verifier: identity.codeVerifier({ deliver: async (customerId, code, locale) => {
  //   const { phone } = await employees.get(customerId);
  //   await sms.send(phone, locale.startsWith("es") ? `Tu código: ${code}` : `Your code: ${code}`);
  //   return { hint: `SMS to •••• ${phone.slice(-2)}` };
  // } }),
});

// Set the PIN once the chat is linked, e.g. in the link-account screen or your onboarding:
identity.setPin(employeeId, pin);

Or write your own: { kind: "pin" | "code", send?(who, locale), check(who, typed) }. With Twilio Verify, when the subject is the user's phone number:

const verify = () => twilio(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN).verify.v2.services(process.env.TWILIO_VERIFY_SERVICE_SID!);

export const twilioVerifier: Verifier = {
  kind: "code",
  async send({ subject }) {
    await verify().verifications.create({ to: subject, channel: "sms" });
    return { hint: `SMS to •••• ${subject.slice(-2)}` };
  },
  async check({ subject }, typed) {
    return (await verify().verificationChecks.create({ to: subject, code: typed }).catch(() => null))?.status === "approved";
  },
};

On a trial account, Twilio Verify only texts numbers verified in its console. check gets who.subject: look up the person the chat is linked to and compare against theirs, never a shared value. Keep a lockout per person in your verifier; the runtime only counts per link.

WhatsApp can't send an authentication template to a BSUID, so on WhatsApp a code goes by SMS or email, or you use a PIN.

Screen

Nothing to write. SurfaceProvider shows its own step, in the user's language (en/es) and with your tokens, then your screen once the PIN is right. opened is recorded only after that. To change it, pass verifyScreen, or wrap the built-in one:

<SurfaceProvider token={token} verifyScreen={(p) => <VerifyStep {...p} note={<a href="/help">Forgot your PIN?</a>} />}>

What the agent gets

Watch out

In the ui-calling repo

Not in the package; for reading if you have the repo.

Source: packages/cli/recipes/verify-before-showing.md