@pisti-paypiller/react 0.0.0-stage → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +159 -2
  3. package/dist/api-keys.d.ts +8 -0
  4. package/dist/api-keys.d.ts.map +1 -0
  5. package/dist/api-keys.js +54 -0
  6. package/dist/api-keys.js.map +1 -0
  7. package/dist/async-state.d.ts +14 -0
  8. package/dist/async-state.d.ts.map +1 -0
  9. package/dist/async-state.js +81 -0
  10. package/dist/async-state.js.map +1 -0
  11. package/dist/auth.d.ts +23 -0
  12. package/dist/auth.d.ts.map +1 -0
  13. package/dist/auth.js +297 -0
  14. package/dist/auth.js.map +1 -0
  15. package/dist/client.d.ts +152 -0
  16. package/dist/client.d.ts.map +1 -0
  17. package/dist/client.js +633 -0
  18. package/dist/client.js.map +1 -0
  19. package/dist/context.d.ts +94 -0
  20. package/dist/context.d.ts.map +1 -0
  21. package/dist/context.js +145 -0
  22. package/dist/context.js.map +1 -0
  23. package/dist/index.d.ts +15 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +9 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/organizations.d.ts +16 -0
  28. package/dist/organizations.d.ts.map +1 -0
  29. package/dist/organizations.js +169 -0
  30. package/dist/organizations.js.map +1 -0
  31. package/dist/resources.d.ts +204 -0
  32. package/dist/resources.d.ts.map +1 -0
  33. package/dist/resources.js +129 -0
  34. package/dist/resources.js.map +1 -0
  35. package/dist/reverification.d.ts +5 -0
  36. package/dist/reverification.d.ts.map +1 -0
  37. package/dist/reverification.js +54 -0
  38. package/dist/reverification.js.map +1 -0
  39. package/dist/types.d.ts +118 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +2 -0
  42. package/dist/types.js.map +1 -0
  43. package/dist/ui.d.ts +72 -0
  44. package/dist/ui.d.ts.map +1 -0
  45. package/dist/ui.js +125 -0
  46. package/dist/ui.js.map +1 -0
  47. package/dist/user-profile.d.ts +6 -0
  48. package/dist/user-profile.d.ts.map +1 -0
  49. package/dist/user-profile.js +219 -0
  50. package/dist/user-profile.js.map +1 -0
  51. package/package.json +48 -4
  52. package/styles.css +517 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pisti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,160 @@
1
- # Temporary Holding Version
1
+ # @pisti-paypiller/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Pisti for React, shaped like `@clerk/react`: one provider, prebuilt sign-in and account
4
+ components, and hooks. It talks to your environment's Frontend API directly from the browser;
5
+ the publishable key is the only required setting. Supports React 18.3 and 19.
6
+
7
+ ```tsx
8
+ import { PistiProvider, Show, SignInButton, SignUpButton, UserButton } from "@pisti-paypiller/react";
9
+ import "@pisti-paypiller/react/styles.css";
10
+
11
+ export function App() {
12
+ return (
13
+ <PistiProvider>
14
+ <header>
15
+ <Show when="signed-out">
16
+ <SignInButton />
17
+ <SignUpButton />
18
+ </Show>
19
+ <Show when="signed-in">
20
+ <UserButton />
21
+ </Show>
22
+ </header>
23
+ </PistiProvider>
24
+ );
25
+ }
26
+ ```
27
+
28
+ That's a working app. `<PistiProvider>` reads `VITE_PISTI_PUBLISHABLE_KEY` (or
29
+ `PISTI_PUBLISHABLE_KEY`) by itself, `SignInButton` opens sign-in in a modal and `UserButton`
30
+ gives the signed-in user Manage account and Sign out.
31
+
32
+ ## Install
33
+
34
+ ```sh
35
+ npm install @pisti-paypiller/react
36
+ ```
37
+
38
+ ```sh
39
+ VITE_PISTI_PUBLISHABLE_KEY=pk_test_…
40
+ ```
41
+
42
+ Apps on `http://localhost` work with development environments as they are. For production, add
43
+ your app's origin under Domains & paths in the console.
44
+
45
+ ## Dedicated pages and your router
46
+
47
+ ```tsx
48
+ import { BrowserRouter, Routes, Route, useNavigate } from "react-router";
49
+ import { PistiProvider, SignIn, SignUp, Show, RedirectToSignIn } from "@pisti-paypiller/react";
50
+
51
+ function PistiWithRouter({ children }: { children: React.ReactNode }) {
52
+ const navigate = useNavigate();
53
+ return (
54
+ <PistiProvider
55
+ signInUrl="/sign-in"
56
+ signUpUrl="/sign-up"
57
+ signInFallbackRedirectUrl="/dashboard"
58
+ afterSignOutUrl="/"
59
+ routerPush={(to) => navigate(to)}
60
+ routerReplace={(to) => navigate(to, { replace: true })}
61
+ >
62
+ {children}
63
+ </PistiProvider>
64
+ );
65
+ }
66
+
67
+ const Protected = ({ children }: { children: React.ReactNode }) => (
68
+ <Show when="signed-in" fallback={<RedirectToSignIn />}>
69
+ {children}
70
+ </Show>
71
+ );
72
+
73
+ export const App = () => (
74
+ <BrowserRouter>
75
+ <PistiWithRouter>
76
+ <Routes>
77
+ <Route path="/sign-in" element={<SignIn />} />
78
+ <Route path="/sign-up" element={<SignUp />} />
79
+ <Route path="/dashboard" element={<Protected><Dashboard /></Protected>} />
80
+ </Routes>
81
+ </PistiWithRouter>
82
+ </BrowserRouter>
83
+ );
84
+ ```
85
+
86
+ After sign-in, visitors go to the first of: `forceRedirectUrl` (prop, then provider),
87
+ `redirect_url` in the URL (set by `RedirectToSignIn` and `requireAuth()`), `fallbackRedirectUrl`
88
+ (prop, then provider), the console's Domains & paths setting, then `/`. Sign-up works the same
89
+ way with the `signUp…` props. A signed-in visitor who opens `/sign-in` goes straight on, and with
90
+ `routerPush` none of this reloads the page. Without a `signInUrl`, buttons and redirects open the
91
+ modal.
92
+
93
+ ### Provider props
94
+
95
+ Each prop falls back to an environment variable, so most apps pass none.
96
+
97
+ | Prop | Environment variable | Default |
98
+ | --- | --- | --- |
99
+ | `publishableKey` | `VITE_PISTI_PUBLISHABLE_KEY` | Required |
100
+ | `signInUrl`, `signUpUrl` | `VITE_PISTI_SIGN_IN_URL`, `VITE_PISTI_SIGN_UP_URL` | Console setting, else modals |
101
+ | `signInFallbackRedirectUrl`, `signUpFallbackRedirectUrl` | `VITE_PISTI_SIGN_IN_FALLBACK_REDIRECT_URL`, `VITE_PISTI_SIGN_UP_FALLBACK_REDIRECT_URL` | Console setting, then `/` |
102
+ | `signInForceRedirectUrl`, `signUpForceRedirectUrl` | `VITE_PISTI_SIGN_IN_FORCE_REDIRECT_URL`, `VITE_PISTI_SIGN_UP_FORCE_REDIRECT_URL` | None |
103
+ | `afterSignOutUrl` | `VITE_PISTI_AFTER_SIGN_OUT_URL` | Console setting, then `/` |
104
+ | `allowedRedirectOrigins` | — | Your app's origin |
105
+ | `routerPush`, `routerReplace` | — | Full page navigation |
106
+ | `appearance` | — | `{ variables: { colorPrimary, colorPrimaryText, colorBackground, colorText, colorTextSecondary, colorBorder, borderRadius, fontFamily } }` |
107
+ | `handleInvitations` | — | `true`: handles `?pisti_invitation=` organization invitation links |
108
+
109
+ ## Components
110
+
111
+ | Component | What it does |
112
+ | --- | --- |
113
+ | `<SignIn />` | Password or email code, two-step verification (including required enrollment and recovery codes), password reset and reactivating a deactivated account. `forceRedirectUrl`, `fallbackRedirectUrl`, `signUpUrl`. |
114
+ | `<SignUp />` | Email verification by code, name and optional password. `forceRedirectUrl`, `fallbackRedirectUrl`, `signInUrl`. |
115
+ | `<Show when fallback>` | Renders for `"signed-in"`, `"signed-out"`, `{ permission }`, `{ role }` or `(has) => boolean` |
116
+ | `<SignInButton />`, `<SignUpButton />` | `mode="modal"` or `"redirect"` (the default when you have a sign-in page), `forceRedirectUrl`, `fallbackRedirectUrl`. Pass your own button as the child to style it. |
117
+ | `<SignOutButton redirectUrl? />` | Signs out, then goes to `redirectUrl` or `afterSignOutUrl`. Accepts a custom child. |
118
+ | `<UserButton />` | Avatar menu. `userProfileMode="navigation"` with `userProfileUrl` for your own page, or `"modal"` (default). `showName`. |
119
+ | `<RedirectToSignIn />`, `<RedirectToSignUp />` | Redirect on render |
120
+ | `<PistiLoaded>`, `<PistiLoading>` | Render after and before the session is known |
121
+ | `<UserProfile apiKeys? />` | Profile, email, password, two-step verification, recovery codes, devices; with `apiKeys`, an API keys page |
122
+ | `<APIKeys />` | Lets the user create, copy and revoke `ak_…` keys for your API. Your backend accepts them with `acceptsToken: "api_key"`. |
123
+ | `<OrganizationSwitcher />`, `<CreateOrganization />`, `<OrganizationProfile />`, `<AcceptOrganizationInvitation />` | Organizations, members, roles, invitations |
124
+
125
+ ## Hooks
126
+
127
+ | Hook | Returns |
128
+ | --- | --- |
129
+ | `useAuth()` | `isLoaded`, `isSignedIn`, `userId`, `sessionId`, `orgId`, `orgSlug`, `orgRole`, `sessionClaims`, `has({ permission, role })`, `getToken()`, `signOut()` |
130
+ | `useUser()` | `user`: `id`, `firstName`, `lastName`, `fullName`, `primaryEmailAddress.emailAddress`, `imageUrl`, `hasImage` |
131
+ | `useSession()` | `session`: `id` and `user` |
132
+ | `usePisti()` | The client: `openSignIn()`, `openSignUp()`, `openUserProfile()`, `closeModal()`, `redirectToSignIn()`, `navigate()`, `signOut()`, `getToken()` |
133
+ | `useAuthenticatedFetch()` | `fetch` with the session token as `Authorization: Bearer`; retries once on 401 |
134
+ | `useSignIn()`, `useSignUp()` | The individual steps, for fully custom forms |
135
+ | `useOrganization()` | Active organization, role, permissions, `setActive(id \| null)` |
136
+ | `useOrganizationList()`, `useAccount()` | Organization and account resources |
137
+ | `useReverification(fn)` | Runs `fn`, asking for the password again if the server needs a recent sign-in |
138
+
139
+ ## Calling your API
140
+
141
+ ```tsx
142
+ const fetchWithSession = useAuthenticatedFetch();
143
+ const response = await fetchWithSession("https://api.example.com/projects");
144
+ ```
145
+
146
+ The SDK keeps a session token (about 60 seconds) fresh in the `__session` cookie on your app's
147
+ origin, so same-site API routes receive it automatically. It also writes `__client_uat`, the
148
+ session's sign-in time (or `0` when signed out), which lets server-rendered pages refresh an
149
+ expired cookie with a handshake instead of treating the visitor as signed out. For APIs on another domain use
150
+ `useAuthenticatedFetch()` or `getToken()`. Verify the token on the server with
151
+ [`@pisti-paypiller/express`](../express/README.md) or [`@pisti-paypiller/backend`](../backend/README.md).
152
+ `<Show>` and `isSignedIn` only control rendering; your API must enforce access.
153
+
154
+ ## Deploying
155
+
156
+ The SDK is static browser code; build and host your app anywhere. For production, use the
157
+ `pk_live_` key, serve over HTTPS, and add your app's origin under Domains & paths.
158
+
159
+ See `sdk.md` in the pisti-docs repository for how the pieces fit, and `pisti-demo`
160
+ in the pisti-examples repository for a working example.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Lets the signed-in user create, copy and revoke API keys for your API, like Clerk's `<APIKeys />`.
3
+ * Your backend accepts them with `getAuth(req, { acceptsToken: "api_key" })`.
4
+ */
5
+ export declare function APIKeys({ className }: {
6
+ className?: string;
7
+ }): import("react").JSX.Element;
8
+ //# sourceMappingURL=api-keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-keys.d.ts","sourceRoot":"","sources":["../src/api-keys.tsx"],"names":[],"mappings":"AAWA;;;GAGG;AACH,wBAAgB,OAAO,CAAC,EAAE,SAAc,EAAE,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,+BA+HjE"}
@@ -0,0 +1,54 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useAccount, useAuth } from "./context.js";
4
+ import { ActionNotice, ErrorNotice, Loading, useAction, useResource } from "./ui.js";
5
+ const lifetimes = [
6
+ { label: "Never expires", seconds: null },
7
+ { label: "30 days", seconds: 30 * 86_400 },
8
+ { label: "90 days", seconds: 90 * 86_400 },
9
+ { label: "1 year", seconds: 365 * 86_400 },
10
+ ];
11
+ /**
12
+ * Lets the signed-in user create, copy and revoke API keys for your API, like Clerk's `<APIKeys />`.
13
+ * Your backend accepts them with `getAuth(req, { acceptsToken: "api_key" })`.
14
+ */
15
+ export function APIKeys({ className = "" }) {
16
+ const account = useAccount();
17
+ const { isLoaded, isSignedIn } = useAuth();
18
+ const keys = useResource(account.apiKeys);
19
+ const action = useAction();
20
+ const [creating, setCreating] = useState(false);
21
+ const [secret, setSecret] = useState(null);
22
+ const [copied, setCopied] = useState(false);
23
+ if (!isLoaded)
24
+ return _jsx(Loading, {});
25
+ if (!isSignedIn)
26
+ return _jsx("p", { children: "Sign in to manage your API keys." });
27
+ function create(event) {
28
+ event.preventDefault();
29
+ const form = new FormData(event.currentTarget);
30
+ const name = String(form.get("name") ?? "").trim();
31
+ const lifetime = lifetimes[Number(form.get("lifetime") ?? 0)]?.seconds ?? null;
32
+ if (!name)
33
+ return;
34
+ void action.run(async () => {
35
+ const created = await account.createApiKey({
36
+ name,
37
+ ...(lifetime ? { secondsUntilExpiration: lifetime } : {}),
38
+ });
39
+ setSecret({ name: created.apiKey.name, value: created.secret });
40
+ setCopied(false);
41
+ setCreating(false);
42
+ keys.reload();
43
+ });
44
+ }
45
+ return (_jsxs("section", { className: "pisti-ui pisti-section " + className, children: [_jsx("h3", { children: "API keys" }), _jsx("p", { className: "pisti-muted", children: "Keys let scripts and integrations call this app as you. Treat them like passwords." }), secret && (_jsxs("div", { className: "pisti-notice", role: "status", children: [_jsxs("p", { children: [_jsx("strong", { children: secret.name }), " is ready. Copy it now: it won\u2019t be shown again."] }), _jsx("code", { className: "pisti-secret", children: secret.value }), _jsxs("div", { className: "pisti-actions", children: [_jsx("button", { type: "button", className: "pisti-secondary", onClick: () => void navigator.clipboard?.writeText(secret.value).then(() => setCopied(true), () => setCopied(false)), children: copied ? "Copied" : "Copy key" }), _jsx("button", { type: "button", className: "pisti-secondary", onClick: () => setSecret(null), children: "Done" })] })] })), keys.isLoading && _jsx(Loading, {}), _jsx(ErrorNotice, { error: keys.error, retry: keys.reload }), _jsx(ActionNotice, { action: action }), keys.data?.length === 0 && !creating && _jsx("p", { children: "You have no API keys yet." }), _jsx("ul", { className: "pisti-list", children: keys.data?.map((key) => (_jsxs("li", { children: [_jsxs("div", { children: [key.name, _jsxs("p", { className: "pisti-muted", children: [_jsxs("code", { children: [key.keyPrefix, "\u2026"] }), " \u00B7", " ", key.expired
46
+ ? "Expired"
47
+ : key.expiresAt
48
+ ? `Expires ${new Date(key.expiresAt).toLocaleDateString()}`
49
+ : "Never expires", " ", "\u00B7 ", key.lastUsedAt ? `Last used ${new Date(key.lastUsedAt).toLocaleDateString()}` : "Never used"] })] }), _jsx("button", { type: "button", className: "pisti-secondary", disabled: action.isPending, onClick: () => void action.run(async () => {
50
+ await account.revokeApiKey(key.id);
51
+ keys.reload();
52
+ }, "API key revoked."), children: "Revoke" })] }, key.id))) }), creating ? (_jsxs("form", { className: "pisti-form", onSubmit: create, children: [_jsxs("label", { children: ["Name", _jsx("input", { name: "name", required: true, maxLength: 100, placeholder: "Deploy script", autoFocus: true })] }), _jsxs("label", { children: ["Expiration", _jsx("select", { name: "lifetime", defaultValue: "0", children: lifetimes.map((lifetime, index) => (_jsx("option", { value: index, children: lifetime.label }, lifetime.label))) })] }), _jsxs("div", { className: "pisti-actions", children: [_jsx("button", { type: "submit", disabled: action.isPending, children: action.isPending ? "Creating…" : "Create key" }), _jsx("button", { type: "button", className: "pisti-secondary", onClick: () => setCreating(false), children: "Cancel" })] })] })) : (_jsx("div", { className: "pisti-actions", children: _jsx("button", { type: "button", onClick: () => setCreating(true), children: "New API key" }) }))] }));
53
+ }
54
+ //# sourceMappingURL=api-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-keys.js","sourceRoot":"","sources":["../src/api-keys.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAErF,MAAM,SAAS,GAAG;IACd,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE;IACzC,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,GAAG,MAAM,EAAE;IAC1C,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,GAAG,MAAM,EAAE;IAC1C,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,GAAG,MAAM,EAAE;CACpC,CAAC;AAEX;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,EAAE,SAAS,GAAG,EAAE,EAA0B;IAC9D,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,OAAO,EAAE,CAAC;IAC3C,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,CAAC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ACG,IACL,EACR,eAAK,SAAS,EAAC,eAAe,aAC1B,iBAAQ,IAAI,EAAC,QAAQ,EAAC,QAAQ,EAAE,MAAM,CAAC,SAAS,YAC3C,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,GACzC,EACT,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,iBAAiB,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,uBAE1E,IACP,IACH,CACV,CAAC,CAAC,CAAC,CACA,cAAK,SAAS,EAAC,eAAe,YAC1B,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,4BAE7C,GACP,CACT,IACK,CACb,CAAC;AACN,CAAC"}
@@ -0,0 +1,14 @@
1
+ export declare function useResource<T>(load: () => Promise<T>): {
2
+ data: T | null;
3
+ error: Error | null;
4
+ isLoading: boolean;
5
+ reload: () => void;
6
+ };
7
+ export declare function useAction(): {
8
+ run: <T>(task: () => Promise<T>, message?: string) => Promise<T | undefined>;
9
+ isPending: boolean;
10
+ error: Error | null;
11
+ success: string | null;
12
+ reset: () => void;
13
+ };
14
+ //# sourceMappingURL=async-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-state.d.ts","sourceRoot":"","sources":["../src/async-state.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;;;;;EAsDpD;AAED,wBAAgB,SAAS;UAKF,CAAC,QACV,MAAM,OAAO,CAAC,CAAC,CAAC,YACZ,MAAM,KACjB,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;;;;;EA2B5B"}
@@ -0,0 +1,81 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ export function useResource(load) {
3
+ const [result, setResult] = useState({ owner: load, data: null, error: null, isLoading: true });
4
+ const [version, setVersion] = useState(0);
5
+ useEffect(() => {
6
+ let active = true;
7
+ setResult((previous) => ({
8
+ owner: load,
9
+ data: previous.owner === load ? previous.data : null,
10
+ error: null,
11
+ isLoading: true,
12
+ }));
13
+ void load().then((value) => {
14
+ if (active)
15
+ setResult({
16
+ owner: load,
17
+ data: value,
18
+ error: null,
19
+ isLoading: false,
20
+ });
21
+ }, (failure) => {
22
+ if (active)
23
+ setResult((previous) => ({
24
+ owner: load,
25
+ data: previous.owner === load ? previous.data : null,
26
+ error: failure instanceof Error
27
+ ? failure
28
+ : new Error("Unable to load this information."),
29
+ isLoading: false,
30
+ }));
31
+ });
32
+ return () => {
33
+ active = false;
34
+ };
35
+ }, [load, version]);
36
+ const reload = useCallback(() => setVersion((value) => value + 1), []);
37
+ const current = result.owner === load
38
+ ? result
39
+ : { data: null, error: null, isLoading: true };
40
+ return {
41
+ data: current.data,
42
+ error: current.error,
43
+ isLoading: current.isLoading,
44
+ reload,
45
+ };
46
+ }
47
+ export function useAction() {
48
+ const running = useRef(false);
49
+ const [isPending, setPending] = useState(false);
50
+ const [error, setError] = useState(null);
51
+ const [success, setSuccess] = useState(null);
52
+ const run = async (task, message) => {
53
+ if (running.current)
54
+ return undefined;
55
+ running.current = true;
56
+ setPending(true);
57
+ setError(null);
58
+ setSuccess(null);
59
+ try {
60
+ const result = await task();
61
+ setSuccess(message ?? null);
62
+ return result;
63
+ }
64
+ catch (failure) {
65
+ setError(failure instanceof Error
66
+ ? failure
67
+ : new Error("The operation could not be completed."));
68
+ return undefined;
69
+ }
70
+ finally {
71
+ running.current = false;
72
+ setPending(false);
73
+ }
74
+ };
75
+ const reset = useCallback(() => {
76
+ setError(null);
77
+ setSuccess(null);
78
+ }, []);
79
+ return { run, isPending, error, success, reset };
80
+ }
81
+ //# sourceMappingURL=async-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-state.js","sourceRoot":"","sources":["../src/async-state.ts"],"names":[],"mappings":"AAAA,OAAO,EA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CAAC;QACjB,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;YAC5B,UAAU,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC;YAC5B,OAAO,MAAM,CAAC;QAClB,CAAC;QAAC,OAAO,OAAO,EAAE,CAAC;YACf,QAAQ,CACJ,OAAO,YAAY,KAAK;gBACpB,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAC3D,CAAC;YACF,OAAO,SAAS,CAAC;QACrB,CAAC;gBAAS,CAAC;YACP,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;YACxB,UAAU,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACL,CAAC,CAAC;IACF,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC3B,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,UAAU,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACrD,CAAC"}
package/dist/auth.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /** Set by the provider's modal host, so the forms close the modal instead of redirecting. */
2
+ export declare const ModalContext: import("react").Context<boolean>;
3
+ export interface SignInProps {
4
+ /** Always go here after signing in. */
5
+ forceRedirectUrl?: string | undefined;
6
+ /** Go here after signing in when there is no `redirect_url`. */
7
+ fallbackRedirectUrl?: string | undefined;
8
+ /** Where the "Sign up" link goes. Defaults to the provider's signUpUrl, else a modal. */
9
+ signUpUrl?: string | undefined;
10
+ className?: string | undefined;
11
+ }
12
+ export interface SignUpProps {
13
+ forceRedirectUrl?: string | undefined;
14
+ fallbackRedirectUrl?: string | undefined;
15
+ /** Where the "Sign in" link goes. Defaults to the provider's signInUrl, else a modal. */
16
+ signInUrl?: string | undefined;
17
+ className?: string | undefined;
18
+ }
19
+ /** A complete sign-in form: password or email code, two-step verification and password reset. */
20
+ export declare function SignIn({ forceRedirectUrl, fallbackRedirectUrl, signUpUrl, className }: SignInProps): import("react").JSX.Element;
21
+ /** A complete sign-up form: email verification by code, name and an optional password. */
22
+ export declare function SignUp({ forceRedirectUrl, fallbackRedirectUrl, signInUrl, className }: SignUpProps): import("react").JSX.Element;
23
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.tsx"],"names":[],"mappings":"AAmBA,6FAA6F;AAC7F,eAAO,MAAM,YAAY,kCAAuB,CAAC;AAEjD,MAAM,WAAW,WAAW;IACxB,uCAAuC;IACvC,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,gEAAgE;IAChE,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC;AAED,MAAM,WAAW,WAAW;IACxB,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,mBAAmB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC;AA2FD,iGAAiG;AACjG,wBAAgB,MAAM,CAAC,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,WAAW,+BAqZlG;AAED,0FAA0F;AAC1F,wBAAgB,MAAM,CAAC,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,WAAW,+BA0IlG"}