DocsPayments & workflows
On this page

Email verification codes

Confirm a transfer, approve a profile change, or protect another signed-in action with three FRL methods. Frontbacked sends a six-digit code to the signed-in user's account email and supplies the email design and translations.

Send a code

frl

Rule excerpt: add this to a complete FRL rule before running it. Try a complete example →

Call OTP methods in endpoint bodies, after dedupe when your endpoint uses it. Sign-in is required. You cannot choose a different recipient or customize the email message.

OptionMeaning
challengeIdRequired nonempty string, up to 200 characters. Choose a key for the action being approved, such as a pending transfer's post ID.
expiresInLifetime in seconds, from 60 to 600. Defaults to 300.
langOptional language tag for the code email, such as fr, pt-BR or zh-Hans; regional tags match their language (fr-CA is French). Any of the platform's languages works. Left out, the email uses the language of the page the visitor is on, else English.

The result is safe to pass to the browser:

json

The code itself is never returned. queued means accepted for delivery when the endpoint succeeds, not proof that the email reached the inbox. Repeating send for an active challenge returns its existing expiry without issuing another code; pending delivery can be retried. Codes created by failed endpoint actions are not emailed.

Each challenge belongs to the current site and signed-in user. A challenge ID is not authorization: your endpoint must still check access to the record or action. Save the proposed values before sending the code, and apply those saved values after confirmation. Changing the proposed action should create a new challenge ID.

Verify and complete the action

backend/index.frl
Rule input (JSON)

Use a complete version 2 rule file. Select a post with “postType” and “action”, or an “endpoint” by name. Saved data, jobs, payments and email need the local server. Dedupe replay protection also needs a site.

Check complete rules or run schemas, permissions, hooks and calculations against the input above. Add excerpts to a complete rule before running.

This example assumes you declared a pending_requests post type with appropriate read permissions. See the bank theme for a complete transfer workflow.

verify accepts a six-digit string, preserving leading zeros. It returns { ok: true } on success or { ok: false, reason: "invalid_or_expired" } when no usable matching code exists. Missing sign-in, invalid options, and exceeded limits fail the endpoint. Use must before performing protected actions.

Successful verification consumes the code. When used inside atomic, consumption and the related post writes succeed together. Failed business writes restore the approval so the customer can retry; verification attempts still count. A consumed challenge ID cannot be issued again. Start a new action with a new ID.

Resend

frl

Rule excerpt: add this to a complete FRL rule before running it. Try a complete example →

Check ownership and that the action still awaits confirmation before resending. The new code replaces the previous code, keeps the original language and lifetime, and returns fresh timestamps. A changed account email requires a fresh challenge ID.

Frontbacked enforces a 60-second resend cooldown, five email sends per user per ten minutes, five verification attempts per challenge per ten minutes, and thirty verification attempts across that user's challenges per ten minutes. Resending does not reset those attempt limits. Excessive repeated send requests are also limited. Expired codes cannot be verified.

Show the code-entry widget

Pass the returned otp object to the runtime:

js

Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →

The options name your FRL endpoints. The widget calls verify with { challengeId, code } and calls resend with { challengeId }. The verification endpoint should complete the protected action and return { ok: true, ... }; that response resolves the widget's promise. The resend endpoint should return { ok: true, otp: ... } or the challenge object directly.

You can supply extra endpoint data with { endpoint: "confirmRequest", body: { requestId } } instead of a name. The widget always supplies its own current challengeId and entered code.

The dialog includes six digit boxes, full-code paste and autofill, keyboard navigation, inline errors, expiry and resend countdowns, focus management, and background scroll locking. English or French follows the challenge language. Closing returns { ok: false, cancelled: true }. Omitting resend disables resending in the widget. Only one OTP dialog can be open at a time.

In local development, emails appear in the local mailbox unless SMTP delivery is configured.