Skip to content

docs: add Pre-register action - #1581

Open
wangsijie wants to merge 2 commits into
masterfrom
wangsijie-pre-register-action-docs
Open

wangsijie wants to merge 2 commits into
masterfrom
wangsijie-pre-register-action-docs

Conversation

@wangsijie

Copy link
Copy Markdown
Contributor

Summary

Document the Pre-register Action added in logto-io/logto#10082.

  • New page developers/actions/pre-register: when the Action runs (every Experience API registration method, after Logto's own registration checks) and when it doesn't, the event payload, the allow and deny results, what end users and custom UIs see on action.registration_denied, a ZeroBounce email validation example, the error policies, and what the Action.PreRegister audit log keeps. It also notes that the event sends a prospective user's email and IP to whatever service the script calls.
  • Actions overview: a third action type, a registration flowchart, and a table row.
  • Configure and test Actions: Pre-register in the Console steps, the error policy table, the audit log events, and the Management API keys.
  • Blocklist: a link to the Pre-register Action for checks with an external service.

A separate commit fixes the action keys. The docs used inlineHook.postFirstFactorVerification and inlineHook.postSignIn as "retained for backward compatibility", but every release since Actions shipped (v1.43.0) uses action.postFirstFactorVerification and action.postSignIn. The inlineHook.* keys never existed, so API calls that used them failed.

The action keys have been action.postFirstFactorVerification and
action.postSignIn since Actions shipped. The inlineHook.* keys never
existed, so API calls using them fail.
Document the Pre-register Action: when it runs, its event and result,
what end users see when a registration is denied, an email validation
example, failure behavior, and audit logs. Add it to the Actions
overview and configuration page, and link it from the email blocklist.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying logto-docs-tutorials with  Cloudflare Pages  Cloudflare Pages

Latest commit: a3930ef
Status: ✅  Deploy successful!
Preview URL: https://c67df00d.logto-docs-tutorials.pages.dev
Branch Preview URL: https://wangsijie-pre-register-actio.logto-docs-tutorials.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying logto-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: a3930ef
Status: ✅  Deploy successful!
Preview URL: https://815f364c.logto-docs.pages.dev
Branch Preview URL: https://wangsijie-pre-register-actio.logto-docs.pages.dev

View logs


## Monitor executions \{#monitor-executions}

Each run creates an `Action.PreRegister` [audit log](/developers/audit-logs) event. To show which sign-up was evaluated, it keeps the interaction event, verification types, application ID, the user's `username`, `primaryEmail`, and `primaryPhone`, and the decision. It does not keep the rest of the profile, the request context, or the deny message returned by the script.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite right: the audit log middleware prepends the request's ip, userAgent, and userAgentParsed to every log entry, and the Action.PreRegister entry is created with the default options, so it does carry them. Only the event's own request field is left out of the logged event.

Since this page has a privacy note, maybe something like:

… It does not copy the rest of the profile, the event's request field, or the deny message returned by the script. Like every audit log entry, it records the IP address and user agent of the request.

| Pre-register | Fail the registration. | Continue the registration as if the Action had allowed it. |

For Post sign-in, a malformed or unsupported return value always fails the sign-in, even when `allow` is selected. Validate every success path in your script and return an explicit supported result or no-op.
For Post sign-in and Pre-register, a malformed or unsupported return value always fails the sign-in or registration, even when `allow` is selected. Validate every success path in your script and return an explicit supported result or no-op.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related: the Supported user patch section above still opens with "An Action can return only these user fields", which no longer holds for Pre-register. Its result guard is strict, so { action: 'allow', user: { ... } } is an invalid result. Dry runs skip result validation, so a script like that passes Run test and then fails every registration with action.general, whatever the error policy.

Maybe scope that sentence, e.g. "A Post first-factor verification or Post sign-in Action can return only these user fields. A Pre-register Action cannot change the user and returns only allow or deny."

| {
action: 'deny';
// Plain text shown to the end user, up to 256 characters.
message?: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: a message over 256 characters isn't truncated. The whole result becomes invalid, and the registration fails with action.general instead of action.registration_denied. Worth a few words here, e.g. // Plain text shown to the end user, up to 256 characters. A longer message makes the result invalid.

throw new Error('ZeroBounce validation failed');
}

if (['invalid', 'spamtrap', 'abuse', 'do_not_mail'].includes(result.status)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ZeroBounce's do_not_mail also covers role-based addresses such as sales@, info@, and contact@ (sub_status: 'role_based'), which are deliverable. Apps that copy this would turn away teams signing up with a shared address. Maybe add a line after the example noting that, and that result.sub_status can be checked to let role-based addresses through.

@charIeszhao charIeszhao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few additional notes inline. One small optional nit on a file outside this diff:

  • docs/developers/README.mdx (line 43): the Actions card description still reads "Run synchronous custom code in the authentication flow to migrate or enrich users." — could also mention screening registrations.

1. Navigate to <CloudLink to="/actions">Console > Actions</CloudLink>.
2. Select **Post first-factor verification** or **Post sign-in**.
2. Select **Post first-factor verification**, **Post sign-in**, or **Pre-register**.
3. Implement the `runAction` function in the script editor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to Implement runAction (line 32 below): it currently reads:

To decline or continue without a user update, return the no-op value supported by the specific action type.

For Pre-register, returning a no-op (undefined, null, {}) allows registration rather than declining it—declining requires explicitly returning { action: 'deny' }. Worth rewording slightly (e.g. pointing to each action type's reference page for no-op vs. deny behavior) so readers don't mistakenly return undefined expecting a denial.


- `Action.PostFirstFactorVerification`
- `Action.PostSignIn`
- `Action.PreRegister`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add Action.PreRegister (Execute Pre-register Action) to the ## Actions table in docs/developers/audit-logs/event-types.mdx (lines 35–41), which currently only lists Action.PostFirstFactorVerification and Action.PostSignIn.

| ------------------------------------------ | -------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| Execution | Synchronous and inline with authentication | Asynchronous and outside the authentication request |
| Can affect the current authentication flow | Yes | No |
| Can modify a user from its result | Yes, using the supported user patch | Not directly; the receiver can call the Management API separately |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since Pre-register cannot modify a user, maybe qualify this lightly as "Yes, for sign-in Actions, using the supported user patch".

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants