@zautha/react 0.1.0 → 0.3.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.
- package/README.md +21 -0
- package/dist/index.cjs +86 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -4
- package/dist/index.d.mts +15 -4
- package/dist/index.mjs +63 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -30,6 +30,27 @@ export function App() {
|
|
|
30
30
|
}
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
## Account management
|
|
34
|
+
|
|
35
|
+
`<UserProfile />` is the signed-in user's account page: name and username, email addresses, password, active
|
|
36
|
+
devices and (when the instance allows it) account deletion. `<UserButton />`'s "Manage account" opens it in a modal, or
|
|
37
|
+
goes to `userProfileUrl` when you pass one (e.g. your instance's hosted `/user` page).
|
|
38
|
+
|
|
39
|
+
## Sensitive actions (reverification)
|
|
40
|
+
|
|
41
|
+
`useReverification(fetcher)` wraps an action that may need a recent identity check. When `fetcher` throws
|
|
42
|
+
`ReverificationRequiredError` (e.g. `user.updatePassword`) or resolves to your backend's `403 reverification_required`
|
|
43
|
+
response (`requireReverification` in `@zautha/backend`, `reverificationError` in `@zautha/nextjs`,
|
|
44
|
+
`RequireZauthaReverification` in `Zautha.AspNetCore`), a modal asks the user to verify and the action runs once more.
|
|
45
|
+
Closing the modal rejects with `ReverificationCancelledError`.
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
const { getToken } = useAuth();
|
|
49
|
+
const transfer = useReverification(async () =>
|
|
50
|
+
fetch("/api/transfer", { method: "POST", headers: { Authorization: `Bearer ${await getToken()}` } }),
|
|
51
|
+
);
|
|
52
|
+
```
|
|
53
|
+
|
|
33
54
|
## License
|
|
34
55
|
|
|
35
56
|
MIT, see [LICENSE](./LICENSE).
|
package/dist/index.cjs
CHANGED
|
@@ -8,11 +8,15 @@ const ZauthaContext = (0, react.createContext)(void 0);
|
|
|
8
8
|
/**
|
|
9
9
|
* Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR
|
|
10
10
|
* create no timers or channels), loads it, and disposes it on unmount. Until then hooks report
|
|
11
|
-
* `isLoaded: false
|
|
11
|
+
* `isLoaded: false`, unless `initialState` (the server's view, e.g. from @zautha/nextjs) says who is signed in.
|
|
12
12
|
*/
|
|
13
13
|
function ZauthaProvider({ publishableKey, children, ...options }) {
|
|
14
14
|
const [zautha, setZautha] = (0, react.useState)(null);
|
|
15
|
-
const { ui, appearance, localization, signInUrl, signUpUrl, navigate } = options;
|
|
15
|
+
const { ui, appearance, localization, signInUrl, signUpUrl, navigate, initialState } = options;
|
|
16
|
+
const [pending] = (0, react.useState)(() => ({
|
|
17
|
+
...NO_STATE,
|
|
18
|
+
initialState: initialState ?? null
|
|
19
|
+
}));
|
|
16
20
|
(0, react.useEffect)(() => {
|
|
17
21
|
const instance = new _zautha_js.Zautha(publishableKey, {
|
|
18
22
|
...ui === void 0 ? {} : { ui },
|
|
@@ -20,7 +24,8 @@ function ZauthaProvider({ publishableKey, children, ...options }) {
|
|
|
20
24
|
...localization === void 0 ? {} : { localization },
|
|
21
25
|
...signInUrl === void 0 ? {} : { signInUrl },
|
|
22
26
|
...signUpUrl === void 0 ? {} : { signUpUrl },
|
|
23
|
-
...navigate === void 0 ? {} : { navigate }
|
|
27
|
+
...navigate === void 0 ? {} : { navigate },
|
|
28
|
+
...initialState === void 0 ? {} : { initialState }
|
|
24
29
|
});
|
|
25
30
|
setZautha(instance);
|
|
26
31
|
instance.load();
|
|
@@ -29,29 +34,37 @@ function ZauthaProvider({ publishableKey, children, ...options }) {
|
|
|
29
34
|
setZautha(null);
|
|
30
35
|
};
|
|
31
36
|
}, [publishableKey]);
|
|
37
|
+
const value = (0, react.useMemo)(() => ({
|
|
38
|
+
zautha,
|
|
39
|
+
pending
|
|
40
|
+
}), [zautha, pending]);
|
|
32
41
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ZauthaContext.Provider, {
|
|
33
|
-
value
|
|
42
|
+
value,
|
|
34
43
|
children
|
|
35
44
|
});
|
|
36
45
|
}
|
|
37
46
|
/** The Zautha instance, or null before the provider has created it. */
|
|
38
47
|
function useZautha() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
return useZauthaContext().zautha;
|
|
49
|
+
}
|
|
50
|
+
function useZauthaContext() {
|
|
51
|
+
const value = (0, react.useContext)(ZauthaContext);
|
|
52
|
+
if (value === void 0) throw new Error("Zautha hooks and components must be used inside <ZauthaProvider>.");
|
|
53
|
+
return value;
|
|
42
54
|
}
|
|
43
55
|
const NO_STATE = {
|
|
44
56
|
status: "loading",
|
|
45
57
|
environment: null,
|
|
46
58
|
client: null,
|
|
47
59
|
session: null,
|
|
48
|
-
user: null
|
|
60
|
+
user: null,
|
|
61
|
+
initialState: null
|
|
49
62
|
};
|
|
50
63
|
const noop = () => () => void 0;
|
|
51
|
-
/** Reactive snapshot of the instance state (the loading state before the instance exists). */
|
|
64
|
+
/** Reactive snapshot of the instance state (the loading state, with any initial state, before the instance exists). */
|
|
52
65
|
function useZauthaState() {
|
|
53
|
-
const zautha =
|
|
54
|
-
return (0, react.useSyncExternalStore)(zautha?.subscribe ?? noop, () => zautha?.getSnapshot() ??
|
|
66
|
+
const { zautha, pending } = useZauthaContext();
|
|
67
|
+
return (0, react.useSyncExternalStore)(zautha?.subscribe ?? noop, () => zautha?.getSnapshot() ?? pending, () => pending);
|
|
55
68
|
}
|
|
56
69
|
//#endregion
|
|
57
70
|
//#region src/hooks.ts
|
|
@@ -61,26 +74,51 @@ function useAuth() {
|
|
|
61
74
|
const state = useZauthaState();
|
|
62
75
|
const getToken = (0, react.useCallback)((options) => zautha?.getToken(options) ?? Promise.resolve(null), [zautha]);
|
|
63
76
|
const signOut = (0, react.useCallback)((options) => zautha?.signOut(options) ?? Promise.resolve(), [zautha]);
|
|
64
|
-
const
|
|
77
|
+
const initial = state.status === "loading" ? state.initialState : null;
|
|
78
|
+
const userId = initial === null ? state.session?.userId ?? null : initial.userId;
|
|
79
|
+
const sessionId = initial === null ? state.session?.id ?? null : initial.sessionId;
|
|
80
|
+
const signedIn = userId !== null;
|
|
65
81
|
const has = (0, react.useCallback)((params) => signedIn && params.role === void 0 && params.permission === void 0, [signedIn]);
|
|
66
82
|
return {
|
|
67
|
-
isLoaded: isLoadedStatus(state.status),
|
|
83
|
+
isLoaded: isLoadedStatus(state.status) || initial !== null,
|
|
68
84
|
isSignedIn: signedIn,
|
|
69
|
-
userId
|
|
70
|
-
sessionId
|
|
85
|
+
userId,
|
|
86
|
+
sessionId,
|
|
71
87
|
getToken,
|
|
72
88
|
signOut,
|
|
73
89
|
has
|
|
74
90
|
};
|
|
75
91
|
}
|
|
92
|
+
/** The signed-in user with its self-service actions (`user.update`, `user.createEmailAddress`, …). */
|
|
76
93
|
function useUser() {
|
|
94
|
+
const zautha = useZautha();
|
|
77
95
|
const state = useZauthaState();
|
|
96
|
+
const user = state.user === null ? null : zautha?.user ?? null;
|
|
78
97
|
return {
|
|
79
98
|
isLoaded: isLoadedStatus(state.status),
|
|
80
99
|
isSignedIn: state.session !== null,
|
|
81
|
-
user
|
|
100
|
+
user
|
|
82
101
|
};
|
|
83
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Wraps a sensitive action so that it completes after an identity check when it needs one: when `fetcher` throws
|
|
105
|
+
* `ReverificationRequiredError` (e.g. `user.updatePassword`) or resolves to a `Response` with the `403
|
|
106
|
+
* reverification_required` body (your backend with @zautha/backend, @zautha/nextjs or Zautha.AspNetCore), the
|
|
107
|
+
* reverification modal opens and, once the user has verified, `fetcher` runs once more with the same arguments (its
|
|
108
|
+
* token is fresh by then). Closing the modal rejects with `ReverificationCancelledError`. Needs `ui` from @zautha/ui on
|
|
109
|
+
* the provider. The returned function is stable; it always calls the latest `fetcher`.
|
|
110
|
+
*/
|
|
111
|
+
function useReverification(fetcher) {
|
|
112
|
+
const zautha = useZautha();
|
|
113
|
+
const latest = (0, react.useRef)(fetcher);
|
|
114
|
+
(0, react.useLayoutEffect)(() => {
|
|
115
|
+
latest.current = fetcher;
|
|
116
|
+
});
|
|
117
|
+
return (0, react.useCallback)((...args) => {
|
|
118
|
+
const call = (...callArgs) => latest.current(...callArgs);
|
|
119
|
+
return zautha === null ? call(...args) : (0, _zautha_js.withReverification)(zautha, call)(...args);
|
|
120
|
+
}, [zautha]);
|
|
121
|
+
}
|
|
84
122
|
function useSession() {
|
|
85
123
|
const state = useZauthaState();
|
|
86
124
|
return {
|
|
@@ -265,6 +303,12 @@ function UserButton(props) {
|
|
|
265
303
|
componentProps: props
|
|
266
304
|
});
|
|
267
305
|
}
|
|
306
|
+
function UserProfile(props) {
|
|
307
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Mounted, {
|
|
308
|
+
name: "UserProfile",
|
|
309
|
+
componentProps: props
|
|
310
|
+
});
|
|
311
|
+
}
|
|
268
312
|
function OAuthConsent(props) {
|
|
269
313
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Mounted, {
|
|
270
314
|
name: "OAuthConsent",
|
|
@@ -275,6 +319,18 @@ function OAuthConsent(props) {
|
|
|
275
319
|
exports.OAuthConsent = OAuthConsent;
|
|
276
320
|
exports.RedirectToSignIn = RedirectToSignIn;
|
|
277
321
|
exports.RedirectToSignUp = RedirectToSignUp;
|
|
322
|
+
Object.defineProperty(exports, "ReverificationCancelledError", {
|
|
323
|
+
enumerable: true,
|
|
324
|
+
get: function() {
|
|
325
|
+
return _zautha_js.ReverificationCancelledError;
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
Object.defineProperty(exports, "ReverificationRequiredError", {
|
|
329
|
+
enumerable: true,
|
|
330
|
+
get: function() {
|
|
331
|
+
return _zautha_js.ReverificationRequiredError;
|
|
332
|
+
}
|
|
333
|
+
});
|
|
278
334
|
exports.Show = Show;
|
|
279
335
|
exports.SignIn = SignIn;
|
|
280
336
|
exports.SignInButton = SignInButton;
|
|
@@ -282,6 +338,7 @@ exports.SignOutButton = SignOutButton;
|
|
|
282
338
|
exports.SignUp = SignUp;
|
|
283
339
|
exports.SignUpButton = SignUpButton;
|
|
284
340
|
exports.UserButton = UserButton;
|
|
341
|
+
exports.UserProfile = UserProfile;
|
|
285
342
|
Object.defineProperty(exports, "ZauthaApiError", {
|
|
286
343
|
enumerable: true,
|
|
287
344
|
get: function() {
|
|
@@ -311,6 +368,18 @@ Object.defineProperty(exports, "ZauthaOfflineError", {
|
|
|
311
368
|
}
|
|
312
369
|
});
|
|
313
370
|
exports.ZauthaProvider = ZauthaProvider;
|
|
371
|
+
Object.defineProperty(exports, "isReverificationCancelledError", {
|
|
372
|
+
enumerable: true,
|
|
373
|
+
get: function() {
|
|
374
|
+
return _zautha_js.isReverificationCancelledError;
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
Object.defineProperty(exports, "isReverificationRequiredError", {
|
|
378
|
+
enumerable: true,
|
|
379
|
+
get: function() {
|
|
380
|
+
return _zautha_js.isReverificationRequiredError;
|
|
381
|
+
}
|
|
382
|
+
});
|
|
314
383
|
Object.defineProperty(exports, "isZauthaApiError", {
|
|
315
384
|
enumerable: true,
|
|
316
385
|
get: function() {
|
|
@@ -336,6 +405,7 @@ Object.defineProperty(exports, "isZauthaOfflineError", {
|
|
|
336
405
|
}
|
|
337
406
|
});
|
|
338
407
|
exports.useAuth = useAuth;
|
|
408
|
+
exports.useReverification = useReverification;
|
|
339
409
|
exports.useSession = useSession;
|
|
340
410
|
exports.useSignIn = useSignIn;
|
|
341
411
|
exports.useSignUp = useSignUp;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["createContext","useState","Zautha","useContext","useSyncExternalStore","useCallback","useSyncExternalStore","Children","isValidElement","cloneElement","useRef"],"sources":["../src/provider.tsx","../src/hooks.ts","../src/control.tsx","../src/buttons.tsx","../src/prebuilt.tsx"],"sourcesContent":["import { Zautha, type ZauthaOptions, type ZauthaState } from \"@zautha/js\";\nimport { createContext, useContext, useEffect, useState, useSyncExternalStore, type ReactNode } from \"react\";\n\nconst ZauthaContext = createContext<Zautha | null | undefined>(undefined);\n\nexport interface ZauthaProviderProps extends Omit<ZauthaOptions, \"fetch\"> {\n publishableKey: string;\n children?: ReactNode;\n}\n\n/**\n * Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR\n * create no timers or channels), loads it, and disposes it on unmount. Until then hooks report\n * `isLoaded: false`.\n */\nexport function ZauthaProvider({ publishableKey, children, ...options }: ZauthaProviderProps): ReactNode {\n const [zautha, setZautha] = useState<Zautha | null>(null);\n const { ui, appearance, localization, signInUrl, signUpUrl, navigate } = options;\n\n useEffect(() => {\n const instance = new Zautha(publishableKey, {\n ...(ui === undefined ? {} : { ui }),\n ...(appearance === undefined ? {} : { appearance }),\n ...(localization === undefined ? {} : { localization }),\n ...(signInUrl === undefined ? {} : { signInUrl }),\n ...(signUpUrl === undefined ? {} : { signUpUrl }),\n ...(navigate === undefined ? {} : { navigate }),\n });\n // The instance is an external system: it is created here, never during render, and published through state.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setZautha(instance);\n void instance.load();\n return () => {\n instance.dispose();\n setZautha(null);\n };\n // Appearance/localization objects are read at mount; changing the key re-creates the instance.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [publishableKey]);\n\n return <ZauthaContext.Provider value={zautha}>{children}</ZauthaContext.Provider>;\n}\n\n/** The Zautha instance, or null before the provider has created it. */\nexport function useZautha(): Zautha | null {\n const zautha = useContext(ZauthaContext);\n if (zautha === undefined) throw new Error(\"Zautha hooks and components must be used inside <ZauthaProvider>.\");\n return zautha;\n}\n\nconst NO_STATE: ZauthaState = { status: \"loading\", environment: null, client: null, session: null, user: null };\nconst noop = (): (() => void) => () => undefined;\n\n/** Reactive snapshot of the instance state (the loading state before the instance exists). */\nexport function useZauthaState(): ZauthaState {\n const zautha = useZautha();\n return useSyncExternalStore(\n zautha?.subscribe ?? noop,\n () => zautha?.getSnapshot() ?? NO_STATE,\n () => NO_STATE,\n );\n}\n","import type { AttemptErrors, FetchStatus, Session, SignInResource, SignUpResource, User } from \"@zautha/js\";\nimport { useCallback, useSyncExternalStore } from \"react\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\n/** Authorization check. In 3a there are no organization claims yet, so role/permission checks are false. */\nexport type HasParams = { role?: string; permission?: string };\nexport type Has = (params: HasParams) => boolean;\n\nexport interface UseAuthResult {\n isLoaded: boolean;\n isSignedIn: boolean;\n userId: string | null;\n sessionId: string | null;\n getToken: (options?: { skipCache?: boolean }) => Promise<string | null>;\n signOut: (options?: { redirectUrl?: string }) => Promise<void>;\n has: Has;\n}\n\nconst isLoadedStatus = (status: string): boolean => status === \"ready\" || status === \"degraded\";\n\nexport function useAuth(): UseAuthResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const getToken = useCallback(\n (options?: { skipCache?: boolean }) => zautha?.getToken(options) ?? Promise.resolve(null),\n [zautha],\n );\n const signOut = useCallback(\n (options?: { redirectUrl?: string }) => zautha?.signOut(options) ?? Promise.resolve(),\n [zautha],\n );\n const signedIn = state.session !== null;\n const has = useCallback<Has>(\n (params) => signedIn && params.role === undefined && params.permission === undefined,\n [signedIn],\n );\n return {\n isLoaded: isLoadedStatus(state.status),\n isSignedIn: signedIn,\n userId: state.session?.userId ?? null,\n sessionId: state.session?.id ?? null,\n getToken,\n signOut,\n has,\n };\n}\n\nexport function useUser(): { isLoaded: boolean; isSignedIn: boolean; user: User | null } {\n const state = useZauthaState();\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: state.session !== null, user: state.user };\n}\n\nexport function useSession(): { isLoaded: boolean; isSignedIn: boolean; session: Session | null } {\n const state = useZauthaState();\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: state.session !== null, session: state.session };\n}\n\nconst noopSubscribe = (): (() => void) => () => undefined;\n\nfunction useResource<T extends SignInResource | SignUpResource>(resource: T | null) {\n const snapshot = useSyncExternalStore(\n resource?.subscribe ?? noopSubscribe,\n () => resource?.snapshot ?? null,\n () => null,\n );\n return snapshot;\n}\n\nexport interface UseSignInResult {\n isLoaded: boolean;\n /** The sign-in resource; null until the provider has created the instance. */\n signIn: SignInResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nconst NO_ERRORS: AttemptErrors = { fields: {}, global: [] };\n\nexport function useSignIn(): UseSignInResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signIn ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signIn: zautha?.signIn ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n\nexport interface UseSignUpResult {\n isLoaded: boolean;\n signUp: SignUpResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nexport function useSignUp(): UseSignUpResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signUp ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signUp: zautha?.signUp ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n","import { useEffect, type ReactNode } from \"react\";\nimport { useAuth, type Has, type HasParams } from \"./hooks\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\nexport type ShowWhen = \"signed-in\" | \"signed-out\" | HasParams | ((has: Has) => boolean);\n\n/**\n * Renders `children` when the condition holds, else `fallback`. Renders nothing until Zautha has\n * loaded, so a signed-in user never sees a signed-out flash.\n */\nexport function Show(props: { when: ShowWhen; fallback?: ReactNode; children?: ReactNode }): ReactNode {\n const { isLoaded, isSignedIn, has } = useAuth();\n if (!isLoaded) return null;\n const { when } = props;\n const pass =\n when === \"signed-in\"\n ? isSignedIn\n : when === \"signed-out\"\n ? !isSignedIn\n : typeof when === \"function\"\n ? when(has)\n : has(when);\n return pass ? props.children : (props.fallback ?? null);\n}\n\nexport function ZauthaLoading(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"loading\" ? props.children : null;\n}\n\n/** Loaded, including degraded (network trouble after load: last known state is shown). */\nexport function ZauthaLoaded(props: { children?: ReactNode }): ReactNode {\n const { status } = useZauthaState();\n return status === \"ready\" || status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaDegraded(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaFailed(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"failed\" ? props.children : null;\n}\n\n/** Sends a signed-out visitor to sign-in once loaded; renders nothing. */\nexport function RedirectToSignIn(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignIn(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n\nexport function RedirectToSignUp(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignUp(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n","import { Children, cloneElement, isValidElement, type MouseEvent, type ReactElement, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\ninterface ButtonProps {\n /** `redirect` (default) goes to the sign-in page; `modal` opens the prebuilt component (needs `ui`). */\n mode?: \"redirect\" | \"modal\";\n redirectUrl?: string;\n children?: ReactNode;\n}\n\n/** Wraps its single child (or renders a plain button) and wires the click. Unstyled by design. */\nfunction Trigger(props: { children: ReactNode; label: string; onClick: () => void }): ReactNode {\n const child = Children.count(props.children) === 1 ? Children.only(props.children) : null;\n if (isValidElement<{ onClick?: (event: MouseEvent) => void }>(child)) {\n const original = child.props.onClick;\n return cloneElement(child as ReactElement<{ onClick?: (event: MouseEvent) => void }>, {\n onClick: (event: MouseEvent) => {\n original?.(event);\n if (!event.defaultPrevented) props.onClick();\n },\n });\n }\n return (\n <button type=\"button\" onClick={props.onClick}>\n {props.children ?? props.label}\n </button>\n );\n}\n\nexport function SignInButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign in\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignIn(options) : zautha?.redirectToSignIn(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignUpButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign up\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignUp(options) : zautha?.redirectToSignUp(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignOutButton(props: { redirectUrl?: string; children?: ReactNode }): ReactNode {\n const zautha = useZautha();\n return (\n <Trigger\n label=\"Sign out\"\n onClick={() => void zautha?.signOut(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl })}\n >\n {props.children}\n </Trigger>\n );\n}\n","import type { UiComponentName } from \"@zautha/js\";\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\n/**\n * Mounts a @zautha/ui component into a div once the instance exists; later prop changes update it in\n * place. SSR renders only the empty div.\n */\nfunction Mounted(props: { name: UiComponentName; componentProps: object }): ReactNode {\n const zautha = useZautha();\n const ref = useRef<HTMLDivElement>(null);\n const mountedWith = useRef<object | null>(null);\n const { name, componentProps } = props;\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null) return;\n zautha.mount(name, element, componentProps);\n mountedWith.current = componentProps;\n return () => {\n mountedWith.current = null;\n zautha.unmount(element);\n };\n // componentProps changes are applied by the effect below without remounting.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [zautha, name]);\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null || mountedWith.current === null || mountedWith.current === componentProps)\n return;\n mountedWith.current = componentProps;\n zautha.updateMounted(element, componentProps);\n }, [zautha, componentProps]);\n\n return <div ref={ref} />;\n}\n\n// Prop types live in @zautha/ui; they are structural here so @zautha/react has no runtime dependency on it.\nexport function SignIn(props: import(\"@zautha/ui\").SignInProps): ReactNode {\n return <Mounted name=\"SignIn\" componentProps={props} />;\n}\n\nexport function SignUp(props: import(\"@zautha/ui\").SignUpProps): ReactNode {\n return <Mounted name=\"SignUp\" componentProps={props} />;\n}\n\nexport function UserButton(props: import(\"@zautha/ui\").UserButtonProps): ReactNode {\n return <Mounted name=\"UserButton\" componentProps={props} />;\n}\n\nexport function OAuthConsent(props: import(\"@zautha/ui\").OAuthConsentProps): ReactNode {\n return <Mounted name=\"OAuthConsent\" componentProps={props} />;\n}\n"],"mappings":";;;;;;AAGA,MAAM,iBAAA,GAAgBA,MAAAA,cAAAA,CAAyC,KAAA,CAAS;;;;;;AAYxE,SAAgB,eAAe,EAAE,gBAAgB,UAAU,GAAG,WAA2C;CACvG,MAAM,CAAC,QAAQ,cAAA,GAAaC,MAAAA,SAAAA,CAAwB,IAAI;CACxD,MAAM,EAAE,IAAI,YAAY,cAAc,WAAW,WAAW,aAAa;CAEzE,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,MAAM,WAAW,IAAIC,WAAAA,OAAO,gBAAgB;GAC1C,GAAI,OAAO,KAAA,IAAY,CAAC,IAAI,EAAE,GAAG;GACjC,GAAI,eAAe,KAAA,IAAY,CAAC,IAAI,EAAE,WAAW;GACjD,GAAI,iBAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,aAAa;GACrD,GAAI,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU;GAC/C,GAAI,cAAc,KAAA,IAAY,CAAC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AAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;EAAS,MAAK;EAAe,gBAAgB;CAAQ,CAAA;AAC9D"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["createContext","useState","Zautha","useMemo","useContext","useSyncExternalStore","useCallback","useRef","withReverification","useSyncExternalStore","Children","isValidElement","cloneElement","useRef"],"sources":["../src/provider.tsx","../src/hooks.ts","../src/control.tsx","../src/buttons.tsx","../src/prebuilt.tsx"],"sourcesContent":["import { Zautha, type ZauthaOptions, type ZauthaState } from \"@zautha/js\";\nimport { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore, type ReactNode } from \"react\";\n\ninterface ZauthaContextValue {\n readonly zautha: Zautha | null;\n /** The snapshot before the instance exists and during server rendering (carries `initialState`). */\n readonly pending: ZauthaState;\n}\n\nconst ZauthaContext = createContext<ZauthaContextValue | undefined>(undefined);\n\nexport interface ZauthaProviderProps extends Omit<ZauthaOptions, \"fetch\"> {\n publishableKey: string;\n children?: ReactNode;\n}\n\n/**\n * Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR\n * create no timers or channels), loads it, and disposes it on unmount. Until then hooks report\n * `isLoaded: false`, unless `initialState` (the server's view, e.g. from @zautha/nextjs) says who is signed in.\n */\nexport function ZauthaProvider({ publishableKey, children, ...options }: ZauthaProviderProps): ReactNode {\n const [zautha, setZautha] = useState<Zautha | null>(null);\n const { ui, appearance, localization, signInUrl, signUpUrl, navigate, initialState } = options;\n const [pending] = useState<ZauthaState>(() => ({ ...NO_STATE, initialState: initialState ?? null }));\n\n useEffect(() => {\n const instance = new Zautha(publishableKey, {\n ...(ui === undefined ? {} : { ui }),\n ...(appearance === undefined ? {} : { appearance }),\n ...(localization === undefined ? {} : { localization }),\n ...(signInUrl === undefined ? {} : { signInUrl }),\n ...(signUpUrl === undefined ? {} : { signUpUrl }),\n ...(navigate === undefined ? {} : { navigate }),\n ...(initialState === undefined ? {} : { initialState }),\n });\n // The instance is an external system: it is created here, never during render, and published through state.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setZautha(instance);\n void instance.load();\n return () => {\n instance.dispose();\n setZautha(null);\n };\n // Appearance/localization objects are read at mount; changing the key re-creates the instance.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [publishableKey]);\n\n const value = useMemo(() => ({ zautha, pending }), [zautha, pending]);\n return <ZauthaContext.Provider value={value}>{children}</ZauthaContext.Provider>;\n}\n\n/** The Zautha instance, or null before the provider has created it. */\nexport function useZautha(): Zautha | null {\n return useZauthaContext().zautha;\n}\n\nfunction useZauthaContext(): ZauthaContextValue {\n const value = useContext(ZauthaContext);\n if (value === undefined) throw new Error(\"Zautha hooks and components must be used inside <ZauthaProvider>.\");\n return value;\n}\n\nconst NO_STATE: ZauthaState = {\n status: \"loading\",\n environment: null,\n client: null,\n session: null,\n user: null,\n initialState: null,\n};\nconst noop = (): (() => void) => () => undefined;\n\n/** Reactive snapshot of the instance state (the loading state, with any initial state, before the instance exists). */\nexport function useZauthaState(): ZauthaState {\n const { zautha, pending } = useZauthaContext();\n return useSyncExternalStore(\n zautha?.subscribe ?? noop,\n () => zautha?.getSnapshot() ?? pending,\n () => pending,\n );\n}\n","import {\n withReverification,\n type AttemptErrors,\n type FetchStatus,\n type Session,\n type SignInResource,\n type SignUpResource,\n type UserResource,\n} from \"@zautha/js\";\nimport { useCallback, useLayoutEffect, useRef, useSyncExternalStore } from \"react\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\n/** Authorization check. In 3a there are no organization claims yet, so role/permission checks are false. */\nexport type HasParams = { role?: string; permission?: string };\nexport type Has = (params: HasParams) => boolean;\n\nexport interface UseAuthResult {\n isLoaded: boolean;\n isSignedIn: boolean;\n userId: string | null;\n sessionId: string | null;\n getToken: (options?: { skipCache?: boolean }) => Promise<string | null>;\n signOut: (options?: { redirectUrl?: string }) => Promise<void>;\n has: Has;\n}\n\nconst isLoadedStatus = (status: string): boolean => status === \"ready\" || status === \"degraded\";\n\nexport function useAuth(): UseAuthResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const getToken = useCallback(\n (options?: { skipCache?: boolean }) => zautha?.getToken(options) ?? Promise.resolve(null),\n [zautha],\n );\n const signOut = useCallback(\n (options?: { redirectUrl?: string }) => zautha?.signOut(options) ?? Promise.resolve(),\n [zautha],\n );\n // Until the first load settles, the server's initial state (if any) answers, so nothing flickers.\n const initial = state.status === \"loading\" ? state.initialState : null;\n const userId = initial === null ? (state.session?.userId ?? null) : initial.userId;\n const sessionId = initial === null ? (state.session?.id ?? null) : initial.sessionId;\n const signedIn = userId !== null;\n const has = useCallback<Has>(\n (params) => signedIn && params.role === undefined && params.permission === undefined,\n [signedIn],\n );\n return {\n isLoaded: isLoadedStatus(state.status) || initial !== null,\n isSignedIn: signedIn,\n userId,\n sessionId,\n getToken,\n signOut,\n has,\n };\n}\n\n/** The signed-in user with its self-service actions (`user.update`, `user.createEmailAddress`, …). */\nexport function useUser(): { isLoaded: boolean; isSignedIn: boolean; user: UserResource | null } {\n const zautha = useZautha();\n const state = useZauthaState();\n // zautha.user is rebuilt only when state.user changes, so the resource is stable between renders.\n const user = state.user === null ? null : (zautha?.user ?? null);\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: state.session !== null, user };\n}\n\n/**\n * Wraps a sensitive action so that it completes after an identity check when it needs one: when `fetcher` throws\n * `ReverificationRequiredError` (e.g. `user.updatePassword`) or resolves to a `Response` with the `403\n * reverification_required` body (your backend with @zautha/backend, @zautha/nextjs or Zautha.AspNetCore), the\n * reverification modal opens and, once the user has verified, `fetcher` runs once more with the same arguments (its\n * token is fresh by then). Closing the modal rejects with `ReverificationCancelledError`. Needs `ui` from @zautha/ui on\n * the provider. The returned function is stable; it always calls the latest `fetcher`.\n */\nexport function useReverification<Args extends unknown[], Result>(\n fetcher: (...args: Args) => Promise<Result>,\n): (...args: Args) => Promise<Result> {\n const zautha = useZautha();\n const latest = useRef(fetcher);\n useLayoutEffect(() => {\n latest.current = fetcher;\n });\n return useCallback(\n (...args: Args) => {\n const call = (...callArgs: Args): Promise<Result> => latest.current(...callArgs);\n // Before the provider has created the instance no modal can open: the action runs as it is.\n return zautha === null ? call(...args) : withReverification(zautha, call)(...args);\n },\n [zautha],\n );\n}\n\nexport function useSession(): { isLoaded: boolean; isSignedIn: boolean; session: Session | null } {\n const state = useZauthaState();\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: state.session !== null, session: state.session };\n}\n\nconst noopSubscribe = (): (() => void) => () => undefined;\n\nfunction useResource<T extends SignInResource | SignUpResource>(resource: T | null) {\n const snapshot = useSyncExternalStore(\n resource?.subscribe ?? noopSubscribe,\n () => resource?.snapshot ?? null,\n () => null,\n );\n return snapshot;\n}\n\nexport interface UseSignInResult {\n isLoaded: boolean;\n /** The sign-in resource; null until the provider has created the instance. */\n signIn: SignInResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nconst NO_ERRORS: AttemptErrors = { fields: {}, global: [] };\n\nexport function useSignIn(): UseSignInResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signIn ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signIn: zautha?.signIn ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n\nexport interface UseSignUpResult {\n isLoaded: boolean;\n signUp: SignUpResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nexport function useSignUp(): UseSignUpResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signUp ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signUp: zautha?.signUp ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n","import { useEffect, type ReactNode } from \"react\";\nimport { useAuth, type Has, type HasParams } from \"./hooks\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\nexport type ShowWhen = \"signed-in\" | \"signed-out\" | HasParams | ((has: Has) => boolean);\n\n/**\n * Renders `children` when the condition holds, else `fallback`. Renders nothing until Zautha has\n * loaded, so a signed-in user never sees a signed-out flash.\n */\nexport function Show(props: { when: ShowWhen; fallback?: ReactNode; children?: ReactNode }): ReactNode {\n const { isLoaded, isSignedIn, has } = useAuth();\n if (!isLoaded) return null;\n const { when } = props;\n const pass =\n when === \"signed-in\"\n ? isSignedIn\n : when === \"signed-out\"\n ? !isSignedIn\n : typeof when === \"function\"\n ? when(has)\n : has(when);\n return pass ? props.children : (props.fallback ?? null);\n}\n\nexport function ZauthaLoading(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"loading\" ? props.children : null;\n}\n\n/** Loaded, including degraded (network trouble after load: last known state is shown). */\nexport function ZauthaLoaded(props: { children?: ReactNode }): ReactNode {\n const { status } = useZauthaState();\n return status === \"ready\" || status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaDegraded(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaFailed(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"failed\" ? props.children : null;\n}\n\n/** Sends a signed-out visitor to sign-in once loaded; renders nothing. */\nexport function RedirectToSignIn(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignIn(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n\nexport function RedirectToSignUp(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignUp(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n","import { Children, cloneElement, isValidElement, type MouseEvent, type ReactElement, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\ninterface ButtonProps {\n /** `redirect` (default) goes to the sign-in page; `modal` opens the prebuilt component (needs `ui`). */\n mode?: \"redirect\" | \"modal\";\n redirectUrl?: string;\n children?: ReactNode;\n}\n\n/** Wraps its single child (or renders a plain button) and wires the click. Unstyled by design. */\nfunction Trigger(props: { children: ReactNode; label: string; onClick: () => void }): ReactNode {\n const child = Children.count(props.children) === 1 ? Children.only(props.children) : null;\n if (isValidElement<{ onClick?: (event: MouseEvent) => void }>(child)) {\n const original = child.props.onClick;\n return cloneElement(child as ReactElement<{ onClick?: (event: MouseEvent) => void }>, {\n onClick: (event: MouseEvent) => {\n original?.(event);\n if (!event.defaultPrevented) props.onClick();\n },\n });\n }\n return (\n <button type=\"button\" onClick={props.onClick}>\n {props.children ?? props.label}\n </button>\n );\n}\n\nexport function SignInButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign in\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignIn(options) : zautha?.redirectToSignIn(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignUpButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign up\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignUp(options) : zautha?.redirectToSignUp(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignOutButton(props: { redirectUrl?: string; children?: ReactNode }): ReactNode {\n const zautha = useZautha();\n return (\n <Trigger\n label=\"Sign out\"\n onClick={() => void zautha?.signOut(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl })}\n >\n {props.children}\n </Trigger>\n );\n}\n","import type { UiComponentName } from \"@zautha/js\";\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\n/**\n * Mounts a @zautha/ui component into a div once the instance exists; later prop changes update it in\n * place. SSR renders only the empty div.\n */\nfunction Mounted(props: { name: UiComponentName; componentProps: object }): ReactNode {\n const zautha = useZautha();\n const ref = useRef<HTMLDivElement>(null);\n const mountedWith = useRef<object | null>(null);\n const { name, componentProps } = props;\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null) return;\n zautha.mount(name, element, componentProps);\n mountedWith.current = componentProps;\n return () => {\n mountedWith.current = null;\n zautha.unmount(element);\n };\n // componentProps changes are applied by the effect below without remounting.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [zautha, name]);\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null || mountedWith.current === null || mountedWith.current === componentProps)\n return;\n mountedWith.current = componentProps;\n zautha.updateMounted(element, componentProps);\n }, [zautha, componentProps]);\n\n return <div ref={ref} />;\n}\n\n// Prop types live in @zautha/ui; they are structural here so @zautha/react has no runtime dependency on it.\nexport function SignIn(props: import(\"@zautha/ui\").SignInProps): ReactNode {\n return <Mounted name=\"SignIn\" componentProps={props} />;\n}\n\nexport function SignUp(props: import(\"@zautha/ui\").SignUpProps): ReactNode {\n return <Mounted name=\"SignUp\" componentProps={props} />;\n}\n\nexport function UserButton(props: import(\"@zautha/ui\").UserButtonProps): ReactNode {\n return <Mounted name=\"UserButton\" componentProps={props} />;\n}\n\nexport function UserProfile(props: import(\"@zautha/ui\").UserProfileProps): ReactNode {\n return <Mounted name=\"UserProfile\" componentProps={props} />;\n}\n\nexport function OAuthConsent(props: import(\"@zautha/ui\").OAuthConsentProps): ReactNode {\n return <Mounted name=\"OAuthConsent\" componentProps={props} />;\n}\n"],"mappings":";;;;;;AASA,MAAM,iBAAA,GAAgBA,MAAAA,cAAAA,CAA8C,KAAA,CAAS;;;;;;AAY7E,SAAgB,eAAe,EAAE,gBAAgB,UAAU,GAAG,WAA2C;CACvG,MAAM,CAAC,QAAQ,cAAA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BAAgB;CAAQ,CAAA;AACxD;AAEA,SAAgB,WAAW,OAAwD;CACjF,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;EAAS,MAAK;EAAa,gBAAgB;CAAQ,CAAA;AAC5D;AAEA,SAAgB,YAAY,OAAyD;CACnF,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;EAAS,MAAK;EAAc,gBAAgB;CAAQ,CAAA;AAC7D;AAEA,SAAgB,aAAa,OAA0D;CACrF,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;EAAS,MAAK;EAAe,gBAAgB;CAAQ,CAAA;AAC9D"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { AttemptErrors, Environment, FetchStatus, Session, Session as Session$1, SignInResource, SignInResource as SignInResource$1, SignUpResource, SignUpResource as SignUpResource$1, User,
|
|
2
|
+
import { AttemptErrors, EmailAddress, Environment, FetchStatus, ReverificationCancelledError, ReverificationRequiredError, ReverificationRequirement, Session, Session as Session$1, SessionWithActivity, SignInResource, SignInResource as SignInResource$1, SignUpResource, SignUpResource as SignUpResource$1, User, UserResource, UserResource as UserResource$1, Zautha, ZauthaApiError, ZauthaError, ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, ZauthaOptions, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError } from "@zautha/js";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
//#region src/provider.d.ts
|
|
5
5
|
interface ZauthaProviderProps extends Omit<ZauthaOptions, "fetch"> {
|
|
@@ -9,7 +9,7 @@ interface ZauthaProviderProps extends Omit<ZauthaOptions, "fetch"> {
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR
|
|
11
11
|
* create no timers or channels), loads it, and disposes it on unmount. Until then hooks report
|
|
12
|
-
* `isLoaded: false
|
|
12
|
+
* `isLoaded: false`, unless `initialState` (the server's view, e.g. from @zautha/nextjs) says who is signed in.
|
|
13
13
|
*/
|
|
14
14
|
export declare function ZauthaProvider({ publishableKey, children, ...options }: ZauthaProviderProps): ReactNode;
|
|
15
15
|
/** The Zautha instance, or null before the provider has created it. */
|
|
@@ -36,11 +36,21 @@ interface UseAuthResult {
|
|
|
36
36
|
has: Has;
|
|
37
37
|
}
|
|
38
38
|
export declare function useAuth(): UseAuthResult;
|
|
39
|
+
/** The signed-in user with its self-service actions (`user.update`, `user.createEmailAddress`, …). */
|
|
39
40
|
export declare function useUser(): {
|
|
40
41
|
isLoaded: boolean;
|
|
41
42
|
isSignedIn: boolean;
|
|
42
|
-
user:
|
|
43
|
+
user: UserResource$1 | null;
|
|
43
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Wraps a sensitive action so that it completes after an identity check when it needs one: when `fetcher` throws
|
|
47
|
+
* `ReverificationRequiredError` (e.g. `user.updatePassword`) or resolves to a `Response` with the `403
|
|
48
|
+
* reverification_required` body (your backend with @zautha/backend, @zautha/nextjs or Zautha.AspNetCore), the
|
|
49
|
+
* reverification modal opens and, once the user has verified, `fetcher` runs once more with the same arguments (its
|
|
50
|
+
* token is fresh by then). Closing the modal rejects with `ReverificationCancelledError`. Needs `ui` from @zautha/ui on
|
|
51
|
+
* the provider. The returned function is stable; it always calls the latest `fetcher`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function useReverification<Args extends unknown[], Result>(fetcher: (...args: Args) => Promise<Result>): (...args: Args) => Promise<Result>;
|
|
44
54
|
export declare function useSession(): {
|
|
45
55
|
isLoaded: boolean;
|
|
46
56
|
isSignedIn: boolean;
|
|
@@ -112,7 +122,8 @@ export declare function SignOutButton(props: {
|
|
|
112
122
|
export declare function SignIn(props: import("@zautha/ui").SignInProps): ReactNode;
|
|
113
123
|
export declare function SignUp(props: import("@zautha/ui").SignUpProps): ReactNode;
|
|
114
124
|
export declare function UserButton(props: import("@zautha/ui").UserButtonProps): ReactNode;
|
|
125
|
+
export declare function UserProfile(props: import("@zautha/ui").UserProfileProps): ReactNode;
|
|
115
126
|
export declare function OAuthConsent(props: import("@zautha/ui").OAuthConsentProps): ReactNode;
|
|
116
127
|
//#endregion
|
|
117
|
-
export { type Environment, type Has, type HasParams, type Session, type ShowWhen, type SignInResource, type SignUpResource, type UseAuthResult, type UseSignInResult, type UseSignUpResult, type User, ZauthaApiError, ZauthaError, type ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, type ZauthaProviderProps, isZauthaApiError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError };
|
|
128
|
+
export { type EmailAddress, type Environment, type Has, type HasParams, ReverificationCancelledError, ReverificationRequiredError, type ReverificationRequirement, type Session, type SessionWithActivity, type ShowWhen, type SignInResource, type SignUpResource, type UseAuthResult, type UseSignInResult, type UseSignUpResult, type User, type UserResource, ZauthaApiError, ZauthaError, type ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, type ZauthaProviderProps, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError };
|
|
118
129
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { AttemptErrors, Environment, FetchStatus, Session, Session as Session$1, SignInResource, SignInResource as SignInResource$1, SignUpResource, SignUpResource as SignUpResource$1, User,
|
|
2
|
+
import { AttemptErrors, EmailAddress, Environment, FetchStatus, ReverificationCancelledError, ReverificationRequiredError, ReverificationRequirement, Session, Session as Session$1, SessionWithActivity, SignInResource, SignInResource as SignInResource$1, SignUpResource, SignUpResource as SignUpResource$1, User, UserResource, UserResource as UserResource$1, Zautha, ZauthaApiError, ZauthaError, ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, ZauthaOptions, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError } from "@zautha/js";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
//#region src/provider.d.ts
|
|
5
5
|
interface ZauthaProviderProps extends Omit<ZauthaOptions, "fetch"> {
|
|
@@ -9,7 +9,7 @@ interface ZauthaProviderProps extends Omit<ZauthaOptions, "fetch"> {
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR
|
|
11
11
|
* create no timers or channels), loads it, and disposes it on unmount. Until then hooks report
|
|
12
|
-
* `isLoaded: false
|
|
12
|
+
* `isLoaded: false`, unless `initialState` (the server's view, e.g. from @zautha/nextjs) says who is signed in.
|
|
13
13
|
*/
|
|
14
14
|
export declare function ZauthaProvider({ publishableKey, children, ...options }: ZauthaProviderProps): ReactNode;
|
|
15
15
|
/** The Zautha instance, or null before the provider has created it. */
|
|
@@ -36,11 +36,21 @@ interface UseAuthResult {
|
|
|
36
36
|
has: Has;
|
|
37
37
|
}
|
|
38
38
|
export declare function useAuth(): UseAuthResult;
|
|
39
|
+
/** The signed-in user with its self-service actions (`user.update`, `user.createEmailAddress`, …). */
|
|
39
40
|
export declare function useUser(): {
|
|
40
41
|
isLoaded: boolean;
|
|
41
42
|
isSignedIn: boolean;
|
|
42
|
-
user:
|
|
43
|
+
user: UserResource$1 | null;
|
|
43
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Wraps a sensitive action so that it completes after an identity check when it needs one: when `fetcher` throws
|
|
47
|
+
* `ReverificationRequiredError` (e.g. `user.updatePassword`) or resolves to a `Response` with the `403
|
|
48
|
+
* reverification_required` body (your backend with @zautha/backend, @zautha/nextjs or Zautha.AspNetCore), the
|
|
49
|
+
* reverification modal opens and, once the user has verified, `fetcher` runs once more with the same arguments (its
|
|
50
|
+
* token is fresh by then). Closing the modal rejects with `ReverificationCancelledError`. Needs `ui` from @zautha/ui on
|
|
51
|
+
* the provider. The returned function is stable; it always calls the latest `fetcher`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function useReverification<Args extends unknown[], Result>(fetcher: (...args: Args) => Promise<Result>): (...args: Args) => Promise<Result>;
|
|
44
54
|
export declare function useSession(): {
|
|
45
55
|
isLoaded: boolean;
|
|
46
56
|
isSignedIn: boolean;
|
|
@@ -112,7 +122,8 @@ export declare function SignOutButton(props: {
|
|
|
112
122
|
export declare function SignIn(props: import("@zautha/ui").SignInProps): ReactNode;
|
|
113
123
|
export declare function SignUp(props: import("@zautha/ui").SignUpProps): ReactNode;
|
|
114
124
|
export declare function UserButton(props: import("@zautha/ui").UserButtonProps): ReactNode;
|
|
125
|
+
export declare function UserProfile(props: import("@zautha/ui").UserProfileProps): ReactNode;
|
|
115
126
|
export declare function OAuthConsent(props: import("@zautha/ui").OAuthConsentProps): ReactNode;
|
|
116
127
|
//#endregion
|
|
117
|
-
export { type Environment, type Has, type HasParams, type Session, type ShowWhen, type SignInResource, type SignUpResource, type UseAuthResult, type UseSignInResult, type UseSignUpResult, type User, ZauthaApiError, ZauthaError, type ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, type ZauthaProviderProps, isZauthaApiError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError };
|
|
128
|
+
export { type EmailAddress, type Environment, type Has, type HasParams, ReverificationCancelledError, ReverificationRequiredError, type ReverificationRequirement, type Session, type SessionWithActivity, type ShowWhen, type SignInResource, type SignUpResource, type UseAuthResult, type UseSignInResult, type UseSignUpResult, type User, type UserResource, ZauthaApiError, ZauthaError, type ZauthaErrorCode, ZauthaNetworkError, ZauthaOfflineError, type ZauthaProviderProps, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError };
|
|
118
129
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { Zautha, ZauthaApiError, ZauthaError, ZauthaNetworkError, ZauthaOfflineError, isZauthaApiError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError } from "@zautha/js";
|
|
3
|
-
import { Children, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { ReverificationCancelledError, ReverificationRequiredError, Zautha, ZauthaApiError, ZauthaError, ZauthaNetworkError, ZauthaOfflineError, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, withReverification } from "@zautha/js";
|
|
3
|
+
import { Children, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/provider.tsx
|
|
6
6
|
const ZauthaContext = createContext(void 0);
|
|
7
7
|
/**
|
|
8
8
|
* Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR
|
|
9
9
|
* create no timers or channels), loads it, and disposes it on unmount. Until then hooks report
|
|
10
|
-
* `isLoaded: false
|
|
10
|
+
* `isLoaded: false`, unless `initialState` (the server's view, e.g. from @zautha/nextjs) says who is signed in.
|
|
11
11
|
*/
|
|
12
12
|
function ZauthaProvider({ publishableKey, children, ...options }) {
|
|
13
13
|
const [zautha, setZautha] = useState(null);
|
|
14
|
-
const { ui, appearance, localization, signInUrl, signUpUrl, navigate } = options;
|
|
14
|
+
const { ui, appearance, localization, signInUrl, signUpUrl, navigate, initialState } = options;
|
|
15
|
+
const [pending] = useState(() => ({
|
|
16
|
+
...NO_STATE,
|
|
17
|
+
initialState: initialState ?? null
|
|
18
|
+
}));
|
|
15
19
|
useEffect(() => {
|
|
16
20
|
const instance = new Zautha(publishableKey, {
|
|
17
21
|
...ui === void 0 ? {} : { ui },
|
|
@@ -19,7 +23,8 @@ function ZauthaProvider({ publishableKey, children, ...options }) {
|
|
|
19
23
|
...localization === void 0 ? {} : { localization },
|
|
20
24
|
...signInUrl === void 0 ? {} : { signInUrl },
|
|
21
25
|
...signUpUrl === void 0 ? {} : { signUpUrl },
|
|
22
|
-
...navigate === void 0 ? {} : { navigate }
|
|
26
|
+
...navigate === void 0 ? {} : { navigate },
|
|
27
|
+
...initialState === void 0 ? {} : { initialState }
|
|
23
28
|
});
|
|
24
29
|
setZautha(instance);
|
|
25
30
|
instance.load();
|
|
@@ -28,29 +33,37 @@ function ZauthaProvider({ publishableKey, children, ...options }) {
|
|
|
28
33
|
setZautha(null);
|
|
29
34
|
};
|
|
30
35
|
}, [publishableKey]);
|
|
36
|
+
const value = useMemo(() => ({
|
|
37
|
+
zautha,
|
|
38
|
+
pending
|
|
39
|
+
}), [zautha, pending]);
|
|
31
40
|
return /* @__PURE__ */ jsx(ZauthaContext.Provider, {
|
|
32
|
-
value
|
|
41
|
+
value,
|
|
33
42
|
children
|
|
34
43
|
});
|
|
35
44
|
}
|
|
36
45
|
/** The Zautha instance, or null before the provider has created it. */
|
|
37
46
|
function useZautha() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
47
|
+
return useZauthaContext().zautha;
|
|
48
|
+
}
|
|
49
|
+
function useZauthaContext() {
|
|
50
|
+
const value = useContext(ZauthaContext);
|
|
51
|
+
if (value === void 0) throw new Error("Zautha hooks and components must be used inside <ZauthaProvider>.");
|
|
52
|
+
return value;
|
|
41
53
|
}
|
|
42
54
|
const NO_STATE = {
|
|
43
55
|
status: "loading",
|
|
44
56
|
environment: null,
|
|
45
57
|
client: null,
|
|
46
58
|
session: null,
|
|
47
|
-
user: null
|
|
59
|
+
user: null,
|
|
60
|
+
initialState: null
|
|
48
61
|
};
|
|
49
62
|
const noop = () => () => void 0;
|
|
50
|
-
/** Reactive snapshot of the instance state (the loading state before the instance exists). */
|
|
63
|
+
/** Reactive snapshot of the instance state (the loading state, with any initial state, before the instance exists). */
|
|
51
64
|
function useZauthaState() {
|
|
52
|
-
const zautha =
|
|
53
|
-
return useSyncExternalStore(zautha?.subscribe ?? noop, () => zautha?.getSnapshot() ??
|
|
65
|
+
const { zautha, pending } = useZauthaContext();
|
|
66
|
+
return useSyncExternalStore(zautha?.subscribe ?? noop, () => zautha?.getSnapshot() ?? pending, () => pending);
|
|
54
67
|
}
|
|
55
68
|
//#endregion
|
|
56
69
|
//#region src/hooks.ts
|
|
@@ -60,26 +73,51 @@ function useAuth() {
|
|
|
60
73
|
const state = useZauthaState();
|
|
61
74
|
const getToken = useCallback((options) => zautha?.getToken(options) ?? Promise.resolve(null), [zautha]);
|
|
62
75
|
const signOut = useCallback((options) => zautha?.signOut(options) ?? Promise.resolve(), [zautha]);
|
|
63
|
-
const
|
|
76
|
+
const initial = state.status === "loading" ? state.initialState : null;
|
|
77
|
+
const userId = initial === null ? state.session?.userId ?? null : initial.userId;
|
|
78
|
+
const sessionId = initial === null ? state.session?.id ?? null : initial.sessionId;
|
|
79
|
+
const signedIn = userId !== null;
|
|
64
80
|
const has = useCallback((params) => signedIn && params.role === void 0 && params.permission === void 0, [signedIn]);
|
|
65
81
|
return {
|
|
66
|
-
isLoaded: isLoadedStatus(state.status),
|
|
82
|
+
isLoaded: isLoadedStatus(state.status) || initial !== null,
|
|
67
83
|
isSignedIn: signedIn,
|
|
68
|
-
userId
|
|
69
|
-
sessionId
|
|
84
|
+
userId,
|
|
85
|
+
sessionId,
|
|
70
86
|
getToken,
|
|
71
87
|
signOut,
|
|
72
88
|
has
|
|
73
89
|
};
|
|
74
90
|
}
|
|
91
|
+
/** The signed-in user with its self-service actions (`user.update`, `user.createEmailAddress`, …). */
|
|
75
92
|
function useUser() {
|
|
93
|
+
const zautha = useZautha();
|
|
76
94
|
const state = useZauthaState();
|
|
95
|
+
const user = state.user === null ? null : zautha?.user ?? null;
|
|
77
96
|
return {
|
|
78
97
|
isLoaded: isLoadedStatus(state.status),
|
|
79
98
|
isSignedIn: state.session !== null,
|
|
80
|
-
user
|
|
99
|
+
user
|
|
81
100
|
};
|
|
82
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Wraps a sensitive action so that it completes after an identity check when it needs one: when `fetcher` throws
|
|
104
|
+
* `ReverificationRequiredError` (e.g. `user.updatePassword`) or resolves to a `Response` with the `403
|
|
105
|
+
* reverification_required` body (your backend with @zautha/backend, @zautha/nextjs or Zautha.AspNetCore), the
|
|
106
|
+
* reverification modal opens and, once the user has verified, `fetcher` runs once more with the same arguments (its
|
|
107
|
+
* token is fresh by then). Closing the modal rejects with `ReverificationCancelledError`. Needs `ui` from @zautha/ui on
|
|
108
|
+
* the provider. The returned function is stable; it always calls the latest `fetcher`.
|
|
109
|
+
*/
|
|
110
|
+
function useReverification(fetcher) {
|
|
111
|
+
const zautha = useZautha();
|
|
112
|
+
const latest = useRef(fetcher);
|
|
113
|
+
useLayoutEffect(() => {
|
|
114
|
+
latest.current = fetcher;
|
|
115
|
+
});
|
|
116
|
+
return useCallback((...args) => {
|
|
117
|
+
const call = (...callArgs) => latest.current(...callArgs);
|
|
118
|
+
return zautha === null ? call(...args) : withReverification(zautha, call)(...args);
|
|
119
|
+
}, [zautha]);
|
|
120
|
+
}
|
|
83
121
|
function useSession() {
|
|
84
122
|
const state = useZauthaState();
|
|
85
123
|
return {
|
|
@@ -264,6 +302,12 @@ function UserButton(props) {
|
|
|
264
302
|
componentProps: props
|
|
265
303
|
});
|
|
266
304
|
}
|
|
305
|
+
function UserProfile(props) {
|
|
306
|
+
return /* @__PURE__ */ jsx(Mounted, {
|
|
307
|
+
name: "UserProfile",
|
|
308
|
+
componentProps: props
|
|
309
|
+
});
|
|
310
|
+
}
|
|
267
311
|
function OAuthConsent(props) {
|
|
268
312
|
return /* @__PURE__ */ jsx(Mounted, {
|
|
269
313
|
name: "OAuthConsent",
|
|
@@ -271,6 +315,6 @@ function OAuthConsent(props) {
|
|
|
271
315
|
});
|
|
272
316
|
}
|
|
273
317
|
//#endregion
|
|
274
|
-
export { OAuthConsent, RedirectToSignIn, RedirectToSignUp, Show, SignIn, SignInButton, SignOutButton, SignUp, SignUpButton, UserButton, ZauthaApiError, ZauthaDegraded, ZauthaError, ZauthaFailed, ZauthaLoaded, ZauthaLoading, ZauthaNetworkError, ZauthaOfflineError, ZauthaProvider, isZauthaApiError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, useAuth, useSession, useSignIn, useSignUp, useUser, useZautha };
|
|
318
|
+
export { OAuthConsent, RedirectToSignIn, RedirectToSignUp, ReverificationCancelledError, ReverificationRequiredError, Show, SignIn, SignInButton, SignOutButton, SignUp, SignUpButton, UserButton, UserProfile, ZauthaApiError, ZauthaDegraded, ZauthaError, ZauthaFailed, ZauthaLoaded, ZauthaLoading, ZauthaNetworkError, ZauthaOfflineError, ZauthaProvider, isReverificationCancelledError, isReverificationRequiredError, isZauthaApiError, isZauthaError, isZauthaNetworkError, isZauthaOfflineError, useAuth, useReverification, useSession, useSignIn, useSignUp, useUser, useZautha };
|
|
275
319
|
|
|
276
320
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/provider.tsx","../src/hooks.ts","../src/control.tsx","../src/buttons.tsx","../src/prebuilt.tsx"],"sourcesContent":["import { Zautha, type ZauthaOptions, type ZauthaState } from \"@zautha/js\";\nimport { createContext, useContext, useEffect, useState, useSyncExternalStore, type ReactNode } from \"react\";\n\nconst ZauthaContext = createContext<Zautha | null | undefined>(undefined);\n\nexport interface ZauthaProviderProps extends Omit<ZauthaOptions, \"fetch\"> {\n publishableKey: string;\n children?: ReactNode;\n}\n\n/**\n * Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR\n * create no timers or channels), loads it, and disposes it on unmount. Until then hooks report\n * `isLoaded: false`.\n */\nexport function ZauthaProvider({ publishableKey, children, ...options }: ZauthaProviderProps): ReactNode {\n const [zautha, setZautha] = useState<Zautha | null>(null);\n const { ui, appearance, localization, signInUrl, signUpUrl, navigate } = options;\n\n useEffect(() => {\n const instance = new Zautha(publishableKey, {\n ...(ui === undefined ? {} : { ui }),\n ...(appearance === undefined ? {} : { appearance }),\n ...(localization === undefined ? {} : { localization }),\n ...(signInUrl === undefined ? {} : { signInUrl }),\n ...(signUpUrl === undefined ? {} : { signUpUrl }),\n ...(navigate === undefined ? {} : { navigate }),\n });\n // The instance is an external system: it is created here, never during render, and published through state.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setZautha(instance);\n void instance.load();\n return () => {\n instance.dispose();\n setZautha(null);\n };\n // Appearance/localization objects are read at mount; changing the key re-creates the instance.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [publishableKey]);\n\n return <ZauthaContext.Provider value={zautha}>{children}</ZauthaContext.Provider>;\n}\n\n/** The Zautha instance, or null before the provider has created it. */\nexport function useZautha(): Zautha | null {\n const zautha = useContext(ZauthaContext);\n if (zautha === undefined) throw new Error(\"Zautha hooks and components must be used inside <ZauthaProvider>.\");\n return zautha;\n}\n\nconst NO_STATE: ZauthaState = { status: \"loading\", environment: null, client: null, session: null, user: null };\nconst noop = (): (() => void) => () => undefined;\n\n/** Reactive snapshot of the instance state (the loading state before the instance exists). */\nexport function useZauthaState(): ZauthaState {\n const zautha = useZautha();\n return useSyncExternalStore(\n zautha?.subscribe ?? noop,\n () => zautha?.getSnapshot() ?? NO_STATE,\n () => NO_STATE,\n );\n}\n","import type { AttemptErrors, FetchStatus, Session, SignInResource, SignUpResource, User } from \"@zautha/js\";\nimport { useCallback, useSyncExternalStore } from \"react\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\n/** Authorization check. In 3a there are no organization claims yet, so role/permission checks are false. */\nexport type HasParams = { role?: string; permission?: string };\nexport type Has = (params: HasParams) => boolean;\n\nexport interface UseAuthResult {\n isLoaded: boolean;\n isSignedIn: boolean;\n userId: string | null;\n sessionId: string | null;\n getToken: (options?: { skipCache?: boolean }) => Promise<string | null>;\n signOut: (options?: { redirectUrl?: string }) => Promise<void>;\n has: Has;\n}\n\nconst isLoadedStatus = (status: string): boolean => status === \"ready\" || status === \"degraded\";\n\nexport function useAuth(): UseAuthResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const getToken = useCallback(\n (options?: { skipCache?: boolean }) => zautha?.getToken(options) ?? Promise.resolve(null),\n [zautha],\n );\n const signOut = useCallback(\n (options?: { redirectUrl?: string }) => zautha?.signOut(options) ?? Promise.resolve(),\n [zautha],\n );\n const signedIn = state.session !== null;\n const has = useCallback<Has>(\n (params) => signedIn && params.role === undefined && params.permission === undefined,\n [signedIn],\n );\n return {\n isLoaded: isLoadedStatus(state.status),\n isSignedIn: signedIn,\n userId: state.session?.userId ?? null,\n sessionId: state.session?.id ?? null,\n getToken,\n signOut,\n has,\n };\n}\n\nexport function useUser(): { isLoaded: boolean; isSignedIn: boolean; user: User | null } {\n const state = useZauthaState();\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: state.session !== null, user: state.user };\n}\n\nexport function useSession(): { isLoaded: boolean; isSignedIn: boolean; session: Session | null } {\n const state = useZauthaState();\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: state.session !== null, session: state.session };\n}\n\nconst noopSubscribe = (): (() => void) => () => undefined;\n\nfunction useResource<T extends SignInResource | SignUpResource>(resource: T | null) {\n const snapshot = useSyncExternalStore(\n resource?.subscribe ?? noopSubscribe,\n () => resource?.snapshot ?? null,\n () => null,\n );\n return snapshot;\n}\n\nexport interface UseSignInResult {\n isLoaded: boolean;\n /** The sign-in resource; null until the provider has created the instance. */\n signIn: SignInResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nconst NO_ERRORS: AttemptErrors = { fields: {}, global: [] };\n\nexport function useSignIn(): UseSignInResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signIn ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signIn: zautha?.signIn ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n\nexport interface UseSignUpResult {\n isLoaded: boolean;\n signUp: SignUpResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nexport function useSignUp(): UseSignUpResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signUp ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signUp: zautha?.signUp ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n","import { useEffect, type ReactNode } from \"react\";\nimport { useAuth, type Has, type HasParams } from \"./hooks\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\nexport type ShowWhen = \"signed-in\" | \"signed-out\" | HasParams | ((has: Has) => boolean);\n\n/**\n * Renders `children` when the condition holds, else `fallback`. Renders nothing until Zautha has\n * loaded, so a signed-in user never sees a signed-out flash.\n */\nexport function Show(props: { when: ShowWhen; fallback?: ReactNode; children?: ReactNode }): ReactNode {\n const { isLoaded, isSignedIn, has } = useAuth();\n if (!isLoaded) return null;\n const { when } = props;\n const pass =\n when === \"signed-in\"\n ? isSignedIn\n : when === \"signed-out\"\n ? !isSignedIn\n : typeof when === \"function\"\n ? when(has)\n : has(when);\n return pass ? props.children : (props.fallback ?? null);\n}\n\nexport function ZauthaLoading(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"loading\" ? props.children : null;\n}\n\n/** Loaded, including degraded (network trouble after load: last known state is shown). */\nexport function ZauthaLoaded(props: { children?: ReactNode }): ReactNode {\n const { status } = useZauthaState();\n return status === \"ready\" || status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaDegraded(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaFailed(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"failed\" ? props.children : null;\n}\n\n/** Sends a signed-out visitor to sign-in once loaded; renders nothing. */\nexport function RedirectToSignIn(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignIn(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n\nexport function RedirectToSignUp(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignUp(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n","import { Children, cloneElement, isValidElement, type MouseEvent, type ReactElement, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\ninterface ButtonProps {\n /** `redirect` (default) goes to the sign-in page; `modal` opens the prebuilt component (needs `ui`). */\n mode?: \"redirect\" | \"modal\";\n redirectUrl?: string;\n children?: ReactNode;\n}\n\n/** Wraps its single child (or renders a plain button) and wires the click. Unstyled by design. */\nfunction Trigger(props: { children: ReactNode; label: string; onClick: () => void }): ReactNode {\n const child = Children.count(props.children) === 1 ? Children.only(props.children) : null;\n if (isValidElement<{ onClick?: (event: MouseEvent) => void }>(child)) {\n const original = child.props.onClick;\n return cloneElement(child as ReactElement<{ onClick?: (event: MouseEvent) => void }>, {\n onClick: (event: MouseEvent) => {\n original?.(event);\n if (!event.defaultPrevented) props.onClick();\n },\n });\n }\n return (\n <button type=\"button\" onClick={props.onClick}>\n {props.children ?? props.label}\n </button>\n );\n}\n\nexport function SignInButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign in\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignIn(options) : zautha?.redirectToSignIn(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignUpButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign up\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignUp(options) : zautha?.redirectToSignUp(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignOutButton(props: { redirectUrl?: string; children?: ReactNode }): ReactNode {\n const zautha = useZautha();\n return (\n <Trigger\n label=\"Sign out\"\n onClick={() => void zautha?.signOut(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl })}\n >\n {props.children}\n </Trigger>\n );\n}\n","import type { UiComponentName } from \"@zautha/js\";\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\n/**\n * Mounts a @zautha/ui component into a div once the instance exists; later prop changes update it in\n * place. SSR renders only the empty div.\n */\nfunction Mounted(props: { name: UiComponentName; componentProps: object }): ReactNode {\n const zautha = useZautha();\n const ref = useRef<HTMLDivElement>(null);\n const mountedWith = useRef<object | null>(null);\n const { name, componentProps } = props;\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null) return;\n zautha.mount(name, element, componentProps);\n mountedWith.current = componentProps;\n return () => {\n mountedWith.current = null;\n zautha.unmount(element);\n };\n // componentProps changes are applied by the effect below without remounting.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [zautha, name]);\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null || mountedWith.current === null || mountedWith.current === componentProps)\n return;\n mountedWith.current = componentProps;\n zautha.updateMounted(element, componentProps);\n }, [zautha, componentProps]);\n\n return <div ref={ref} />;\n}\n\n// Prop types live in @zautha/ui; they are structural here so @zautha/react has no runtime dependency on it.\nexport function SignIn(props: import(\"@zautha/ui\").SignInProps): ReactNode {\n return <Mounted name=\"SignIn\" componentProps={props} />;\n}\n\nexport function SignUp(props: import(\"@zautha/ui\").SignUpProps): ReactNode {\n return <Mounted name=\"SignUp\" componentProps={props} />;\n}\n\nexport function UserButton(props: import(\"@zautha/ui\").UserButtonProps): ReactNode {\n return <Mounted name=\"UserButton\" componentProps={props} />;\n}\n\nexport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gBAAgB;CAAQ,CAAA;AAC5D;AAEA,SAAgB,aAAa,OAA0D;CACrF,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAe,gBAAgB;CAAQ,CAAA;AAC9D"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/provider.tsx","../src/hooks.ts","../src/control.tsx","../src/buttons.tsx","../src/prebuilt.tsx"],"sourcesContent":["import { Zautha, type ZauthaOptions, type ZauthaState } from \"@zautha/js\";\nimport { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore, type ReactNode } from \"react\";\n\ninterface ZauthaContextValue {\n readonly zautha: Zautha | null;\n /** The snapshot before the instance exists and during server rendering (carries `initialState`). */\n readonly pending: ZauthaState;\n}\n\nconst ZauthaContext = createContext<ZauthaContextValue | undefined>(undefined);\n\nexport interface ZauthaProviderProps extends Omit<ZauthaOptions, \"fetch\"> {\n publishableKey: string;\n children?: ReactNode;\n}\n\n/**\n * Creates the Zautha instance after mount (never during render, so StrictMode's double mount and SSR\n * create no timers or channels), loads it, and disposes it on unmount. Until then hooks report\n * `isLoaded: false`, unless `initialState` (the server's view, e.g. from @zautha/nextjs) says who is signed in.\n */\nexport function ZauthaProvider({ publishableKey, children, ...options }: ZauthaProviderProps): ReactNode {\n const [zautha, setZautha] = useState<Zautha | null>(null);\n const { ui, appearance, localization, signInUrl, signUpUrl, navigate, initialState } = options;\n const [pending] = useState<ZauthaState>(() => ({ ...NO_STATE, initialState: initialState ?? null }));\n\n useEffect(() => {\n const instance = new Zautha(publishableKey, {\n ...(ui === undefined ? {} : { ui }),\n ...(appearance === undefined ? {} : { appearance }),\n ...(localization === undefined ? {} : { localization }),\n ...(signInUrl === undefined ? {} : { signInUrl }),\n ...(signUpUrl === undefined ? {} : { signUpUrl }),\n ...(navigate === undefined ? {} : { navigate }),\n ...(initialState === undefined ? {} : { initialState }),\n });\n // The instance is an external system: it is created here, never during render, and published through state.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setZautha(instance);\n void instance.load();\n return () => {\n instance.dispose();\n setZautha(null);\n };\n // Appearance/localization objects are read at mount; changing the key re-creates the instance.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [publishableKey]);\n\n const value = useMemo(() => ({ zautha, pending }), [zautha, pending]);\n return <ZauthaContext.Provider value={value}>{children}</ZauthaContext.Provider>;\n}\n\n/** The Zautha instance, or null before the provider has created it. */\nexport function useZautha(): Zautha | null {\n return useZauthaContext().zautha;\n}\n\nfunction useZauthaContext(): ZauthaContextValue {\n const value = useContext(ZauthaContext);\n if (value === undefined) throw new Error(\"Zautha hooks and components must be used inside <ZauthaProvider>.\");\n return value;\n}\n\nconst NO_STATE: ZauthaState = {\n status: \"loading\",\n environment: null,\n client: null,\n session: null,\n user: null,\n initialState: null,\n};\nconst noop = (): (() => void) => () => undefined;\n\n/** Reactive snapshot of the instance state (the loading state, with any initial state, before the instance exists). */\nexport function useZauthaState(): ZauthaState {\n const { zautha, pending } = useZauthaContext();\n return useSyncExternalStore(\n zautha?.subscribe ?? noop,\n () => zautha?.getSnapshot() ?? pending,\n () => pending,\n );\n}\n","import {\n withReverification,\n type AttemptErrors,\n type FetchStatus,\n type Session,\n type SignInResource,\n type SignUpResource,\n type UserResource,\n} from \"@zautha/js\";\nimport { useCallback, useLayoutEffect, useRef, useSyncExternalStore } from \"react\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\n/** Authorization check. In 3a there are no organization claims yet, so role/permission checks are false. */\nexport type HasParams = { role?: string; permission?: string };\nexport type Has = (params: HasParams) => boolean;\n\nexport interface UseAuthResult {\n isLoaded: boolean;\n isSignedIn: boolean;\n userId: string | null;\n sessionId: string | null;\n getToken: (options?: { skipCache?: boolean }) => Promise<string | null>;\n signOut: (options?: { redirectUrl?: string }) => Promise<void>;\n has: Has;\n}\n\nconst isLoadedStatus = (status: string): boolean => status === \"ready\" || status === \"degraded\";\n\nexport function useAuth(): UseAuthResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const getToken = useCallback(\n (options?: { skipCache?: boolean }) => zautha?.getToken(options) ?? Promise.resolve(null),\n [zautha],\n );\n const signOut = useCallback(\n (options?: { redirectUrl?: string }) => zautha?.signOut(options) ?? Promise.resolve(),\n [zautha],\n );\n // Until the first load settles, the server's initial state (if any) answers, so nothing flickers.\n const initial = state.status === \"loading\" ? state.initialState : null;\n const userId = initial === null ? (state.session?.userId ?? null) : initial.userId;\n const sessionId = initial === null ? (state.session?.id ?? null) : initial.sessionId;\n const signedIn = userId !== null;\n const has = useCallback<Has>(\n (params) => signedIn && params.role === undefined && params.permission === undefined,\n [signedIn],\n );\n return {\n isLoaded: isLoadedStatus(state.status) || initial !== null,\n isSignedIn: signedIn,\n userId,\n sessionId,\n getToken,\n signOut,\n has,\n };\n}\n\n/** The signed-in user with its self-service actions (`user.update`, `user.createEmailAddress`, …). */\nexport function useUser(): { isLoaded: boolean; isSignedIn: boolean; user: UserResource | null } {\n const zautha = useZautha();\n const state = useZauthaState();\n // zautha.user is rebuilt only when state.user changes, so the resource is stable between renders.\n const user = state.user === null ? null : (zautha?.user ?? null);\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: state.session !== null, user };\n}\n\n/**\n * Wraps a sensitive action so that it completes after an identity check when it needs one: when `fetcher` throws\n * `ReverificationRequiredError` (e.g. `user.updatePassword`) or resolves to a `Response` with the `403\n * reverification_required` body (your backend with @zautha/backend, @zautha/nextjs or Zautha.AspNetCore), the\n * reverification modal opens and, once the user has verified, `fetcher` runs once more with the same arguments (its\n * token is fresh by then). Closing the modal rejects with `ReverificationCancelledError`. Needs `ui` from @zautha/ui on\n * the provider. The returned function is stable; it always calls the latest `fetcher`.\n */\nexport function useReverification<Args extends unknown[], Result>(\n fetcher: (...args: Args) => Promise<Result>,\n): (...args: Args) => Promise<Result> {\n const zautha = useZautha();\n const latest = useRef(fetcher);\n useLayoutEffect(() => {\n latest.current = fetcher;\n });\n return useCallback(\n (...args: Args) => {\n const call = (...callArgs: Args): Promise<Result> => latest.current(...callArgs);\n // Before the provider has created the instance no modal can open: the action runs as it is.\n return zautha === null ? call(...args) : withReverification(zautha, call)(...args);\n },\n [zautha],\n );\n}\n\nexport function useSession(): { isLoaded: boolean; isSignedIn: boolean; session: Session | null } {\n const state = useZauthaState();\n return { isLoaded: isLoadedStatus(state.status), isSignedIn: state.session !== null, session: state.session };\n}\n\nconst noopSubscribe = (): (() => void) => () => undefined;\n\nfunction useResource<T extends SignInResource | SignUpResource>(resource: T | null) {\n const snapshot = useSyncExternalStore(\n resource?.subscribe ?? noopSubscribe,\n () => resource?.snapshot ?? null,\n () => null,\n );\n return snapshot;\n}\n\nexport interface UseSignInResult {\n isLoaded: boolean;\n /** The sign-in resource; null until the provider has created the instance. */\n signIn: SignInResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nconst NO_ERRORS: AttemptErrors = { fields: {}, global: [] };\n\nexport function useSignIn(): UseSignInResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signIn ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signIn: zautha?.signIn ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n\nexport interface UseSignUpResult {\n isLoaded: boolean;\n signUp: SignUpResource | null;\n errors: AttemptErrors;\n fetchStatus: FetchStatus;\n}\n\nexport function useSignUp(): UseSignUpResult {\n const zautha = useZautha();\n const state = useZauthaState();\n const snapshot = useResource(zautha?.signUp ?? null);\n return {\n isLoaded: isLoadedStatus(state.status),\n signUp: zautha?.signUp ?? null,\n errors: snapshot?.errors ?? NO_ERRORS,\n fetchStatus: snapshot?.fetchStatus ?? \"idle\",\n };\n}\n","import { useEffect, type ReactNode } from \"react\";\nimport { useAuth, type Has, type HasParams } from \"./hooks\";\nimport { useZautha, useZauthaState } from \"./provider\";\n\nexport type ShowWhen = \"signed-in\" | \"signed-out\" | HasParams | ((has: Has) => boolean);\n\n/**\n * Renders `children` when the condition holds, else `fallback`. Renders nothing until Zautha has\n * loaded, so a signed-in user never sees a signed-out flash.\n */\nexport function Show(props: { when: ShowWhen; fallback?: ReactNode; children?: ReactNode }): ReactNode {\n const { isLoaded, isSignedIn, has } = useAuth();\n if (!isLoaded) return null;\n const { when } = props;\n const pass =\n when === \"signed-in\"\n ? isSignedIn\n : when === \"signed-out\"\n ? !isSignedIn\n : typeof when === \"function\"\n ? when(has)\n : has(when);\n return pass ? props.children : (props.fallback ?? null);\n}\n\nexport function ZauthaLoading(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"loading\" ? props.children : null;\n}\n\n/** Loaded, including degraded (network trouble after load: last known state is shown). */\nexport function ZauthaLoaded(props: { children?: ReactNode }): ReactNode {\n const { status } = useZauthaState();\n return status === \"ready\" || status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaDegraded(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"degraded\" ? props.children : null;\n}\n\nexport function ZauthaFailed(props: { children?: ReactNode }): ReactNode {\n return useZauthaState().status === \"failed\" ? props.children : null;\n}\n\n/** Sends a signed-out visitor to sign-in once loaded; renders nothing. */\nexport function RedirectToSignIn(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignIn(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n\nexport function RedirectToSignUp(props: { redirectUrl?: string }): ReactNode {\n const zautha = useZautha();\n const { isLoaded, isSignedIn } = useAuth();\n const { redirectUrl } = props;\n useEffect(() => {\n if (zautha !== null && isLoaded && !isSignedIn)\n zautha.redirectToSignUp(redirectUrl === undefined ? {} : { redirectUrl });\n }, [zautha, isLoaded, isSignedIn, redirectUrl]);\n return null;\n}\n","import { Children, cloneElement, isValidElement, type MouseEvent, type ReactElement, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\ninterface ButtonProps {\n /** `redirect` (default) goes to the sign-in page; `modal` opens the prebuilt component (needs `ui`). */\n mode?: \"redirect\" | \"modal\";\n redirectUrl?: string;\n children?: ReactNode;\n}\n\n/** Wraps its single child (or renders a plain button) and wires the click. Unstyled by design. */\nfunction Trigger(props: { children: ReactNode; label: string; onClick: () => void }): ReactNode {\n const child = Children.count(props.children) === 1 ? Children.only(props.children) : null;\n if (isValidElement<{ onClick?: (event: MouseEvent) => void }>(child)) {\n const original = child.props.onClick;\n return cloneElement(child as ReactElement<{ onClick?: (event: MouseEvent) => void }>, {\n onClick: (event: MouseEvent) => {\n original?.(event);\n if (!event.defaultPrevented) props.onClick();\n },\n });\n }\n return (\n <button type=\"button\" onClick={props.onClick}>\n {props.children ?? props.label}\n </button>\n );\n}\n\nexport function SignInButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign in\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignIn(options) : zautha?.redirectToSignIn(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignUpButton(props: ButtonProps): ReactNode {\n const zautha = useZautha();\n const options = props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl };\n return (\n <Trigger\n label=\"Sign up\"\n onClick={() => (props.mode === \"modal\" ? zautha?.openSignUp(options) : zautha?.redirectToSignUp(options))}\n >\n {props.children}\n </Trigger>\n );\n}\n\nexport function SignOutButton(props: { redirectUrl?: string; children?: ReactNode }): ReactNode {\n const zautha = useZautha();\n return (\n <Trigger\n label=\"Sign out\"\n onClick={() => void zautha?.signOut(props.redirectUrl === undefined ? {} : { redirectUrl: props.redirectUrl })}\n >\n {props.children}\n </Trigger>\n );\n}\n","import type { UiComponentName } from \"@zautha/js\";\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport { useZautha } from \"./provider\";\n\n/**\n * Mounts a @zautha/ui component into a div once the instance exists; later prop changes update it in\n * place. SSR renders only the empty div.\n */\nfunction Mounted(props: { name: UiComponentName; componentProps: object }): ReactNode {\n const zautha = useZautha();\n const ref = useRef<HTMLDivElement>(null);\n const mountedWith = useRef<object | null>(null);\n const { name, componentProps } = props;\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null) return;\n zautha.mount(name, element, componentProps);\n mountedWith.current = componentProps;\n return () => {\n mountedWith.current = null;\n zautha.unmount(element);\n };\n // componentProps changes are applied by the effect below without remounting.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [zautha, name]);\n\n useEffect(() => {\n const element = ref.current;\n if (zautha === null || element === null || mountedWith.current === null || mountedWith.current === componentProps)\n return;\n mountedWith.current = componentProps;\n zautha.updateMounted(element, componentProps);\n }, [zautha, componentProps]);\n\n return <div ref={ref} />;\n}\n\n// Prop types live in @zautha/ui; they are structural here so @zautha/react has no runtime dependency on it.\nexport function SignIn(props: import(\"@zautha/ui\").SignInProps): ReactNode {\n return <Mounted name=\"SignIn\" componentProps={props} />;\n}\n\nexport function SignUp(props: import(\"@zautha/ui\").SignUpProps): ReactNode {\n return <Mounted name=\"SignUp\" componentProps={props} />;\n}\n\nexport function UserButton(props: import(\"@zautha/ui\").UserButtonProps): ReactNode {\n return <Mounted name=\"UserButton\" componentProps={props} />;\n}\n\nexport function UserProfile(props: import(\"@zautha/ui\").UserProfileProps): ReactNode {\n return <Mounted name=\"UserProfile\" componentProps={props} />;\n}\n\nexport function OAuthConsent(props: import(\"@zautha/ui\").OAuthConsentProps): ReactNode {\n return <Mounted name=\"OAuthConsent\" componentProps={props} />;\n}\n"],"mappings":";;;;;AASA,MAAM,gBAAgB,cAA8C,KAAA,CAAS;;;;;;AAY7E,SAAgB,eAAe,EAAE,gBAAgB,UAAU,GAAG,WAA2C;CACvG,MAAM,CAAC,QAAQ,aAAa,SAAwB,IAAI;CACxD,MAAM,EAAE,IAAI,YAAY,cAAc,WAAW,WAAW,UAAU,iBAAi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GAAG,CAAC,QAAQ,IAAI,CAAC;CAEjB,gBAAgB;EACd,MAAM,UAAU,IAAI;EACpB,IAAI,WAAW,QAAQ,YAAY,QAAQ,YAAY,YAAY,QAAQ,YAAY,YAAY,gBACjG;EACF,YAAY,UAAU;EACtB,OAAO,cAAc,SAAS,cAAc;CAC9C,GAAG,CAAC,QAAQ,cAAc,CAAC;CAE3B,OAAO,oBAAC,OAAD,EAAU,IAAM,CAAA;AACzB;AAGA,SAAgB,OAAO,OAAoD;CACzE,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAS,gBAAgB;CAAQ,CAAA;AACxD;AAEA,SAAgB,OAAO,OAAoD;CACzE,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAS,gBAAgB;CAAQ,CAAA;AACxD;AAEA,SAAgB,WAAW,OAAwD;CACjF,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAa,gBAAgB;CAAQ,CAAA;AAC5D;AAEA,SAAgB,YAAY,OAAyD;CACnF,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAc,gBAAgB;CAAQ,CAAA;AAC7D;AAEA,SAAgB,aAAa,OAA0D;CACrF,OAAO,oBAAC,SAAD;EAAS,MAAK;EAAe,gBAAgB;CAAQ,CAAA;AAC9D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zautha/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "React bindings for Zautha: provider, hooks, <Show>, buttons and prebuilt components.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"LICENSE"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@zautha/js": "^0.
|
|
34
|
+
"@zautha/js": "^0.3.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": "^19.0.0",
|
|
38
38
|
"react-dom": "^19.0.0",
|
|
39
|
-
"@zautha/ui": "^0.
|
|
39
|
+
"@zautha/ui": "^0.3.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@size-limit/preset-small-lib": "14.0.1",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@testing-library/user-event": "14.6.7",
|
|
45
45
|
"@types/react": "19.3.0",
|
|
46
46
|
"@types/react-dom": "19.3.0",
|
|
47
|
-
"@zautha/ui": "0.
|
|
47
|
+
"@zautha/ui": "0.3.0",
|
|
48
48
|
"happy-dom": "20.14.5",
|
|
49
49
|
"msw": "2.15.0",
|
|
50
50
|
"react": "19.3.0",
|