@passflow/react 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +95 -5
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.es.js +145 -145
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/src/components/form/forgot-password/forgot-password.d.ts.map +1 -1
  8. package/dist/src/components/form/signin/index.d.ts.map +1 -1
  9. package/dist/src/components/form/signup/index.d.ts.map +1 -1
  10. package/dist/src/components/provider/passflow-provider.d.cts +6 -0
  11. package/dist/src/components/provider/passflow-provider.d.ts +6 -0
  12. package/dist/src/components/provider/passflow-provider.d.ts.map +1 -1
  13. package/dist/src/components/ui/anti-bot/anti-bot-check.d.cts +22 -0
  14. package/dist/src/components/ui/anti-bot/anti-bot-check.d.ts +22 -0
  15. package/dist/src/components/ui/anti-bot/anti-bot-check.d.ts.map +1 -0
  16. package/dist/src/components/ui/anti-bot/fake-vendors.d.cts +33 -0
  17. package/dist/src/components/ui/anti-bot/fake-vendors.d.ts +33 -0
  18. package/dist/src/components/ui/anti-bot/fake-vendors.d.ts.map +1 -0
  19. package/dist/src/components/ui/anti-bot/index.d.cts +3 -0
  20. package/dist/src/components/ui/anti-bot/index.d.ts +3 -0
  21. package/dist/src/components/ui/anti-bot/index.d.ts.map +1 -0
  22. package/dist/src/components/ui/anti-bot/vendors.d.cts +61 -0
  23. package/dist/src/components/ui/anti-bot/vendors.d.ts +61 -0
  24. package/dist/src/components/ui/anti-bot/vendors.d.ts.map +1 -0
  25. package/dist/src/components/ui/index.d.cts +1 -0
  26. package/dist/src/components/ui/index.d.ts +1 -0
  27. package/dist/src/components/ui/index.d.ts.map +1 -1
  28. package/dist/src/components/ui/login-screen/login-screen.d.ts.map +1 -1
  29. package/dist/src/components/ui/login-screen/types.d.cts +6 -0
  30. package/dist/src/components/ui/login-screen/types.d.ts +6 -0
  31. package/dist/src/components/ui/login-screen/types.d.ts.map +1 -1
  32. package/dist/src/hooks/index.d.cts +1 -0
  33. package/dist/src/hooks/index.d.ts +1 -0
  34. package/dist/src/hooks/index.d.ts.map +1 -1
  35. package/dist/src/hooks/use-anti-bot.d.cts +16 -0
  36. package/dist/src/hooks/use-anti-bot.d.ts +16 -0
  37. package/dist/src/hooks/use-anti-bot.d.ts.map +1 -0
  38. package/dist/src/hooks/use-auth-agent-tools.d.cts +15 -0
  39. package/dist/src/hooks/use-auth-agent-tools.d.ts +15 -0
  40. package/dist/src/hooks/use-auth-agent-tools.d.ts.map +1 -0
  41. package/dist/src/hooks/use-forgot-password.d.ts.map +1 -1
  42. package/dist/src/hooks/use-passwordless-complete.d.cts +5 -2
  43. package/dist/src/hooks/use-passwordless-complete.d.ts +5 -2
  44. package/dist/src/hooks/use-passwordless-complete.d.ts.map +1 -1
  45. package/dist/src/hooks/use-provider.d.cts +5 -3
  46. package/dist/src/hooks/use-provider.d.ts +5 -3
  47. package/dist/src/hooks/use-provider.d.ts.map +1 -1
  48. package/dist/src/hooks/use-signin.d.cts +6 -3
  49. package/dist/src/hooks/use-signin.d.ts +6 -3
  50. package/dist/src/hooks/use-signin.d.ts.map +1 -1
  51. package/dist/src/hooks/use-signup.d.cts +6 -3
  52. package/dist/src/hooks/use-signup.d.ts +6 -3
  53. package/dist/src/hooks/use-signup.d.ts.map +1 -1
  54. package/dist/src/utils/agent-tools.d.cts +96 -0
  55. package/dist/src/utils/agent-tools.d.ts +96 -0
  56. package/dist/src/utils/agent-tools.d.ts.map +1 -0
  57. package/dist/src/utils/auth-error.d.cts +11 -2
  58. package/dist/src/utils/auth-error.d.ts +11 -2
  59. package/dist/src/utils/auth-error.d.ts.map +1 -1
  60. package/dist/src/utils/index.d.cts +1 -1
  61. package/dist/src/utils/index.d.ts +1 -1
  62. package/dist/src/utils/index.d.ts.map +1 -1
  63. package/dist/src/utils/model-context.d.cts +38 -0
  64. package/dist/src/utils/model-context.d.ts +38 -0
  65. package/dist/src/utils/model-context.d.ts.map +1 -0
  66. package/dist/style.css +1 -1
  67. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  All notable changes to `@passflow/react` are documented in this file.
4
4
 
5
+ ## [0.30.0] - 2026-11-23
6
+
7
+ ### Added
8
+
9
+ - Bot mode. On an app whose bot mode is `human_only`, the sign-in, sign-up and forgot-password screens run the human check the app's settings name. The built-in check shows "Checking your browser…" while it solves. Cloudflare Turnstile, hCaptcha and reCAPTCHA v3 load their script once, render with the app's site key and hand out a fresh token for each request. reCAPTCHA v3 uses a score key and the action `passflow_auth`. An app in `bot_friendly` mode renders as before.
10
+ - A failed human check shows one message on every covered screen: "We could not confirm you are human. Try again." When the check is unavailable (503 `anti_bot.unavailable`, the server or the vendor is down), the screen shows the same "temporarily unavailable" message as other 503s instead.
11
+ - `AntiBotCheck` renders that check, with the types `AntiBotCheckProps`, `AntiBotBuiltinCheckProps`, `AntiBotVendorCheckProps`, `AntiBotGetToken` and `AntiBotVendor`. `useAntiBot(appSettings)` returns its props, or `undefined` when the app asks for no check.
12
+ - `PassflowProvider` passes `antiBotWorkerUrl`, the `PassflowConfig` option, to `@passflow/core`. Serve the worker file `@passflow/core/anti-bot-worker.js` (`node_modules/@passflow/core/dist/anti-bot-worker.js`) from the app's own origin and pass its URL. The built-in check then solves in a Web Worker. Without it, the check runs on the main thread.
13
+ - WebMCP tools. On a `bot_friendly` app, `SignIn`/`SignInForm` and `SignUp`/`SignUpForm` register tools for an in-browser agent through `document.modelContext`, or else `navigator.modelContext`: `list_auth_methods`, `get_auth_status`, `sign_in_password` (sign-in) or `sign_up_password` (sign-up), `start_passwordless`, `complete_passwordless`, `start_social` and `sign_in_passkey`. Each is registered only when the app has its method on. `sign_in_passkey` only tells the agent to ask the user to click the passkey button. The tools go away when the form unmounts. If the browser refuses any registration (a duplicate name, a denied permission), the form registers none and works as before. Every request a tool sends carries `X-Passflow-Agent-Tool: 1`. No tool is registered on a `human_only` app, or on the device approval, passwordless approval and consent screens.
14
+
15
+ - On a `human_only` app, the silent sign-in `PassflowProvider` runs on the login page (`/auth/session/exchange`) answers the server's 403 `anti_bot.required` by sending the exchange once more with an anti-bot value from `passflow.antiBotToken({ operation: 'session.exchange' })`. An exchange the server does not refuse asks for no value, so other apps make no extra solve. With the built-in check, silent sign-in keeps working. With Turnstile, hCaptcha or reCAPTCHA, no widget is on the page at that point, so the server refuses the exchange. The user then signs in on the page, and a `prompt=none` request ends in `interaction_required`. This is a known limit of vendor captchas.
16
+
17
+ ### Changed
18
+
19
+ - The minimum `@passflow/core` is now 0.34.0.
20
+ - `useSignIn().fetch`, `useSignUp().fetch` and `usePasswordlessComplete().fetch` take an optional last argument, `options` (`PassflowAuthOptions`), and pass it to core. So do `useProvider`'s `federatedWithPopup` and `federatedWithRedirect`, after `inviteToken`. `{ agentTool: true }` marks a request as sent by an agent tool.
21
+ - `useSignIn`, `useSignUp` and `usePasswordlessComplete` return `readError()`. It returns the error the latest `fetch` set, and you can read it right after `await fetch()`, before the next render.
22
+
23
+ ### Fixed
24
+
25
+ - `PassflowProvider` accepted `antiBotWorkerUrl` but did not pass it to core, so the built-in check always ran on the main thread.
26
+ - `useForgotPassword` stayed in `isLoading` after a failed request. It now clears `isLoading` on failure.
27
+
5
28
  ## [0.29.0] - 2026-11-22
6
29
 
7
30
  ### Added
package/README.md CHANGED
@@ -19,6 +19,7 @@ This is a SDK for react application.
19
19
  - [Login button](#login-button)
20
20
  - [Two-factor setup for a signed-in user](#two-factor-setup-for-a-signed-in-user)
21
21
  - [Step-up](#step-up)
22
+ - [Bot mode and WebMCP tools](#bot-mode-and-webmcp-tools)
22
23
  - [React Router](#react-router)
23
24
  - [Wouter](#wouter)
24
25
  - [TanStack Router](#tanstack-router)
@@ -394,6 +395,91 @@ The dialog offers the factors the server lists in `available_factors`, in its or
394
395
 
395
396
  The hosted login page never calls `onSignInRequired`. It shows the sign-in form for sign-in required and insufficient, and puts the unsatisfiable and rate-limited messages on the page in place of the form.
396
397
 
398
+ ### Bot mode and WebMCP tools
399
+
400
+ Since 0.30.0 (with `@passflow/core` 0.34.0 or later), the forms follow the app's bot mode from its settings:
401
+
402
+ | Bot mode | Sign-in, sign-up and forgot-password | WebMCP tools |
403
+ |----------|--------------------------------------|--------------|
404
+ | `bot_friendly` (also when unset) | Render as before, with no human check | Registered by `SignIn`/`SignInForm` and `SignUp`/`SignUpForm` when the browser has a model-context API |
405
+ | `human_only` | Run the human check named in the app's settings | Never registered |
406
+
407
+ **Human check on a `human_only` app.**
408
+
409
+ The forms render the check for you. The app's settings choose one of four providers:
410
+
411
+ | Provider | What the user sees | Script the page loads |
412
+ |----------|--------------------|-----------------------|
413
+ | `builtin` | "Checking your browser…" while core solves a proof of work | None |
414
+ | `turnstile` | Cloudflare Turnstile, only if it asks for an interaction | `https://challenges.cloudflare.com/turnstile/v0/api.js` |
415
+ | `hcaptcha` | Invisible hCaptcha, with a challenge only when hCaptcha wants one | `https://js.hcaptcha.com/1/api.js` |
416
+ | `recaptcha` | reCAPTCHA v3 (a score key), with action `passflow_auth` | `https://www.google.com/recaptcha/api.js` |
417
+
418
+ A vendor check loads its script once per page, renders with the site key from the app's settings and asks for a fresh token on each request. A vendor with no site key in the settings renders nothing, and the request then fails.
419
+
420
+ When the check fails, the screen shows one message for every cause: "We could not confirm you are human. Try again." When the check is unavailable because the server or the vendor is down, it shows the "temporarily unavailable" message instead.
421
+
422
+ **Built-in check: serve the worker.** `@passflow/core` ships the worker as `@passflow/core/anti-bot-worker.js`, the file `node_modules/@passflow/core/dist/anti-bot-worker.js`. Serve it from the app's own origin and pass its URL as `antiBotWorkerUrl`. For example, copy it into a Vite or Next.js `public/` folder:
423
+
424
+ ```bash
425
+ cp node_modules/@passflow/core/dist/anti-bot-worker.js public/anti-bot-worker.js
426
+ ```
427
+
428
+ ```tsx
429
+ <PassflowProvider url={url} appId={appId} antiBotWorkerUrl='/anti-bot-worker.js'>
430
+ <App />
431
+ </PassflowProvider>
432
+ ```
433
+
434
+ The provider reads `antiBotWorkerUrl` once, when it mounts. Without it, the proof of work runs on the main thread, and the page can stall while it solves. Copy the file again after you upgrade `@passflow/core`.
435
+
436
+ **Content Security Policy.** A strict CSP must allow the vendor's hosts in `script-src` and `frame-src`. The script hosts come from the SDK; the rest follow each vendor's CSP guide, which also lists any `connect-src` or `style-src` it needs.
437
+
438
+ | Provider | `script-src` and `frame-src` |
439
+ |----------|------------------------------|
440
+ | `turnstile` | `https://challenges.cloudflare.com` |
441
+ | `hcaptcha` | `https://js.hcaptcha.com`, `https://*.hcaptcha.com` |
442
+ | `recaptcha` | `https://www.google.com/recaptcha/`, `https://www.gstatic.com/recaptcha/` |
443
+
444
+ The built-in check needs no extra host. A worker served from your own origin needs `'self'` in `worker-src`, or in `script-src`, which it falls back to.
445
+
446
+ **Your own form.** `AntiBotCheck` and `useAntiBot` are exported for a screen you build yourself. `useAntiBot(appSettings)` returns the props, or `undefined` when the app asks for no check:
447
+
448
+ ```tsx
449
+ import { AntiBotCheck, useAntiBot, useAppSettings } from '@passflow/react';
450
+
451
+ const HumanCheck = () => {
452
+ const { appSettings } = useAppSettings();
453
+ const antiBot = useAntiBot(appSettings);
454
+ return antiBot ? <AntiBotCheck {...antiBot} /> : null;
455
+ };
456
+ ```
457
+
458
+ Keep it mounted while your form sends its requests. A vendor check gives core its tokens only while it is mounted.
459
+
460
+ **WebMCP tools on a `bot_friendly` app.**
461
+
462
+ WebMCP is a browser draft API that lets an agent in the browser call tools a page registers. The sign-in and sign-up forms look for it at `document.modelContext`, then at `navigator.modelContext`. With neither, they register nothing and work as before.
463
+
464
+ A form registers only the tools for methods the app has enabled:
465
+
466
+ | Tool | Read-only | Registered when | What it does |
467
+ |------|-----------|-----------------|--------------|
468
+ | `list_auth_methods` | Yes | Always | Returns the enabled methods as JSON: password identifiers, passwordless methods, passkey and social providers |
469
+ | `get_auth_status` | Yes | Always | Answers "Signed in.", "Not signed in." or that a second factor is pending |
470
+ | `sign_in_password` | No | Sign-in form, password on | Signs in with `identifier` and `password` |
471
+ | `sign_up_password` | No | Sign-up form, password on | Creates an account with `identifier` and `password`, after the app's password rules |
472
+ | `start_passwordless` | No | Email or phone code or link on | Sends a code or a sign-in link to `identifier`. The page does not navigate |
473
+ | `complete_passwordless` | No | Email or phone code on | Finishes with `challenge_id` and `code` |
474
+ | `start_social` | No | Any social provider on | Opens the `provider` sign-in; the user finishes on the provider's page |
475
+ | `sign_in_passkey` | No | Passkey on | Starts nothing. It tells the agent to ask the user to click the passkey button |
476
+
477
+ An `identifier` is an email when it looks like one, a phone number when it starts with `+` (E.164), and a username otherwise. Each tool checks its own arguments before it sends anything, answers with a short text, and never throws.
478
+
479
+ The tools run the form's own handlers, so they send exactly the requests a person filling in the form would send. Each one passes `{ agentTool: true }` to core, and core adds the header `X-Passflow-Agent-Tool: 1`. A second factor, an emailed code or a passkey stays with the user on the page.
480
+
481
+ The form removes its tools when it unmounts. No other screen registers tools: the device approval, passwordless approval and consent screens never do, and neither does forgot-password.
482
+
397
483
  The sections below wire the app's router into the **standalone form components** (`SignIn`, `SignUp`, …) through `PassflowProvider`'s `navigate` and `router` props. `PassflowFlow` does not need them.
398
484
 
399
485
  ### React Router
@@ -787,6 +873,7 @@ The URL and the session exist only in the browser. So the server renders the flo
787
873
  | scopes | string[] | Array of required scopes |
788
874
  | router | "default" \| "react-router" \| "wouter" \| "tanstack-router" | Router being used (optional) (default is native window navigation) |
789
875
  | navigate | (options: NavigateOptions) => void | Navigation function (optional) (default is native window navigation) |
876
+ | antiBotWorkerUrl | string | Same-origin URL of `@passflow/core/anti-bot-worker.js`, for the built-in human check (optional). See [Bot mode and WebMCP tools](#bot-mode-and-webmcp-tools) |
790
877
 
791
878
  ## Form Components
792
879
 
@@ -996,10 +1083,11 @@ The bundled `SignIn` form does this for you: it opens `ForgotPassword` with the
996
1083
 
997
1084
  | Property | Type | Description |
998
1085
  |----------|------|-------------|
999
- | fetch | `(payload: PassflowPasskeyAuthenticateStartPayload \| PassflowSignInPayload \| PassflowPasswordlessSignInPayload, type: 'passkey' \| 'password' \| 'passwordless') => Promise<false \| SignInOutcome \| PassflowPasswordlessResponse>` | Sign in function |
1086
+ | fetch | `(payload: PassflowPasskeyAuthenticateStartPayload \| PassflowSignInPayload \| PassflowPasswordlessSignInPayload, type: 'passkey' \| 'password' \| 'passwordless', options?: PassflowAuthOptions) => Promise<false \| SignInOutcome \| PassflowPasswordlessResponse>` | Sign in function. `options` goes to core as the request's last argument |
1000
1087
  | isLoading | `boolean` | Loading state |
1001
1088
  | isError | `boolean` | Error state |
1002
1089
  | error | `string` | Error message |
1090
+ | readError | `() => AuthUiError \| null` | The error the latest `fetch` set; `null` after a success or `reset()`. Readable right after `await fetch()`, before the next render |
1003
1091
 
1004
1092
  `fetch` resolves one of:
1005
1093
 
@@ -1023,10 +1111,11 @@ const { fetch, isLoading, isError, error } = useSignUp();
1023
1111
 
1024
1112
  | Property | Type | Description |
1025
1113
  |----------|------|-------------|
1026
- | fetch | `(payload: PassflowPasskeyRegisterStartPayload \| PassflowSignUpPayload \| PassflowPasswordlessSignInPayload, type: 'passkey' \| 'password' \| 'passwordless') => Promise<false \| SignInOutcome \| PassflowPasswordlessResponse>` | Sign up function |
1114
+ | fetch | `(payload: PassflowPasskeyRegisterStartPayload \| PassflowSignUpPayload \| PassflowPasswordlessSignInPayload, type: 'passkey' \| 'password' \| 'passwordless', options?: PassflowAuthOptions) => Promise<false \| SignInOutcome \| PassflowPasswordlessResponse>` | Sign up function. `options` goes to core as the request's last argument |
1027
1115
  | isLoading | `boolean` | Loading state |
1028
1116
  | isError | `boolean` | Error state |
1029
1117
  | error | `string` | Error message |
1118
+ | readError | `() => AuthUiError \| null` | The error the latest `fetch` set; `null` after a success or `reset()`. Readable right after `await fetch()`, before the next render |
1030
1119
 
1031
1120
  `fetch` resolves the same outcomes as `useSignIn().fetch`.
1032
1121
 
@@ -1059,8 +1148,8 @@ const { federatedWithPopup, federatedWithRedirect } = useProvider(redirectUrl);
1059
1148
 
1060
1149
  | Property | Type | Description |
1061
1150
  |----------|------|-------------|
1062
- | federatedWithPopup | `(provider: Providers) => void` | Popup authentication function |
1063
- | federatedWithRedirect | `(provider: Providers) => void` | Redirect authentication function |
1151
+ | federatedWithPopup | `(provider: Providers, inviteToken?: string, options?: PassflowAuthOptions) => void` | Popup authentication function |
1152
+ | federatedWithRedirect | `(provider: Providers, inviteToken?: string, options?: PassflowAuthOptions) => void` | Redirect authentication function |
1064
1153
 
1065
1154
  ### useResetPassword
1066
1155
  Hook for resetting user password.
@@ -1190,10 +1279,11 @@ const { fetch, isLoading, isError, error } = usePasswordlessComplete();
1190
1279
 
1191
1280
  | Property | Type | Description |
1192
1281
  |----------|------|-------------|
1193
- | fetch | `(payload: PassflowPasswordlessSignInCompletePayload) => Promise<PassflowValidationResponse \| null>` | Complete passwordless auth function |
1282
+ | fetch | `(payload: PassflowPasswordlessSignInCompletePayload, options?: PassflowAuthOptions) => Promise<PassflowValidationResponse \| null>` | Complete passwordless auth function |
1194
1283
  | isLoading | `boolean` | Loading state |
1195
1284
  | isError | `boolean` | Error state |
1196
1285
  | error | `string` | Error message |
1286
+ | readError | `() => string` | The same text as `error` (`''` when none), readable right after `await fetch()` |
1197
1287
 
1198
1288
  ### useSessionExpired
1199
1289
  Hook for reacting to the end of a session, for example to redirect to your login page.