@passflow/react 0.26.2 → 0.28.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 (66) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +89 -3
  3. package/dist/index.cjs +2 -1
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.es.js +105 -104
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/src/components/flow/consent/index.d.cts +1 -11
  8. package/dist/src/components/flow/consent/index.d.ts +1 -11
  9. package/dist/src/components/flow/consent/index.d.ts.map +1 -1
  10. package/dist/src/components/flow/device-verify/index.d.cts +1 -8
  11. package/dist/src/components/flow/device-verify/index.d.ts +1 -8
  12. package/dist/src/components/flow/device-verify/index.d.ts.map +1 -1
  13. package/dist/src/components/flow/two-factor-setup/index.d.ts.map +1 -1
  14. package/dist/src/components/flow/two-factor-setup-magic-link/index.d.cts +0 -13
  15. package/dist/src/components/flow/two-factor-setup-magic-link/index.d.ts +0 -13
  16. package/dist/src/components/flow/two-factor-setup-magic-link/index.d.ts.map +1 -1
  17. package/dist/src/components/flow/two-factor-verify/index.d.ts.map +1 -1
  18. package/dist/src/components/form/forgot-password/forgot-password-success.d.cts +1 -1
  19. package/dist/src/components/form/forgot-password/forgot-password-success.d.ts +1 -1
  20. package/dist/src/components/form/forgot-password/forgot-password-success.d.ts.map +1 -1
  21. package/dist/src/components/form/forgot-password/forgot-password.d.ts.map +1 -1
  22. package/dist/src/components/form/reset-password/index.d.ts.map +1 -1
  23. package/dist/src/components/form/signin/index.d.ts.map +1 -1
  24. package/dist/src/components/form/signup/index.d.ts.map +1 -1
  25. package/dist/src/components/form/two-factor-verify/two-factor-verify-form.d.ts.map +1 -1
  26. package/dist/src/components/form/verify-challenge/verify-challenge-magic-link.d.ts.map +1 -1
  27. package/dist/src/components/form/verify-challenge/verify-challenge-otp.d.ts.map +1 -1
  28. package/dist/src/components/login-button/index.d.cts +6 -2
  29. package/dist/src/components/login-button/index.d.ts +6 -2
  30. package/dist/src/components/login-button/index.d.ts.map +1 -1
  31. package/dist/src/components/provider/passflow-provider.d.ts.map +1 -1
  32. package/dist/src/components/provider/upgrade-provider.d.cts +1 -1
  33. package/dist/src/components/provider/upgrade-provider.d.ts +1 -1
  34. package/dist/src/components/provider/upgrade-provider.d.ts.map +1 -1
  35. package/dist/src/components/ui/fields/field-otp.d.cts +3 -5
  36. package/dist/src/components/ui/fields/field-otp.d.ts +3 -5
  37. package/dist/src/components/ui/fields/field-otp.d.ts.map +1 -1
  38. package/dist/src/components/ui/login-button/use-shadcn-theme.d.cts +1 -1
  39. package/dist/src/components/ui/login-button/use-shadcn-theme.d.ts +1 -1
  40. package/dist/src/components/ui/login-button/use-shadcn-theme.d.ts.map +1 -1
  41. package/dist/src/dev-account.d.ts.map +1 -1
  42. package/dist/src/hocs/index.d.cts +1 -0
  43. package/dist/src/hocs/index.d.ts +1 -0
  44. package/dist/src/hocs/index.d.ts.map +1 -1
  45. package/dist/src/hocs/with-error.d.ts.map +1 -1
  46. package/dist/src/hocs/with-hydration.d.cts +8 -0
  47. package/dist/src/hocs/with-hydration.d.ts +8 -0
  48. package/dist/src/hocs/with-hydration.d.ts.map +1 -0
  49. package/dist/src/hooks/use-app-settings.d.ts.map +1 -1
  50. package/dist/src/hooks/use-auth-cloud-redirect.d.ts.map +1 -1
  51. package/dist/src/hooks/use-isomorphic-layout-effect.d.cts +7 -0
  52. package/dist/src/hooks/use-isomorphic-layout-effect.d.ts +7 -0
  53. package/dist/src/hooks/use-isomorphic-layout-effect.d.ts.map +1 -0
  54. package/dist/src/hooks/use-trusted-devices.d.ts.map +1 -1
  55. package/dist/src/hooks/use-two-factor-status.d.ts.map +1 -1
  56. package/dist/src/hooks/use-user-passkeys.d.ts.map +1 -1
  57. package/dist/src/index.d.cts +1 -0
  58. package/dist/src/index.d.ts +1 -0
  59. package/dist/src/index.d.ts.map +1 -1
  60. package/dist/src/utils/hosted-sign-in.d.cts +20 -0
  61. package/dist/src/utils/hosted-sign-in.d.ts +20 -0
  62. package/dist/src/utils/hosted-sign-in.d.ts.map +1 -0
  63. package/dist/src/utils/index.d.cts +1 -0
  64. package/dist/src/utils/index.d.ts +1 -0
  65. package/dist/src/utils/index.d.ts.map +1 -1
  66. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -2,6 +2,34 @@
2
2
 
3
3
  All notable changes to `@passflow/react` are documented in this file.
4
4
 
5
+ ## [0.28.0] - 2026-11-21
6
+
7
+ ### Changed
8
+
9
+ - A hosted sign-in started by the SDK now asks to return to the app root, `${origin}/`, instead of the page it started on. That covers `LoginButton`, the default step-up sign-in, the "Sign in again" action and `useAuthCloudRedirect`. After the sign-in, `PassflowProvider` takes the user back to the page they started on. Register `${origin}/` as a redirect URL of the app. Before, a sign-in started on a page such as `/account/settings` asked to return to that page and the hosted login refused it with "redirect_uri not registered for this client" unless that exact page was registered.
10
+ - A hosted sign-out with no `postLogoutRedirectUri` now returns to `${origin}/` too, since it defaults to the address the sign-in returned to.
11
+ - A `redirectUrl` passed in `authRedirectOptions` (or to `startHostedSignIn()`) is used as before, and the user stays where it lands. An app served under a sub-path (Vite `base: '/app/'`) passes `redirectUrl`, such as `${origin}/app/`, to `LoginButton`'s `authRedirectOptions` or to `startHostedSignIn()`, since the origin root is not its page.
12
+
13
+ ### Added
14
+
15
+ - `startHostedSignIn(passflow, options?)` starts the hosted sign-in the same way, for an app with its own sign-in button.
16
+
17
+ ## [0.27.0] - 2026-11-21
18
+
19
+ ### Fixed
20
+
21
+ - A server render in Node no longer throws `window is not defined`. `PassflowFlow` and every public screen render on the server with `PassflowProvider` around them. No component reads `window` or `document` during render.
22
+ - A screen that reads the URL or the session renders nothing on the server and in the hydration render. It shows its content in the render right after hydration, so the server HTML and the browser's first render match. This covers `PassflowFlow`, `SignIn`, `SignUp`, `SignInForm`, `SignUpForm`, `InvitationJoin`, `ForgotPassword`, `ForgotPasswordSuccess`, `ResetPassword`, `VerifyChallengeOTP`, `VerifyChallengeMagicLink`, `TwoFactorVerifyFlow`, `TwoFactorVerifyForm`, `TwoFactorSetupFlow`, `TwoFactorSetupMagicLinkFlow`, `ConsentFlow` and `DeviceVerifyFlow`. A page rendered only in the browser shows them from its first render, as before.
23
+ - On a server-rendered page, a sign-in landing that owes its second factor goes to the flow's own 2FA route, such as `/auth/two-factor-verify`. It went to `/two-factor-verify` when the flow had a `pathPrefix`.
24
+ - `next build` with `cacheComponents` no longer stops on "unstable value `crypto.randomUUID()` in a Client Component". `@passflow/core` 0.32.1 mints its device id when the first request goes out, not while `PassflowProvider` renders. The minimum `@passflow/core` is now 0.32.1.
25
+ - React 18 no longer warns "useLayoutEffect does nothing on the server" from `PassflowProvider` and the hooks under it.
26
+ - On React 18, `FieldOtp` passes its `ref` to the code input and no longer warns that `ref` is not a prop.
27
+
28
+ ### Added
29
+
30
+ - The bundles start with `'use client'`. A Next.js server component, such as `app/layout.tsx`, can import `PassflowProvider` and the other components from `@passflow/react` directly, with no `'use client'` wrapper of its own. Before, its build stopped on "Export Controller doesn't exist in target module".
31
+ - The README shows how to mount `PassflowFlow` in a Next.js App Router app: on an optional catch-all route under a prefix (`app/auth/[[...passflow]]/page.tsx`), so a reload of any flow path reaches the flow page; with `location` and `navigate` from Next.js's router, so leaving the flow loads the next page; and with the provider in the route's layout. A flow at the root uses `app/page.tsx` plus a required catch-all, `app/[...passflow]/page.tsx`, with `pathPrefix=""`.
32
+
5
33
  ## [0.26.2] - 2026-11-20
6
34
 
7
35
  ### Fixed
package/README.md CHANGED
@@ -22,6 +22,7 @@ This is a SDK for react application.
22
22
  - [React Router](#react-router)
23
23
  - [Wouter](#wouter)
24
24
  - [TanStack Router](#tanstack-router)
25
+ - [Next.js (App Router)](#nextjs-app-router)
25
26
  - [Props](#props)
26
27
  - [PassflowProvider](#passflowprovider)
27
28
  - [Form Components](#form-components)
@@ -320,7 +321,7 @@ import { LoginButton } from '@passflow/react';
320
321
  <LoginButton />;
321
322
  ```
322
323
 
323
- Signed out, it shows **Sign in** (`signInLabel`) and a click starts the hosted sign-in, `passflow.authRedirect(authRedirectOptions)`. Signed in, it shows the user's email (`signedInLabel={(user) => …}`) and a click signs out with `useAuth().logout()`, which also ends the hosted session after a hosted sign-in; `postLogoutRedirectUri` says where the browser lands. The button is disabled and `aria-busy` while the sign-out is in flight, and it switches on sign-in and sign-out events.
324
+ Signed out, it shows **Sign in** (`signInLabel`) and a click starts the hosted sign-in, `startHostedSignIn(passflow, authRedirectOptions)`. Signed in, it shows the user's email (`signedInLabel={(user) => …}`) and a click signs out with `useAuth().logout()`, which also ends the hosted session after a hosted sign-in; `postLogoutRedirectUri` says where the browser lands. The button is disabled and `aria-busy` while the sign-out is in flight, and it switches on sign-in and sign-out events.
324
325
 
325
326
  To use your own button, wrap it. Your element becomes the button: it keeps its props, content and look, and gets a click handler that calls its own `onClick` first, then signs in or out unless that called `event.preventDefault()` (a component that calls `onClick()` with no event still signs in or out). No label is injected, so its text stays as you wrote it. While the sign-out is in flight it gets `disabled` and `aria-busy`; otherwise those stay as you passed them. For text that switches, pass a function, which also receives `busy`:
326
327
 
@@ -338,6 +339,19 @@ In an app styled with shadcn/ui, `appearance="shadcn"` takes `--primary`, `--pri
338
339
  <LoginButton appearance='shadcn' />
339
340
  ```
340
341
 
342
+ #### Where the hosted sign-in returns
343
+
344
+ The redirect URL the SDK sends is the app root, `${origin}/`, unless `authRedirectOptions.redirectUrl` is given. Register `${origin}/` as a redirect URL of the app. The page the user started on is kept in sessionStorage, and once the provider has taken the sign-in at `/` it navigates back there with `replace`, so a sign-in started on `/account/settings?tab=2` ends on that page. A `redirectUrl` you pass is sent as it is, and the user lands there instead. An app served under a sub-path (Vite `base: '/app/'`) is not at the origin root, so it passes its own `redirectUrl`, such as `${origin}/app/`, in `LoginButton`'s `authRedirectOptions` or to `startHostedSignIn()`.
345
+
346
+ Every hosted sign-in the SDK starts works this way: `LoginButton`, `useAuthCloudRedirect`, and the step-up and "sign in again" fallbacks. For a button of your own, call the same function:
347
+
348
+ ```tsx
349
+ import { startHostedSignIn, usePassflow } from '@passflow/react';
350
+
351
+ const passflow = usePassflow();
352
+ <button type='button' onClick={() => void startHostedSignIn(passflow)}>Sign in</button>;
353
+ ```
354
+
341
355
  ### Two-factor setup for a signed-in user
342
356
 
343
357
  When the app's two-factor policy is **Optional**, sign-in does not ask the user to set up an authenticator. Let a signed-in user turn it on from your own page with one component:
@@ -372,7 +386,7 @@ The dialog offers the factors the server lists in `available_factors`, in its or
372
386
  | Rate limited | "Too many attempts. Try again in 30 seconds.", with the wait in seconds, minutes, hours or days, rounded up ("15 minutes", "1 day"), or the server's own text when it names no wait. No new code is asked for. |
373
387
  | Insufficient (verified, but the call was challenged again) | The levels reached and required, with **Sign in again**, which calls `upgrade.onSignInRequired`. |
374
388
 
375
- `upgrade.onSignInRequired` is where those sign-ins go. By default it opens the app's own sign-in route when a `PassflowFlow` is mounted, and otherwise calls `passflow.authRedirect()`. Pass your own to send the user somewhere else:
389
+ `upgrade.onSignInRequired` is where those sign-ins go. By default it opens the app's own sign-in route when a `PassflowFlow` is mounted, and otherwise calls `startHostedSignIn(passflow)`. Pass your own to send the user somewhere else:
376
390
 
377
391
  ```tsx
378
392
  <PassflowProvider {...config} upgrade={{ interceptFetch: true, onSignInRequired: () => router.navigate('/login') }}>
@@ -690,6 +704,77 @@ export const routerTree = rootRoute.addChildren([
690
704
  ]);
691
705
  ```
692
706
 
707
+ ### Next.js (App Router)
708
+
709
+ Three things make the flow work in the App Router:
710
+
711
+ - **A catch-all route.** The flow moves the address to `/auth/signin`, `/auth/signup`, `/auth/two-factor-verify` and its other paths. Mount it on an optional catch-all, `app/auth/[[...passflow]]/page.tsx`, so a reload of any of them reaches the flow page.
712
+ - **Next.js's router.** Pass the flow `location` and `navigate` from `next/navigation`. A change the flow makes to the address on its own does not load another page in Next.js, so leaving the flow, for example after sign-in, needs the router.
713
+ - **The provider in a layout.** `app/auth/layout.tsx` stays mounted while the flow moves between its paths, so the provider keeps its state. Give it `twoFactorVerifyPath`, the flow's second-factor path under the prefix. Without it, a sign-in that comes back owing a second factor can go to `/two-factor-verify` instead of `/auth/two-factor-verify`, because the flow behind the page's Suspense boundary has not told the provider its path yet.
714
+
715
+ The package is client code and says so (`'use client'`), so a server component, such as this layout, can import from it directly.
716
+
717
+ ```tsx
718
+ // app/auth/layout.tsx
719
+ import { PassflowProvider } from '@passflow/react';
720
+ import '@passflow/react/dist/style.css';
721
+ import type { ReactNode } from 'react';
722
+
723
+ export default function AuthLayout({ children }: { children: ReactNode }) {
724
+ return (
725
+ <PassflowProvider
726
+ url={process.env.NEXT_PUBLIC_PASSFLOW_URL}
727
+ appId={process.env.NEXT_PUBLIC_PASSFLOW_APP_ID}
728
+ twoFactorVerifyPath="/auth/two-factor-verify"
729
+ >
730
+ {children}
731
+ </PassflowProvider>
732
+ );
733
+ }
734
+ ```
735
+
736
+ The flow page is a client component: it reads Next.js's router and hands the flow a function.
737
+
738
+ ```tsx
739
+ // app/auth/[[...passflow]]/page.tsx
740
+ 'use client';
741
+
742
+ import { PassflowFlow } from '@passflow/react';
743
+ import { usePathname, useRouter, useSearchParams } from 'next/navigation';
744
+ import { Suspense } from 'react';
745
+
746
+ function Flow() {
747
+ const pathname = usePathname();
748
+ const searchParams = useSearchParams();
749
+ const router = useRouter();
750
+ return (
751
+ <PassflowFlow
752
+ pathPrefix="/auth"
753
+ successAuthRedirect="/dashboard"
754
+ location={{ pathname, search: searchParams.toString() }}
755
+ navigate={(to, { replace }) => {
756
+ const href = `${to.pathname}${to.search}${to.hash ?? ''}`;
757
+ if (replace) router.replace(href);
758
+ else router.push(href);
759
+ }}
760
+ />
761
+ );
762
+ }
763
+
764
+ // useSearchParams needs a Suspense boundary in a prerendered page.
765
+ export default function PassflowPage() {
766
+ return (
767
+ <Suspense>
768
+ <Flow />
769
+ </Suspense>
770
+ );
771
+ }
772
+ ```
773
+
774
+ **The flow at the root.** Next.js does not allow `app/[[...passflow]]/page.tsx` beside `app/page.tsx`. Put the provider around `children` in `app/layout.tsx`, render the flow from both `app/page.tsx` and a required catch-all, `app/[...passflow]/page.tsx`, and pass `pathPrefix=""` and `twoFactorVerifyPath="/two-factor-verify"`. Next.js's own routes, such as `/dashboard`, still win over the catch-all. Any other unknown path reaches the flow, which moves it to `/signin`, instead of a 404.
775
+
776
+ The URL and the session exist only in the browser. So the server renders the flow's screens as nothing, and the browser shows them right after hydration.
777
+
693
778
  ## Props
694
779
 
695
780
  ### PassflowProvider
@@ -817,7 +902,8 @@ When the user signed in through the hosted login (`authRedirect()`), `logout()`
817
902
  ```tsx
818
903
  const { logout } = useAuth();
819
904
 
820
- // Must match one of the app's registered redirect URLs. Default: the address the hosted sign-in landed on.
905
+ // Must match one of the app's registered redirect URLs. Default: the address the hosted sign-in landed on, the app root
906
+ // when the SDK started it.
821
907
  await logout({ postLogoutRedirectUri: 'https://app.example.com/signed-out' });
822
908
  ```
823
909