@atlasauth/react 0.1.17 → 0.1.19
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/CHANGELOG.md +18 -0
- package/dist/AtlasProvider.d.ts +9 -0
- package/dist/AtlasProvider.js +2 -0
- package/dist/AtlasProvider.js.map +1 -1
- package/dist/account.d.ts +66 -0
- package/dist/account.js +223 -0
- package/dist/account.js.map +1 -0
- package/dist/auth-buttons.d.ts +29 -0
- package/dist/auth-buttons.js +43 -0
- package/dist/auth-buttons.js.map +1 -0
- package/dist/billing.d.ts +127 -0
- package/dist/billing.js +235 -0
- package/dist/billing.js.map +1 -0
- package/dist/components-shared.d.ts +22 -0
- package/dist/components-shared.js +70 -0
- package/dist/components-shared.js.map +1 -0
- package/dist/components.d.ts +29 -427
- package/dist/components.js +68 -1223
- package/dist/components.js.map +1 -1
- package/dist/control-components.d.ts +46 -0
- package/dist/control-components.js +69 -0
- package/dist/control-components.js.map +1 -0
- package/dist/flow.d.ts +81 -0
- package/dist/flow.js +319 -0
- package/dist/flow.js.map +1 -0
- package/dist/organization.d.ts +37 -0
- package/dist/organization.js +111 -0
- package/dist/organization.js.map +1 -0
- package/dist/reverification.d.ts +21 -0
- package/dist/reverification.js +74 -0
- package/dist/reverification.js.map +1 -0
- package/dist/sign-in.d.ts +42 -0
- package/dist/sign-in.js +91 -0
- package/dist/sign-in.js.map +1 -0
- package/dist/sign-up.d.ts +18 -0
- package/dist/sign-up.js +37 -0
- package/dist/sign-up.js.map +1 -0
- package/dist/user-button.d.ts +54 -0
- package/dist/user-button.js +75 -0
- package/dist/user-button.js.map +1 -0
- package/dist/waitlist.d.ts +15 -0
- package/dist/waitlist.js +52 -0
- package/dist/waitlist.js.map +1 -0
- package/package.json +4 -3
package/dist/flow.js
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AttemptFlow = AttemptFlow;
|
|
4
|
+
exports.useFlow = useFlow;
|
|
5
|
+
exports.SocialSignInButtons = SocialSignInButtons;
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const js_1 = require("@atlasauth/js");
|
|
9
|
+
const AtlasProvider_1 = require("./AtlasProvider");
|
|
10
|
+
const fapi_1 = require("./fapi");
|
|
11
|
+
const components_shared_1 = require("./components-shared");
|
|
12
|
+
/**
|
|
13
|
+
* The server-driven flow shell.
|
|
14
|
+
*
|
|
15
|
+
* Every branch comes from `nextStep`, which is exhaustive — including the
|
|
16
|
+
* `unknown` case, which renders an honest message instead of nothing.
|
|
17
|
+
*/
|
|
18
|
+
function AttemptFlow({ attempt, onSubmit, busy, errors, titleKey, hideTitle, }) {
|
|
19
|
+
const t = (0, components_shared_1.useText)();
|
|
20
|
+
const cardClass = (0, components_shared_1.useClass)('card', 'atlas-card');
|
|
21
|
+
const titleClass = (0, components_shared_1.useClass)('headerTitle', 'atlas-title');
|
|
22
|
+
const inputClass = (0, components_shared_1.useClass)('formFieldInput', 'atlas-input');
|
|
23
|
+
const buttonClass = (0, components_shared_1.useClass)('formButtonPrimary', 'atlas-button');
|
|
24
|
+
const errorClass = (0, components_shared_1.useClass)('formFieldError', 'atlas-error');
|
|
25
|
+
const [values, setValues] = (0, react_1.useState)({});
|
|
26
|
+
const step = attempt ? (0, js_1.nextStep)(attempt) : { kind: 'collect_identifier' };
|
|
27
|
+
const field = (name, labelKey, type = 'text') => ((0, jsx_runtime_1.jsxs)("label", { className: "atlas-field", children: [(0, jsx_runtime_1.jsx)("span", { children: t(labelKey) }), (0, jsx_runtime_1.jsx)("input", { className: inputClass, type: type, value: values[name] ?? '', onChange: (event) => setValues((v) => ({ ...v, [name]: event.target.value })) }), errors
|
|
28
|
+
.filter((error) => error.param === name)
|
|
29
|
+
.map((error) => ((0, jsx_runtime_1.jsx)("span", { className: errorClass, children: error.message }, error.code)))] }, name));
|
|
30
|
+
const fields = () => {
|
|
31
|
+
switch (step.kind) {
|
|
32
|
+
case 'collect_identifier':
|
|
33
|
+
return [field('identifier', 'signIn.identifierLabel', 'email')];
|
|
34
|
+
case 'collect_first_factor':
|
|
35
|
+
return [field('password', 'signIn.passwordLabel', 'password')];
|
|
36
|
+
case 'collect_second_factor':
|
|
37
|
+
return [field('code', 'mfa.codeLabel')];
|
|
38
|
+
case 'enroll_second_factor':
|
|
39
|
+
/**
|
|
40
|
+
* Two codes, not one. §5.6 wants consecutive codes so a phone with a
|
|
41
|
+
* fast clock fails here rather than on every sign-in afterwards, and
|
|
42
|
+
* asking for one would hide that failure until it was expensive.
|
|
43
|
+
*/
|
|
44
|
+
return [
|
|
45
|
+
field('code', 'mfa.enrollFirstCodeLabel'),
|
|
46
|
+
field('secondCode', 'mfa.enrollSecondCodeLabel'),
|
|
47
|
+
];
|
|
48
|
+
case 'collect_email_code':
|
|
49
|
+
return [field('code', 'signIn.emailCodeLabel')];
|
|
50
|
+
case 'collect_new_password':
|
|
51
|
+
return [field('password', 'reset.newPasswordLabel', 'password')];
|
|
52
|
+
case 'await_oauth':
|
|
53
|
+
return [(0, jsx_runtime_1.jsx)("p", { children: t('signIn.magicLinkSent') }, "oauth")];
|
|
54
|
+
case 'done':
|
|
55
|
+
return [(0, jsx_runtime_1.jsx)("p", { children: t('signIn.checkOtherTab') }, "done")];
|
|
56
|
+
case 'restart':
|
|
57
|
+
return [(0, jsx_runtime_1.jsx)("p", { children: t('error.generic') }, "restart")];
|
|
58
|
+
default:
|
|
59
|
+
/**
|
|
60
|
+
* A status this SDK version does not know. Saying so beats rendering
|
|
61
|
+
* nothing, which is a blank login box the user cannot act on.
|
|
62
|
+
*/
|
|
63
|
+
return [
|
|
64
|
+
(0, jsx_runtime_1.jsx)("p", { className: errorClass, children: t('error.generic') }, "unknown"),
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: cardClass, children: [hideTitle ? null : (0, jsx_runtime_1.jsx)("h1", { className: titleClass, children: t(titleKey) }), errors
|
|
69
|
+
.filter((error) => !error.param)
|
|
70
|
+
.map((error) => ((0, jsx_runtime_1.jsx)("p", { className: errorClass, role: "alert", children: error.message }, error.code))), (0, jsx_runtime_1.jsxs)("form", { onSubmit: (event) => {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
onSubmit(values);
|
|
73
|
+
}, children: [fields(), step.kind !== 'done' && step.kind !== 'await_oauth' ? ((0, jsx_runtime_1.jsx)("button", { className: buttonClass, disabled: busy, type: "submit", children: t('signIn.submit') })) : null] })] }));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Drives the flow through `advance`, which owns the step-to-endpoint mapping.
|
|
77
|
+
* This component never decides what comes next — it renders the status the
|
|
78
|
+
* server returned and posts whatever the driver says the current step needs.
|
|
79
|
+
*/
|
|
80
|
+
function useFlow() {
|
|
81
|
+
const { publishableKey, frontendApi, reload, pendingAttempt } = (0, AtlasProvider_1.useAtlas)();
|
|
82
|
+
// Seeded from a redirect that came back mid-flow (e.g. OAuth needing a second
|
|
83
|
+
// factor), so the user resumes at the demanded step instead of starting over.
|
|
84
|
+
const [state, setState] = (0, react_1.useState)(() => (0, fapi_1.flowFromPending)(pendingAttempt));
|
|
85
|
+
const client = (0, react_1.useMemo)(() => new fapi_1.FapiClient({ publishableKey, baseUrl: frontendApi }), [frontendApi, publishableKey]);
|
|
86
|
+
// Apply a driver result to the UI, and — on completion — exchange the one-time
|
|
87
|
+
// ticket (§7.1) for cookies over a same-origin request (FAPI is cross-origin
|
|
88
|
+
// to the app and cannot set the cookie on the completion response itself),
|
|
89
|
+
// THEN re-boot so the rest of the app sees a signed-in user. Shared by the
|
|
90
|
+
// password/flow `submit` and the native (Google) button, so both complete a
|
|
91
|
+
// sign-in identically.
|
|
92
|
+
const finish = (0, react_1.useCallback)(async (next) => {
|
|
93
|
+
setState(next);
|
|
94
|
+
if (next.attempt?.status === 'complete') {
|
|
95
|
+
if (next.ticket) {
|
|
96
|
+
await client.post('/v1/client/tickets/exchange', {
|
|
97
|
+
attempt_id: next.attempt.id,
|
|
98
|
+
ticket: next.ticket,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
await reload();
|
|
102
|
+
}
|
|
103
|
+
}, [client, reload]);
|
|
104
|
+
const submit = (0, react_1.useCallback)((values) => {
|
|
105
|
+
void (async () => {
|
|
106
|
+
setState((current) => ({ ...current, busy: true, errors: [] }));
|
|
107
|
+
const next = await (0, fapi_1.advance)(client, state, values);
|
|
108
|
+
await finish(next);
|
|
109
|
+
})();
|
|
110
|
+
}, [client, finish, state]);
|
|
111
|
+
/** §5.3: collect a sign-in completed by a link opened on another device. */
|
|
112
|
+
(0, react_1.useEffect)(() => {
|
|
113
|
+
if (!(0, fapi_1.shouldKeepPolling)(state))
|
|
114
|
+
return;
|
|
115
|
+
const timer = setInterval(() => {
|
|
116
|
+
void (async () => {
|
|
117
|
+
const { state: next, ticket } = await (0, fapi_1.pollAttempt)(client, state);
|
|
118
|
+
setState(next);
|
|
119
|
+
if (!ticket || !next.attempt)
|
|
120
|
+
return;
|
|
121
|
+
// The ticket is exchanged by a normal request, so no session token has
|
|
122
|
+
// ever appeared in a URL.
|
|
123
|
+
await client.post('/v1/client/tickets/exchange', {
|
|
124
|
+
attempt_id: next.attempt.id,
|
|
125
|
+
ticket,
|
|
126
|
+
});
|
|
127
|
+
await reload();
|
|
128
|
+
})();
|
|
129
|
+
}, 2_000);
|
|
130
|
+
return () => clearInterval(timer);
|
|
131
|
+
}, [client, reload, state]);
|
|
132
|
+
return { state, submit, client, finish };
|
|
133
|
+
}
|
|
134
|
+
/** Google's multi-color "G" mark — trusted, static, first-party SVG. */
|
|
135
|
+
function GoogleMark() {
|
|
136
|
+
return ((0, jsx_runtime_1.jsxs)("svg", { className: "atlas-social-icon", width: "18", height: "18", viewBox: "0 0 24 24", "aria-hidden": "true", focusable: "false", children: [(0, jsx_runtime_1.jsx)("path", { fill: "#4285F4", d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" }), (0, jsx_runtime_1.jsx)("path", { fill: "#34A853", d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" }), (0, jsx_runtime_1.jsx)("path", { fill: "#FBBC05", d: "M5.84 14.1c-.22-.66-.35-1.36-.35-2.1s.13-1.44.35-2.1V7.06H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.94l3.66-2.84z" }), (0, jsx_runtime_1.jsx)("path", { fill: "#EA4335", d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.06l3.66 2.84C6.71 7.31 9.14 5.38 12 5.38z" })] }));
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* §6 the native "Sign in with Google" button (GSI id_token flow — no secret, no
|
|
140
|
+
* redirect). Discovers whether Google native sign-in is enabled for the instance
|
|
141
|
+
* via `/v1/client/environment`; if so it mints a single-use replay-binding nonce
|
|
142
|
+
* and renders OUR OWN themed button, backed by Google's real (but transparent)
|
|
143
|
+
* GSI button overlaid on top. The user sees a button that inherits the app's
|
|
144
|
+
* appearance (the `socialButton` element key / `atlas-social-button` class, so
|
|
145
|
+
* `appearance.elements.socialButton` and the design tokens theme it like every
|
|
146
|
+
* other control) — NOT Google's fixed, unstyleable button. On a returned
|
|
147
|
+
* credential the id_token is posted to the native endpoint and completes through
|
|
148
|
+
* the shared `finish`. Renders nothing when Google native sign-in isn't enabled.
|
|
149
|
+
*
|
|
150
|
+
* One-Tap stays off unless `oneTap` is set (see {@link FlowProps.googleOneTap}).
|
|
151
|
+
*/
|
|
152
|
+
function GoogleSignInButton({ client, onComplete, oneTap, }) {
|
|
153
|
+
const ref = (0, react_1.useRef)(null);
|
|
154
|
+
const socialButtonClass = (0, components_shared_1.useClass)('socialButton', 'atlas-social-button');
|
|
155
|
+
const [clientId, setClientId] = (0, react_1.useState)(null);
|
|
156
|
+
// Discover the Google client_id (exposed only for native-enabled providers).
|
|
157
|
+
(0, react_1.useEffect)(() => {
|
|
158
|
+
let alive = true;
|
|
159
|
+
void (async () => {
|
|
160
|
+
const res = await client.get('/v1/client/environment');
|
|
161
|
+
const google = res.data?.social_providers?.find((p) => p.provider === 'google' && p.native && p.client_id && p.allow_sign_in !== false);
|
|
162
|
+
if (alive)
|
|
163
|
+
setClientId(google?.client_id ?? null);
|
|
164
|
+
})();
|
|
165
|
+
return () => {
|
|
166
|
+
alive = false;
|
|
167
|
+
};
|
|
168
|
+
}, [client]);
|
|
169
|
+
// Overlay Google's invisible button on our themed one once client_id is known.
|
|
170
|
+
(0, react_1.useEffect)(() => {
|
|
171
|
+
const wrapper = ref.current;
|
|
172
|
+
if (!clientId || !wrapper)
|
|
173
|
+
return;
|
|
174
|
+
let cancelled = false;
|
|
175
|
+
let handle;
|
|
176
|
+
void (async () => {
|
|
177
|
+
const nonce = await (0, js_1.mintNativeNonce)(client, 'google');
|
|
178
|
+
if (cancelled || !nonce || !ref.current)
|
|
179
|
+
return;
|
|
180
|
+
handle = await (0, js_1.renderGoogleOverlayButton)({
|
|
181
|
+
wrapper,
|
|
182
|
+
clientId,
|
|
183
|
+
nonce,
|
|
184
|
+
oneTap: oneTap ?? false,
|
|
185
|
+
onCredential: (idToken) => {
|
|
186
|
+
void (async () => {
|
|
187
|
+
const next = await (0, js_1.nativeSignIn)(client, { provider: 'google', idToken, nonce });
|
|
188
|
+
await onComplete(next);
|
|
189
|
+
})();
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
})();
|
|
193
|
+
return () => {
|
|
194
|
+
cancelled = true;
|
|
195
|
+
handle?.destroy();
|
|
196
|
+
};
|
|
197
|
+
}, [client, clientId, oneTap, onComplete]);
|
|
198
|
+
if (!clientId)
|
|
199
|
+
return null;
|
|
200
|
+
// Our styled button; GSI's transparent real button is overlaid onto this node.
|
|
201
|
+
// Defaults are driven by the appearance design tokens (`--atlas-*` set on
|
|
202
|
+
// `.atlas-root`), so the button matches the app's theme out of the box AND
|
|
203
|
+
// updates when a customer sets `appearance.variables`; `appearance.elements.socialButton`
|
|
204
|
+
// (appended to the class) still layers CSS on top. minHeight matches GSI's
|
|
205
|
+
// own button height so the transparent overlay lines up over the visible one.
|
|
206
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ref: ref, className: socialButtonClass, "data-atlas": "google-signin", "data-atlas-provider": "google", role: "button", tabIndex: 0, style: DEFAULT_SOCIAL_BUTTON_STYLE, children: [(0, jsx_runtime_1.jsx)(GoogleMark, {}), (0, jsx_runtime_1.jsx)("span", { className: "atlas-social-label", children: "Continue with Google" })] }));
|
|
207
|
+
}
|
|
208
|
+
/** Theme-token defaults so the social button looks right with no customer CSS. */
|
|
209
|
+
const DEFAULT_SOCIAL_BUTTON_STYLE = {
|
|
210
|
+
display: 'flex',
|
|
211
|
+
alignItems: 'center',
|
|
212
|
+
justifyContent: 'center',
|
|
213
|
+
gap: '8px',
|
|
214
|
+
width: '100%',
|
|
215
|
+
boxSizing: 'border-box',
|
|
216
|
+
minHeight: '40px',
|
|
217
|
+
padding: '10px 16px',
|
|
218
|
+
border: '1px solid var(--atlas-color-border, #e4e4e9)',
|
|
219
|
+
borderRadius: 'var(--atlas-border-radius, 8px)',
|
|
220
|
+
background: 'var(--atlas-color-background, #ffffff)',
|
|
221
|
+
color: 'var(--atlas-color-text, #1c1c1f)',
|
|
222
|
+
fontFamily: 'var(--atlas-font-family, inherit)',
|
|
223
|
+
fontWeight: 500,
|
|
224
|
+
cursor: 'pointer',
|
|
225
|
+
userSelect: 'none',
|
|
226
|
+
};
|
|
227
|
+
/** Human label for a provider key, for the redirect button text. */
|
|
228
|
+
const PROVIDER_LABEL = {
|
|
229
|
+
github: 'GitHub',
|
|
230
|
+
gitlab: 'GitLab',
|
|
231
|
+
microsoft: 'Microsoft',
|
|
232
|
+
apple: 'Apple',
|
|
233
|
+
facebook: 'Facebook',
|
|
234
|
+
discord: 'Discord',
|
|
235
|
+
linkedin: 'LinkedIn',
|
|
236
|
+
google: 'Google',
|
|
237
|
+
x: 'X',
|
|
238
|
+
twitter: 'X',
|
|
239
|
+
slack: 'Slack',
|
|
240
|
+
spotify: 'Spotify',
|
|
241
|
+
twitch: 'Twitch',
|
|
242
|
+
notion: 'Notion',
|
|
243
|
+
};
|
|
244
|
+
function providerLabel(p) {
|
|
245
|
+
return PROVIDER_LABEL[p] ?? p.charAt(0).toUpperCase() + p.slice(1).replace(/[_-]/g, ' ');
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* §6 all enabled social sign-in providers, native-first.
|
|
249
|
+
*
|
|
250
|
+
* A provider with an in-page native flow (Google today) renders its secretless
|
|
251
|
+
* button — no redirect, no new tab, no stranded initiating tab. Every OTHER
|
|
252
|
+
* enabled provider (GitHub, Microsoft, Discord, …) renders a redirect button that
|
|
253
|
+
* starts the OAuth flow and returns to THIS page, where `<AtlasProvider>` exchanges
|
|
254
|
+
* the returned ticket for a session. Previously `<SignIn>` rendered only the
|
|
255
|
+
* Google button, so an instance's other social providers never appeared.
|
|
256
|
+
*/
|
|
257
|
+
function SocialSignInButtons({ client, onComplete, oneTap, oauthMode, }) {
|
|
258
|
+
const socialButtonClass = (0, components_shared_1.useClass)('socialButton', 'atlas-social-button');
|
|
259
|
+
const { oauthMode: providerOauthMode } = (0, AtlasProvider_1.useAtlas)();
|
|
260
|
+
const effectiveMode = oauthMode ?? providerOauthMode ?? 'redirect';
|
|
261
|
+
const [redirectProviders, setRedirectProviders] = (0, react_1.useState)([]);
|
|
262
|
+
(0, react_1.useEffect)(() => {
|
|
263
|
+
let alive = true;
|
|
264
|
+
void (async () => {
|
|
265
|
+
const res = await client.get('/v1/client/environment');
|
|
266
|
+
const list = (res.data?.social_providers ?? [])
|
|
267
|
+
.filter((p) => p.allow_sign_in !== false)
|
|
268
|
+
// Google renders as the native GSI button below. Any other native provider
|
|
269
|
+
// gets its own in-page button in a later pass; the rest use redirect.
|
|
270
|
+
.filter((p) => p.provider !== 'google')
|
|
271
|
+
.map((p) => p.provider);
|
|
272
|
+
if (alive)
|
|
273
|
+
setRedirectProviders(list);
|
|
274
|
+
})();
|
|
275
|
+
return () => {
|
|
276
|
+
alive = false;
|
|
277
|
+
};
|
|
278
|
+
}, [client]);
|
|
279
|
+
const startSocial = (0, react_1.useCallback)((provider) => {
|
|
280
|
+
void (async () => {
|
|
281
|
+
if (typeof window === 'undefined')
|
|
282
|
+
return;
|
|
283
|
+
const redirectUrl = window.location.href;
|
|
284
|
+
if (effectiveMode === 'popup') {
|
|
285
|
+
const out = await (0, js_1.startOauthPopup)(client, { provider, redirectUrl });
|
|
286
|
+
// Popup blocked → fall back to a full redirect (always safe to enable).
|
|
287
|
+
if (out.blocked && out.authorizationUrl) {
|
|
288
|
+
window.location.href = out.authorizationUrl;
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
// Completed in the popup → drive the SAME completion path as the native
|
|
292
|
+
// (Google) button: exchange the one-time ticket + re-boot signed-in.
|
|
293
|
+
if (out.ticket) {
|
|
294
|
+
await onComplete({
|
|
295
|
+
attempt: { id: out.attemptId, status: 'complete' },
|
|
296
|
+
ticket: out.ticket,
|
|
297
|
+
});
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
// 2FA / connect / provider error → hand off to the redirect continuation
|
|
301
|
+
// so the existing status handling takes over in the opener.
|
|
302
|
+
if (out.continuationUrl) {
|
|
303
|
+
window.location.href = out.continuationUrl;
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
// popup_closed / start_failed → the user cancelled; nothing to do.
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const res = await (0, js_1.startOauthRedirect)(client, { provider, redirectUrl });
|
|
310
|
+
if (res)
|
|
311
|
+
window.location.href = res.authorizationUrl;
|
|
312
|
+
})();
|
|
313
|
+
}, [client, effectiveMode, onComplete]);
|
|
314
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(GoogleSignInButton, { client: client, onComplete: onComplete, oneTap: oneTap }), redirectProviders.map((provider) => ((0, jsx_runtime_1.jsx)("div", { className: socialButtonClass, "data-atlas": "social-signin", "data-atlas-provider": provider, role: "button", tabIndex: 0, style: DEFAULT_SOCIAL_BUTTON_STYLE, onClick: () => startSocial(provider), onKeyDown: (e) => {
|
|
315
|
+
if (e.key === 'Enter' || e.key === ' ')
|
|
316
|
+
startSocial(provider);
|
|
317
|
+
}, children: (0, jsx_runtime_1.jsxs)("span", { className: "atlas-social-label", children: ["Continue with ", providerLabel(provider)] }) }, provider)))] }));
|
|
318
|
+
}
|
|
319
|
+
//# sourceMappingURL=flow.js.map
|
package/dist/flow.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.js","sourceRoot":"","sources":["../src/flow.tsx"],"names":[],"mappings":";;AA2EA,kCAgHC;AAOD,0BAoEC;AAwLD,kDAgGC;;AA9hBD,iCAOe;AACf,sCASuB;AACvB,mDAA2C;AAC3C,iCAOgB;AAChB,2DAAwD;AA0CxD;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,EAC1B,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,SAAS,GAQV;IACC,MAAM,CAAC,GAAG,IAAA,2BAAO,GAAE,CAAC;IACpB,MAAM,SAAS,GAAG,IAAA,4BAAQ,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,IAAA,4BAAQ,EAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAG,IAAA,4BAAQ,EAAC,gBAAgB,EAAE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yBACL,QAAQ,EAC7B,IAAI,EAAC,QAAQ,EACb,QAAQ,EAAE,CAAC,EACX,KAAK,EAAE,2BAA2B,EAClC,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,EACpC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE;oBACf,IAAI,CAAC,CAAC,GAAG,KAAK,OAAO,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG;wBAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;gBAChE,CAAC,YAED,kCAAM,SAAS,EAAC,oBAAoB,+BAAgB,aAAa,CAAC,QAAQ,CAAC,IAAQ,IAZ9E,QAAQ,CAaT,CACP,CAAC,IACD,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useOrganization } from './hooks';
|
|
2
|
+
export declare function OrganizationSwitcher(): import("react").JSX.Element;
|
|
3
|
+
/**
|
|
4
|
+
* Clerk-parity `useOrganizationList()`. The memberships the signed-in user
|
|
5
|
+
* belongs to, plus a `createOrganization(name)` that creates one through FAPI and
|
|
6
|
+
* re-boots the provider so the new membership appears everywhere. `memberships`
|
|
7
|
+
* comes straight from {@link useOrganization} (the same list `<OrganizationSwitcher>`
|
|
8
|
+
* renders), so there is one source of truth for what the user belongs to.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useOrganizationList(): {
|
|
11
|
+
memberships: ReturnType<typeof useOrganization>['memberships'];
|
|
12
|
+
createOrganization(name: string): Promise<{
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
} | null>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Clerk-parity `<CreateOrganization>`. A small name-and-submit form that creates
|
|
19
|
+
* an organization via {@link useOrganizationList} and immediately makes it the
|
|
20
|
+
* active org, so the user drops straight into the org they just made. Styled like
|
|
21
|
+
* the `<SignUp>` card. `onCreate` fires with the created org for a caller that
|
|
22
|
+
* wants to route afterwards.
|
|
23
|
+
*/
|
|
24
|
+
export declare function CreateOrganization({ onCreate, }?: {
|
|
25
|
+
onCreate?(organization: {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
}): void;
|
|
29
|
+
}): import("react").JSX.Element;
|
|
30
|
+
/**
|
|
31
|
+
* Clerk-parity `<OrganizationList>`. Every organization the user belongs to as a
|
|
32
|
+
* button that switches to it (mirroring `<OrganizationSwitcher>`'s markup), plus
|
|
33
|
+
* an inline `<CreateOrganization>` so a user with no orgs — or who wants another —
|
|
34
|
+
* can make one without leaving the list.
|
|
35
|
+
*/
|
|
36
|
+
export declare function OrganizationList(): import("react").JSX.Element;
|
|
37
|
+
export declare function OrganizationProfile(): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OrganizationSwitcher = OrganizationSwitcher;
|
|
4
|
+
exports.useOrganizationList = useOrganizationList;
|
|
5
|
+
exports.CreateOrganization = CreateOrganization;
|
|
6
|
+
exports.OrganizationList = OrganizationList;
|
|
7
|
+
exports.OrganizationProfile = OrganizationProfile;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const AtlasProvider_1 = require("./AtlasProvider");
|
|
11
|
+
const hooks_1 = require("./hooks");
|
|
12
|
+
const components_shared_1 = require("./components-shared");
|
|
13
|
+
const control_components_1 = require("./control-components");
|
|
14
|
+
function OrganizationSwitcher() {
|
|
15
|
+
const { memberships, organization, setActive } = (0, hooks_1.useOrganization)();
|
|
16
|
+
const t = (0, components_shared_1.useText)();
|
|
17
|
+
const menuClass = (0, components_shared_1.useClass)('menu', 'atlas-menu');
|
|
18
|
+
const itemClass = (0, components_shared_1.useClass)('menuItem', 'atlas-menu-item');
|
|
19
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: menuClass, children: [(0, jsx_runtime_1.jsx)("button", { className: itemClass, onClick: () => void setActive(null), children: t('organization.personal') }), memberships.map((membership) => ((0, jsx_runtime_1.jsx)("button", { className: itemClass, disabled: membership.organization.id === organization?.id, onClick: () => void setActive(membership.organization.id), children: membership.organization.name }, membership.organization.id)))] }));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Clerk-parity `useOrganizationList()`. The memberships the signed-in user
|
|
23
|
+
* belongs to, plus a `createOrganization(name)` that creates one through FAPI and
|
|
24
|
+
* re-boots the provider so the new membership appears everywhere. `memberships`
|
|
25
|
+
* comes straight from {@link useOrganization} (the same list `<OrganizationSwitcher>`
|
|
26
|
+
* renders), so there is one source of truth for what the user belongs to.
|
|
27
|
+
*/
|
|
28
|
+
function useOrganizationList() {
|
|
29
|
+
const { memberships } = (0, hooks_1.useOrganization)();
|
|
30
|
+
const { reload } = (0, AtlasProvider_1.useAtlas)();
|
|
31
|
+
const client = (0, components_shared_1.useMeClient)();
|
|
32
|
+
const createOrganization = (0, react_1.useCallback)(async (name) => {
|
|
33
|
+
const res = await client.post('/v1/client/organizations', {
|
|
34
|
+
name,
|
|
35
|
+
});
|
|
36
|
+
// Re-boot so the new membership lands in `memberships` for the whole app,
|
|
37
|
+
// not just this hook's caller.
|
|
38
|
+
await reload();
|
|
39
|
+
return res.data;
|
|
40
|
+
}, [client, reload]);
|
|
41
|
+
return { memberships, createOrganization };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Clerk-parity `<CreateOrganization>`. A small name-and-submit form that creates
|
|
45
|
+
* an organization via {@link useOrganizationList} and immediately makes it the
|
|
46
|
+
* active org, so the user drops straight into the org they just made. Styled like
|
|
47
|
+
* the `<SignUp>` card. `onCreate` fires with the created org for a caller that
|
|
48
|
+
* wants to route afterwards.
|
|
49
|
+
*/
|
|
50
|
+
function CreateOrganization({ onCreate, } = {}) {
|
|
51
|
+
const { createOrganization } = useOrganizationList();
|
|
52
|
+
const { setActive } = (0, hooks_1.useOrganization)();
|
|
53
|
+
const t = (0, components_shared_1.useText)();
|
|
54
|
+
const cardClass = (0, components_shared_1.useClass)('card', 'atlas-card');
|
|
55
|
+
const titleClass = (0, components_shared_1.useClass)('headerTitle', 'atlas-title');
|
|
56
|
+
const inputClass = (0, components_shared_1.useClass)('formFieldInput', 'atlas-input');
|
|
57
|
+
const buttonClass = (0, components_shared_1.useClass)('formButtonPrimary', 'atlas-button');
|
|
58
|
+
const errorClass = (0, components_shared_1.useClass)('formFieldError', 'atlas-error');
|
|
59
|
+
const [name, setName] = (0, react_1.useState)('');
|
|
60
|
+
const [busy, setBusy] = (0, react_1.useState)(false);
|
|
61
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
62
|
+
const submit = async () => {
|
|
63
|
+
const trimmed = name.trim();
|
|
64
|
+
if (!trimmed)
|
|
65
|
+
return;
|
|
66
|
+
setBusy(true);
|
|
67
|
+
setError(null);
|
|
68
|
+
try {
|
|
69
|
+
const org = await createOrganization(trimmed);
|
|
70
|
+
if (!org) {
|
|
71
|
+
setError(t('error.generic'));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await setActive(org.id);
|
|
75
|
+
setName('');
|
|
76
|
+
onCreate?.(org);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
setError(t('error.generic'));
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
setBusy(false);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return ((0, jsx_runtime_1.jsxs)("form", { className: cardClass, "data-atlas": "create-organization", onSubmit: (event) => {
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
void submit();
|
|
88
|
+
}, children: [(0, jsx_runtime_1.jsx)("h2", { className: titleClass, children: t('organization.createTitle') }), (0, jsx_runtime_1.jsxs)("label", { className: "atlas-field", children: [(0, jsx_runtime_1.jsx)("span", { children: t('organization.nameLabel') }), (0, jsx_runtime_1.jsx)("input", { className: inputClass, value: name, onChange: (event) => setName(event.target.value) })] }), error ? ((0, jsx_runtime_1.jsx)("p", { className: errorClass, role: "alert", children: error })) : null, (0, jsx_runtime_1.jsx)("button", { className: buttonClass, type: "submit", disabled: busy || !name.trim(), children: t('organization.create') })] }));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Clerk-parity `<OrganizationList>`. Every organization the user belongs to as a
|
|
92
|
+
* button that switches to it (mirroring `<OrganizationSwitcher>`'s markup), plus
|
|
93
|
+
* an inline `<CreateOrganization>` so a user with no orgs — or who wants another —
|
|
94
|
+
* can make one without leaving the list.
|
|
95
|
+
*/
|
|
96
|
+
function OrganizationList() {
|
|
97
|
+
const { memberships, organization, setActive } = (0, hooks_1.useOrganization)();
|
|
98
|
+
const t = (0, components_shared_1.useText)();
|
|
99
|
+
const menuClass = (0, components_shared_1.useClass)('menu', 'atlas-menu');
|
|
100
|
+
const itemClass = (0, components_shared_1.useClass)('menuItem', 'atlas-menu-item');
|
|
101
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: menuClass, "data-atlas": "organization-list", children: [memberships.map((membership) => ((0, jsx_runtime_1.jsx)("button", { className: itemClass, disabled: membership.organization.id === organization?.id, onClick: () => void setActive(membership.organization.id), children: membership.organization.name }, membership.organization.id))), (0, jsx_runtime_1.jsx)("span", { className: itemClass, "data-atlas": "organization-list-divider", children: t('organization.orCreate') }), (0, jsx_runtime_1.jsx)(CreateOrganization, {})] }));
|
|
102
|
+
}
|
|
103
|
+
function OrganizationProfile() {
|
|
104
|
+
const { organization, membership } = (0, hooks_1.useOrganization)();
|
|
105
|
+
const t = (0, components_shared_1.useText)();
|
|
106
|
+
const cardClass = (0, components_shared_1.useClass)('card', 'atlas-card');
|
|
107
|
+
if (!organization)
|
|
108
|
+
return null;
|
|
109
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: cardClass, children: [(0, jsx_runtime_1.jsx)("h1", { children: organization.name }), (0, jsx_runtime_1.jsxs)("p", { children: [t('organization.roleLabel'), ": ", membership?.role] }), (0, jsx_runtime_1.jsx)(control_components_1.Protect, { permission: "org:sys_memberships:manage", children: (0, jsx_runtime_1.jsx)("button", { children: t('organization.invite') }) })] }));
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=organization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organization.js","sourceRoot":"","sources":["../src/organization.tsx"],"names":[],"mappings":";;AAMA,oDAuBC;AASD,kDAsBC;AASD,gDA+DC;AAQD,4CAwBC;AAED,kDAoBC;;AA1LD,iCAA8C;AAC9C,mDAA2C;AAC3C,mCAA0C;AAC1C,2DAAqE;AACrE,6DAA+C;AAE/C,SAAgB,oBAAoB;IAClC,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,IAAA,uBAAe,GAAE,CAAC;IACnE,MAAM,CAAC,GAAG,IAAA,2BAAO,GAAE,CAAC;IACpB,MAAM,SAAS,GAAG,IAAA,4BAAQ,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,MAAM,SAAS,GAAG,IAAA,4BAAQ,EAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IAE1D,OAAO,CACL,iCAAK,SAAS,EAAE,SAAS,aACvB,mCAAQ,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,SAAS,CAAC,IAAI,CAAC,YAC9D,CAAC,CAAC,uBAAuB,CAAC,GACpB,EACR,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAC/B,mCAEE,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,UAAU,CAAC,YAAY,CAAC,EAAE,KAAK,YAAY,EAAE,EAAE,EACzD,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC,YAExD,UAAU,CAAC,YAAY,CAAC,IAAI,IALxB,UAAU,CAAC,YAAY,CAAC,EAAE,CAMxB,CACV,CAAC,IACE,CACP,CAAC;AACJ,CAAC;AAED;;;;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Y,CAAC,EAAE,CAMxB,CACV,CAAC,EACF,iCAAM,SAAS,EAAE,SAAS,gBAAa,2BAA2B,YAC/D,CAAC,CAAC,uBAAuB,CAAC,GACtB,EACP,uBAAC,kBAAkB,KAAG,IAClB,CACP,CAAC;AACJ,CAAC;AAED,SAAgB,mBAAmB;IACjC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,IAAA,uBAAe,GAAE,CAAC;IACvD,MAAM,CAAC,GAAG,IAAA,2BAAO,GAAE,CAAC;IACpB,MAAM,SAAS,GAAG,IAAA,4BAAQ,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAEjD,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAE/B,OAAO,CACL,iCAAK,SAAS,EAAE,SAAS,aACvB,yCAAK,YAAY,CAAC,IAAI,GAAM,EAC5B,0CACG,CAAC,CAAC,wBAAwB,CAAC,QAAI,UAAU,EAAE,IAAI,IAC9C,EAGJ,uBAAC,4BAAO,IAAC,UAAU,EAAC,4BAA4B,YAC9C,6CAAS,CAAC,CAAC,qBAAqB,CAAC,GAAU,GACnC,IACN,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ReauthInput } from '@atlasauth/js';
|
|
2
|
+
/**
|
|
3
|
+
* Clerk-parity `useReverification()`. A thin, headless wrapper over the EXISTING
|
|
4
|
+
* step-up path (`@atlasauth/js`'s {@link reauthenticate} → `POST /v1/client/me/reauthenticate`)
|
|
5
|
+
* — it invents no server endpoint.
|
|
6
|
+
*
|
|
7
|
+
* Wrap a security-sensitive action with `withReverification(action)`. It runs the
|
|
8
|
+
* action; if that throws or returns a `STEP_UP_REQUIRED` (reauthentication-required)
|
|
9
|
+
* signal, it flips `needsReverification` true and parks the call. The caller renders
|
|
10
|
+
* its own prompt, gathers a credential, and calls `completeReverification(input)`,
|
|
11
|
+
* which re-authenticates in place and retries the action ONCE — resolving the
|
|
12
|
+
* original `withReverification` promise with the retry's result. `cancelReverification`
|
|
13
|
+
* abandons the parked call. A wrong password throws out of `completeReverification`
|
|
14
|
+
* with the parked call intact, so the prompt can let the user try again.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useReverification(): {
|
|
17
|
+
withReverification<T>(action: () => T | Promise<T>): Promise<T>;
|
|
18
|
+
needsReverification: boolean;
|
|
19
|
+
completeReverification(input: ReauthInput): Promise<void>;
|
|
20
|
+
cancelReverification(): void;
|
|
21
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useReverification = useReverification;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const js_1 = require("@atlasauth/js");
|
|
6
|
+
const AtlasProvider_1 = require("./AtlasProvider");
|
|
7
|
+
/**
|
|
8
|
+
* Clerk-parity `useReverification()`. A thin, headless wrapper over the EXISTING
|
|
9
|
+
* step-up path (`@atlasauth/js`'s {@link reauthenticate} → `POST /v1/client/me/reauthenticate`)
|
|
10
|
+
* — it invents no server endpoint.
|
|
11
|
+
*
|
|
12
|
+
* Wrap a security-sensitive action with `withReverification(action)`. It runs the
|
|
13
|
+
* action; if that throws or returns a `STEP_UP_REQUIRED` (reauthentication-required)
|
|
14
|
+
* signal, it flips `needsReverification` true and parks the call. The caller renders
|
|
15
|
+
* its own prompt, gathers a credential, and calls `completeReverification(input)`,
|
|
16
|
+
* which re-authenticates in place and retries the action ONCE — resolving the
|
|
17
|
+
* original `withReverification` promise with the retry's result. `cancelReverification`
|
|
18
|
+
* abandons the parked call. A wrong password throws out of `completeReverification`
|
|
19
|
+
* with the parked call intact, so the prompt can let the user try again.
|
|
20
|
+
*/
|
|
21
|
+
function useReverification() {
|
|
22
|
+
const { publishableKey, frontendApi } = (0, AtlasProvider_1.useAtlas)();
|
|
23
|
+
const [needsReverification, setNeedsReverification] = (0, react_1.useState)(false);
|
|
24
|
+
const pending = (0, react_1.useRef)(null);
|
|
25
|
+
// A STEP_UP_REQUIRED signal, whether it arrived as a thrown Error carrying a
|
|
26
|
+
// `.code`, or as a returned FapiClient response whose `errors[]` names it.
|
|
27
|
+
const isStepUp = (candidate) => {
|
|
28
|
+
if (!candidate || typeof candidate !== 'object')
|
|
29
|
+
return false;
|
|
30
|
+
if (candidate.code === 'STEP_UP_REQUIRED')
|
|
31
|
+
return true;
|
|
32
|
+
const errors = candidate.errors;
|
|
33
|
+
return Array.isArray(errors) && errors.some((error) => error?.code === 'STEP_UP_REQUIRED');
|
|
34
|
+
};
|
|
35
|
+
const park = (action) => new Promise((resolve, reject) => {
|
|
36
|
+
pending.current = { action, resolve: resolve, reject };
|
|
37
|
+
setNeedsReverification(true);
|
|
38
|
+
});
|
|
39
|
+
const withReverification = (0, react_1.useCallback)(async (action) => {
|
|
40
|
+
try {
|
|
41
|
+
const result = await action();
|
|
42
|
+
return isStepUp(result) ? await park(action) : result;
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
if (isStepUp(err))
|
|
46
|
+
return await park(action);
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
}, []);
|
|
50
|
+
const completeReverification = (0, react_1.useCallback)(async (input) => {
|
|
51
|
+
// Throws on a bad credential; the parked call is left intact so the prompt
|
|
52
|
+
// can retry, and we neither clear it nor drop the flag until this resolves.
|
|
53
|
+
await (0, js_1.reauthenticate)(input, { api: frontendApi, publishableKey });
|
|
54
|
+
const job = pending.current;
|
|
55
|
+
pending.current = null;
|
|
56
|
+
setNeedsReverification(false);
|
|
57
|
+
if (!job)
|
|
58
|
+
return;
|
|
59
|
+
try {
|
|
60
|
+
job.resolve(await job.action());
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
job.reject(err);
|
|
64
|
+
}
|
|
65
|
+
}, [frontendApi, publishableKey]);
|
|
66
|
+
const cancelReverification = (0, react_1.useCallback)(() => {
|
|
67
|
+
const job = pending.current;
|
|
68
|
+
pending.current = null;
|
|
69
|
+
setNeedsReverification(false);
|
|
70
|
+
job?.reject(new Error('Reverification cancelled.'));
|
|
71
|
+
}, []);
|
|
72
|
+
return { withReverification, needsReverification, completeReverification, cancelReverification };
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=reverification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reverification.js","sourceRoot":"","sources":["../src/reverification.tsx"],"names":[],"mappings":";;AAkBA,8CAoEC;AAtFD,iCAAsD;AACtD,sCAAiE;AACjE,mDAA2C;AAE3C;;;;;;;;;;;;;GAaG;AACH,SAAgB,iBAAiB;IAM/B,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,IAAA,wBAAQ,GAAE,CAAC;IACnD,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IACtE,MAAM,OAAO,GAAG,IAAA,cAAM,EAIZ,IAAI,CAAC,CAAC;IAEhB,6EAA6E;IAC7E,2EAA2E;IAC3E,MAAM,QAAQ,GAAG,CAAC,SAAkB,EAAW,EAAE;QAC/C,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC9D,IAAK,SAA+B,CAAC,IAAI,KAAK,kBAAkB;YAAE,OAAO,IAAI,CAAC;QAC9E,MAAM,MAAM,GAAI,SAAmD,CAAC,MAAM,CAAC;QAC3E,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,kBAAkB,CAAC,CAAC;IAC7F,CAAC,CAAC;IAEF,MAAM,IAAI,GAAG,CAAK,MAA4B,EAAc,EAAE,CAC5D,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACjC,OAAO,CAAC,OAAO,GAAG,EAAE,MAAM,EAAE,OAAO,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