@midsummer-ai/sdk 0.1.0-staging.3778 → 0.1.0-staging.3784
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/auth/contract.mjs +1 -1
- package/auth/index.mjs +1 -1
- package/auth/password.mjs +1 -1
- package/auth/react.d.mts +50 -27
- package/auth/react.mjs +1047 -532
- package/{auth-DBp5FHvK.mjs → auth-BtqjgQ-V.mjs} +411 -122
- package/{client-CIuYlRWZ.mjs → client-CrJkXd5h.mjs} +108 -37
- package/database/client.mjs +1 -1
- package/{engine-o-3LFoL3.mjs → engine-9WBvqNSV.mjs} +15 -21
- package/package.json +1 -1
- package/{qr-Br1sOBmT.mjs → qr-BySxqLW6.mjs} +86 -271
- package/style-CCFT-5rG.mjs +684 -0
package/auth/react.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { t as DATABASE_TOKEN_PATH, u as signedInDatabase } from "../client-
|
|
1
|
+
import { t as DATABASE_TOKEN_PATH, u as signedInDatabase } from "../client-CrJkXd5h.mjs";
|
|
2
2
|
import { DatabaseProvider } from "../database/react.mjs";
|
|
3
|
-
import { a as WORDS, c as deviceOf, i as CAPTCHA_WIDGETS, l as
|
|
3
|
+
import { a as WORDS, c as deviceOf, i as CAPTCHA_WIDGETS, l as screenName, n as textOn, o as ago, t as authCss, u as setupKeyOf } from "../style-CCFT-5rG.mjs";
|
|
4
|
+
import { a as shapeAttributes, r as ICONS, t as qrPath } from "../qr-BySxqLW6.mjs";
|
|
4
5
|
import { AuthClientError, authClient } from "./client.mjs";
|
|
5
6
|
import { Fragment, createContext, createElement, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
6
7
|
//#region src/auth/react.ts
|
|
@@ -9,7 +10,7 @@ import { Fragment, createContext, createElement, useCallback, useContext, useEff
|
|
|
9
10
|
*
|
|
10
11
|
* import { AuthProvider, SignIn, UserButton } from "@midsummer-ai/sdk/auth/react"
|
|
11
12
|
*
|
|
12
|
-
* <AuthProvider>
|
|
13
|
+
* <AuthProvider appearance={{ theme: "auto" }}>
|
|
13
14
|
* <UserButton />
|
|
14
15
|
* <SignIn redirectTo="/dashboard" />
|
|
15
16
|
* </AuthProvider>
|
|
@@ -17,16 +18,23 @@ import { Fragment, createContext, createElement, useCallback, useContext, useEff
|
|
|
17
18
|
* `<SignIn/>`, `<SignUp/>`, `<UserButton/>`, `<UserProfile/>` (profile, password, two-step sign-in, passkeys,
|
|
18
19
|
* sessions, API keys and the apps a person let in), `<OrganizationSwitcher/>` and `<OrganizationProfile/>` (members,
|
|
19
20
|
* roles and invitations). They show only the ways in the app's settings turn on, in the app's name, logo and colour,
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* the same screens for apps that don't use
|
|
23
|
-
* app's database as whoever is signed in, for
|
|
21
|
+
* and look as Midsummer's own sign-in does: its type, fields, buttons and motion, light and dark. `appearance` (or the
|
|
22
|
+
* CSS variables in `./style.ts`) sets the theme, the brand colour, the corners and the font. `useAuth()` gives any
|
|
23
|
+
* component who is signed in. The hosted pages under `/api/auth/ui` are the same screens for apps that don't use
|
|
24
|
+
* React. `<AuthProvider database>` also gives the components inside it the app's database as whoever is signed in, for
|
|
25
|
+
* `useQuery` and the other hooks of `@midsummer-ai/sdk/react`.
|
|
24
26
|
*/
|
|
25
27
|
const Context = createContext(null);
|
|
28
|
+
/** The provider's appearance, and the addresses the app serves at, which a screen's title never shows as its name. */
|
|
29
|
+
const Look = createContext({
|
|
30
|
+
appearance: void 0,
|
|
31
|
+
hosts: []
|
|
32
|
+
});
|
|
26
33
|
/**
|
|
27
|
-
* Gives the screens inside it the client and who is signed in; `baseURL` when the app's server is on another address
|
|
28
|
-
* With `database`, the hooks of `@midsummer-ai/sdk/react` inside it
|
|
29
|
-
* database as whoever is signed in (`signedInDatabase`), and connect again
|
|
34
|
+
* Gives the screens inside it the client and who is signed in; `baseURL` when the app's server is on another address,
|
|
35
|
+
* and `appearance` to match the app's look. With `database`, the hooks of `@midsummer-ai/sdk/react` inside it
|
|
36
|
+
* (`useQuery`, `useMutation`) reach the app's database as whoever is signed in (`signedInDatabase`), and connect again
|
|
37
|
+
* as someone signs in or out.
|
|
30
38
|
*/
|
|
31
39
|
function AuthProvider(props) {
|
|
32
40
|
const client = useMemo(() => props.client ?? authClient(props.baseURL ? { baseURL: props.baseURL } : {}), [props.client, props.baseURL]);
|
|
@@ -59,7 +67,14 @@ function AuthProvider(props) {
|
|
|
59
67
|
settings,
|
|
60
68
|
refresh
|
|
61
69
|
]);
|
|
62
|
-
|
|
70
|
+
const here = globalThis.location?.href;
|
|
71
|
+
const hosts = [here ? URL.parse(here)?.hostname : void 0, props.baseURL ? URL.parse(props.baseURL)?.hostname : void 0].filter((one) => Boolean(one));
|
|
72
|
+
const look = useMemo(() => ({
|
|
73
|
+
appearance: props.appearance,
|
|
74
|
+
hosts
|
|
75
|
+
}), [props.appearance, hosts.join(" ")]);
|
|
76
|
+
const css = useMemo(() => authCss(props.baseURL ?? ""), [props.baseURL]);
|
|
77
|
+
return createElement(Context.Provider, { value: state }, createElement(Look.Provider, { value: look }, createElement("style", { "data-msa": "" }, css), db ? createElement(DatabaseProvider, { client: db }, props.children) : props.children));
|
|
63
78
|
}
|
|
64
79
|
/** Who is signed in, the client and the app's settings: inside an `AuthProvider`. */
|
|
65
80
|
function useAuth() {
|
|
@@ -67,15 +82,45 @@ function useAuth() {
|
|
|
67
82
|
if (!state) throw new Error("useAuth and the sign-in screens go inside <AuthProvider>.");
|
|
68
83
|
return state;
|
|
69
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* The attributes of a screen's outer element: the theme, and the brand, corners and font the app and its settings
|
|
87
|
+
* give. A whole screen (`frame`) takes the width it is given; a button or a switcher keeps its own.
|
|
88
|
+
*/
|
|
89
|
+
function useRoot(frame = false) {
|
|
90
|
+
const { settings } = useAuth();
|
|
91
|
+
const { appearance } = useContext(Look);
|
|
92
|
+
const style = {};
|
|
93
|
+
const color = settings?.branding.color;
|
|
94
|
+
if (color) Object.assign(style, {
|
|
95
|
+
"--msa-app-brand": color,
|
|
96
|
+
"--msa-app-brand-text": textOn(color)
|
|
97
|
+
});
|
|
98
|
+
if (appearance?.brand) Object.assign(style, { "--msa-brand": appearance.brand }, /^#[0-9a-f]{6}$/iu.test(appearance.brand) ? { "--msa-brand-text": textOn(appearance.brand) } : {});
|
|
99
|
+
if (appearance?.radius) style["--msa-radius"] = appearance.radius;
|
|
100
|
+
if (appearance?.font) style["--msa-font"] = appearance.font;
|
|
101
|
+
return {
|
|
102
|
+
className: frame ? "msa msa-frame" : "msa",
|
|
103
|
+
...appearance?.theme ? { "data-msa-theme": appearance.theme } : {},
|
|
104
|
+
...Object.keys(style).length ? { style } : {}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** The app's name for a screen's title, or null when it is only the address the app serves at. */
|
|
108
|
+
function useName() {
|
|
109
|
+
const { settings } = useAuth();
|
|
110
|
+
return screenName(settings?.branding.name, useContext(Look).hosts);
|
|
111
|
+
}
|
|
70
112
|
/** Runs one call at a time, keeping whether it is running and the words of its refusal. */
|
|
71
113
|
function useCall() {
|
|
72
114
|
const [busy, setBusy] = useState(false);
|
|
73
115
|
const [error, setError] = useState(null);
|
|
116
|
+
const running = useRef(false);
|
|
74
117
|
return {
|
|
75
118
|
busy,
|
|
76
119
|
error,
|
|
77
120
|
setError,
|
|
78
121
|
run: useCallback(async (work) => {
|
|
122
|
+
if (running.current) return false;
|
|
123
|
+
running.current = true;
|
|
79
124
|
setBusy(true);
|
|
80
125
|
setError(null);
|
|
81
126
|
try {
|
|
@@ -85,55 +130,185 @@ function useCall() {
|
|
|
85
130
|
setError(caught instanceof AuthClientError ? caught.message : caught instanceof DOMException ? WORDS.errors.passkeyCancelled : WORDS.errors.generic);
|
|
86
131
|
return false;
|
|
87
132
|
} finally {
|
|
133
|
+
running.current = false;
|
|
88
134
|
setBusy(false);
|
|
89
135
|
}
|
|
90
136
|
}, [])
|
|
91
137
|
};
|
|
92
138
|
}
|
|
93
|
-
/**
|
|
94
|
-
function
|
|
139
|
+
/** A countdown in seconds, for how long until a code may be sent again. */
|
|
140
|
+
function useCountdown() {
|
|
141
|
+
const [left, setLeft] = useState(0);
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (!left) return;
|
|
144
|
+
const tick = setTimeout(() => setLeft(left - 1), 1e3);
|
|
145
|
+
return () => clearTimeout(tick);
|
|
146
|
+
}, [left]);
|
|
147
|
+
return [left, setLeft];
|
|
148
|
+
}
|
|
149
|
+
/** True for a moment after `show()`, so a button can say it worked ("Saved") and settle back. */
|
|
150
|
+
function useDone() {
|
|
151
|
+
const [done, setDone] = useState(false);
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
if (!done) return;
|
|
154
|
+
const settle = setTimeout(() => setDone(false), 1600);
|
|
155
|
+
return () => clearTimeout(settle);
|
|
156
|
+
}, [done]);
|
|
157
|
+
return [done, () => setDone(true)];
|
|
158
|
+
}
|
|
159
|
+
const classes = (...names) => names.filter(Boolean).join(" ");
|
|
160
|
+
const camel = (name) => name.replace(/-([a-z])/gu, (_, letter) => letter.toUpperCase());
|
|
161
|
+
/** One of the screens' icons, hidden from screen readers: the control it sits in carries the words. */
|
|
162
|
+
function Icon(props) {
|
|
163
|
+
const drawing = ICONS[props.name];
|
|
164
|
+
return createElement("svg", {
|
|
165
|
+
className: "msa-icon",
|
|
166
|
+
"aria-hidden": true,
|
|
167
|
+
focusable: "false",
|
|
168
|
+
viewBox: drawing.viewBox
|
|
169
|
+
}, ...drawing.shapes.map((shape, index) => createElement("path", {
|
|
170
|
+
key: index,
|
|
171
|
+
...Object.fromEntries(Object.entries(shapeAttributes(shape)).map(([key, value]) => [camel(key), value]))
|
|
172
|
+
})));
|
|
173
|
+
}
|
|
174
|
+
/** A person's or an organization's picture, else its first letter. */
|
|
175
|
+
function Avatar(props) {
|
|
176
|
+
return createElement("span", {
|
|
177
|
+
className: "msa-avatar",
|
|
178
|
+
"aria-hidden": true,
|
|
179
|
+
...props.size ? { "data-size": props.size } : {},
|
|
180
|
+
...props.square ? { "data-shape": "square" } : {}
|
|
181
|
+
}, props.image ? createElement("img", {
|
|
182
|
+
src: props.image,
|
|
183
|
+
alt: ""
|
|
184
|
+
}) : props.name.trim().slice(0, 1).toUpperCase());
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The card every sign-in screen sits in: the app's logo, the title and the line under it, then the screen. A new
|
|
188
|
+
* `stage` (the next step of signing in) enters as Midsummer's content does; the first one doesn't animate.
|
|
189
|
+
*/
|
|
190
|
+
function Screen(props) {
|
|
95
191
|
const { settings } = useAuth();
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
192
|
+
const root = useRoot(true);
|
|
193
|
+
const id = useId();
|
|
194
|
+
const first = useRef(props.stage);
|
|
195
|
+
const moved = props.stage !== first.current;
|
|
196
|
+
const logo = settings?.branding.logo;
|
|
197
|
+
return createElement("div", root, createElement("section", {
|
|
198
|
+
className: classes("msa-card", props.appear && "msa-enter"),
|
|
199
|
+
"aria-labelledby": id
|
|
200
|
+
}, createElement("div", {
|
|
201
|
+
key: props.stage ?? "",
|
|
202
|
+
className: moved ? "msa-enter" : void 0
|
|
203
|
+
}, createElement("header", { className: "msa-head" }, logo ? createElement("img", {
|
|
105
204
|
className: "msa-logo",
|
|
106
|
-
src:
|
|
107
|
-
alt: settings
|
|
108
|
-
}) : null, createElement("
|
|
205
|
+
src: logo,
|
|
206
|
+
alt: settings?.branding.name ?? ""
|
|
207
|
+
}) : null, createElement("div", { className: "msa-titles" }, createElement("h1", {
|
|
208
|
+
id,
|
|
209
|
+
className: "msa-title"
|
|
210
|
+
}, props.title), props.lead ? createElement("p", { className: "msa-lead" }, props.lead) : null)), createElement("div", { className: "msa-body" }, props.children))));
|
|
109
211
|
}
|
|
212
|
+
/** The address a sentence is about, set apart so it reads first: on a line of its own, or `inline` in the sentence. */
|
|
213
|
+
const Subject = (props) => createElement("span", { className: classes("msa-subject", props.inline && "msa-inline") }, props.children);
|
|
214
|
+
/** A labelled field; a password one shows and hides what is typed. */
|
|
110
215
|
function Field(props) {
|
|
111
|
-
|
|
112
|
-
|
|
216
|
+
const id = useId();
|
|
217
|
+
const [shown, setShown] = useState(false);
|
|
218
|
+
const secret = props.type === "password";
|
|
219
|
+
const input = createElement("input", {
|
|
220
|
+
id,
|
|
221
|
+
className: "msa-input",
|
|
222
|
+
type: secret && shown ? "text" : props.type ?? "text",
|
|
113
223
|
value: props.value,
|
|
114
224
|
required: props.required ?? true,
|
|
115
225
|
autoComplete: props.autoComplete,
|
|
116
|
-
|
|
226
|
+
placeholder: props.placeholder,
|
|
227
|
+
autoFocus: props.autoFocus,
|
|
228
|
+
minLength: props.minLength,
|
|
229
|
+
...props.type === "email" ? {
|
|
230
|
+
spellCheck: false,
|
|
231
|
+
autoCapitalize: "none"
|
|
232
|
+
} : {},
|
|
117
233
|
onChange: (event) => props.onChange(event.target.value)
|
|
118
|
-
})
|
|
234
|
+
});
|
|
235
|
+
const label = createElement("label", {
|
|
236
|
+
htmlFor: id,
|
|
237
|
+
className: props.quiet ? "msa-sr" : "msa-label"
|
|
238
|
+
}, props.label);
|
|
239
|
+
return createElement("div", { className: "msa-field" }, props.aside ? createElement("div", { className: "msa-label-row" }, label, props.aside) : label, secret ? createElement("div", { className: "msa-secret-field" }, input, createElement("button", {
|
|
240
|
+
type: "button",
|
|
241
|
+
className: "msa-reveal",
|
|
242
|
+
"aria-label": shown ? "Hide password" : "Show password",
|
|
243
|
+
"aria-pressed": shown,
|
|
244
|
+
onClick: () => setShown(!shown)
|
|
245
|
+
}, createElement(Icon, { name: "eye" }), createElement(Icon, { name: "eyeSlash" }))) : input);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The code a person types from their mail or authenticator app, as six boxes like Midsummer's own sign-in: one real
|
|
249
|
+
* field over them, so pasting, autofill from a mail and screen readers all see a single input. The sixth digit sends
|
|
250
|
+
* it at once (`onComplete`).
|
|
251
|
+
*/
|
|
252
|
+
function CodeField(props) {
|
|
253
|
+
const id = useId();
|
|
254
|
+
return createElement("div", { className: "msa-field" }, createElement("label", {
|
|
255
|
+
htmlFor: id,
|
|
256
|
+
className: "msa-sr"
|
|
257
|
+
}, props.label), createElement("div", {
|
|
258
|
+
className: "msa-otp",
|
|
259
|
+
"data-boxes": ""
|
|
260
|
+
}, createElement("input", {
|
|
261
|
+
id,
|
|
262
|
+
className: "msa-input msa-code",
|
|
263
|
+
value: props.value,
|
|
264
|
+
required: true,
|
|
265
|
+
autoComplete: "one-time-code",
|
|
266
|
+
inputMode: "numeric",
|
|
267
|
+
autoFocus: true,
|
|
268
|
+
maxLength: 6,
|
|
269
|
+
spellCheck: false,
|
|
270
|
+
placeholder: WORDS.placeholders.code,
|
|
271
|
+
onChange: (event) => {
|
|
272
|
+
const value = event.target.value.replace(/\D/gu, "").slice(0, 6);
|
|
273
|
+
props.onChange(value);
|
|
274
|
+
if (value.length === 6) props.onComplete?.(value);
|
|
275
|
+
}
|
|
276
|
+
}), createElement("div", {
|
|
277
|
+
className: "msa-otp-boxes",
|
|
278
|
+
"aria-hidden": true
|
|
279
|
+
}, ...Array.from({ length: 6 }, (_, index) => createElement("span", {
|
|
280
|
+
key: index,
|
|
281
|
+
className: "msa-otp-box",
|
|
282
|
+
...index === Math.min(props.value.length, 5) ? { "data-active": "" } : {}
|
|
283
|
+
}, props.value[index] ?? "")))));
|
|
119
284
|
}
|
|
285
|
+
/** Where a refusal is said, under the fields; empty, it takes no room. */
|
|
120
286
|
const Problem = (props) => createElement("p", {
|
|
121
287
|
className: "msa-error",
|
|
122
|
-
role: "alert"
|
|
123
|
-
"aria-live": "assertive"
|
|
288
|
+
role: "alert"
|
|
124
289
|
}, props.message ?? "");
|
|
125
|
-
const Note = (props) => createElement("p", {
|
|
126
|
-
className: "msa-note",
|
|
127
|
-
role: "status"
|
|
128
|
-
}, props.children);
|
|
129
290
|
function Submit(props) {
|
|
130
291
|
return createElement("button", {
|
|
131
292
|
type: "submit",
|
|
132
|
-
className: "msa-primary",
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}, props.label);
|
|
293
|
+
className: "msa-button msa-primary msa-block",
|
|
294
|
+
"aria-busy": props.busy || void 0
|
|
295
|
+
}, props.busy ? WORDS.busy : props.label);
|
|
136
296
|
}
|
|
297
|
+
/** A quiet action in a line of them, such as "Resend code". */
|
|
298
|
+
const LinkButton = (props) => createElement("button", {
|
|
299
|
+
type: "button",
|
|
300
|
+
className: "msa-link",
|
|
301
|
+
disabled: props.disabled,
|
|
302
|
+
onClick: props.onClick
|
|
303
|
+
}, props.children);
|
|
304
|
+
/** Quiet actions on one line, parted by dots. */
|
|
305
|
+
const Links = (props) => {
|
|
306
|
+
const shown = (Array.isArray(props.children) ? props.children : [props.children]).filter(Boolean);
|
|
307
|
+
return createElement("div", { className: "msa-links" }, ...shown.flatMap((one, index) => index ? [createElement("span", {
|
|
308
|
+
key: `dot-${index}`,
|
|
309
|
+
"aria-hidden": true
|
|
310
|
+
}, "·"), createElement(Fragment, { key: index }, one)] : [createElement(Fragment, { key: index }, one)]));
|
|
311
|
+
};
|
|
137
312
|
const onSubmit = (work) => (event) => {
|
|
138
313
|
event.preventDefault();
|
|
139
314
|
work();
|
|
@@ -142,7 +317,7 @@ const onSubmit = (work) => (event) => {
|
|
|
142
317
|
function Captcha(props) {
|
|
143
318
|
const { settings } = useAuth();
|
|
144
319
|
const captcha = settings?.captcha;
|
|
145
|
-
const id = useId().replace(/[^a-zA-Z0-9]/
|
|
320
|
+
const id = useId().replace(/[^a-zA-Z0-9]/gu, "");
|
|
146
321
|
useEffect(() => {
|
|
147
322
|
if (!captcha) return;
|
|
148
323
|
const widget = CAPTCHA_WIDGETS[captcha.provider];
|
|
@@ -165,12 +340,28 @@ function Captcha(props) {
|
|
|
165
340
|
"data-callback": `msaCaptcha${id}`
|
|
166
341
|
});
|
|
167
342
|
}
|
|
168
|
-
/**
|
|
343
|
+
/** Google, GitHub and passkeys side by side over the form, the way in the screen leads with set apart by "or". */
|
|
344
|
+
function Ways(props) {
|
|
345
|
+
if (!props.ways.length) return null;
|
|
346
|
+
const one = props.ways.length === 1;
|
|
347
|
+
return createElement(Fragment, null, createElement("div", {
|
|
348
|
+
className: "msa-ways",
|
|
349
|
+
"data-count": props.ways.length
|
|
350
|
+
}, ...props.ways.map((way) => createElement("button", {
|
|
351
|
+
key: way.label,
|
|
352
|
+
type: "button",
|
|
353
|
+
className: "msa-button msa-secondary",
|
|
354
|
+
...one ? {} : { "aria-label": way.named },
|
|
355
|
+
onClick: way.onClick
|
|
356
|
+
}, createElement(Icon, { name: way.icon }), createElement("span", { className: "msa-way-label" }, one ? way.named : way.label)))), createElement("div", { className: "msa-or" }, WORDS.ways.or));
|
|
357
|
+
}
|
|
358
|
+
/** A secret shown once, on one line, with a Copy button that shows Copied once it has. */
|
|
169
359
|
function Secret(props) {
|
|
170
|
-
const [copied,
|
|
360
|
+
const [copied, copy] = useDone();
|
|
171
361
|
return createElement("div", { className: "msa-secret" }, createElement("code", { "aria-label": props.label }, props.value), createElement("button", {
|
|
172
362
|
type: "button",
|
|
173
|
-
|
|
363
|
+
className: "msa-button msa-secondary msa-small",
|
|
364
|
+
onClick: () => void navigator.clipboard?.writeText(props.value).then(copy, () => {})
|
|
174
365
|
}, copied ? WORDS.account.copied : WORDS.account.copy));
|
|
175
366
|
}
|
|
176
367
|
/** The code an authenticator app scans as two-step sign-in starts. */
|
|
@@ -193,32 +384,22 @@ function QrCode(props) {
|
|
|
193
384
|
fill: "#111111"
|
|
194
385
|
}));
|
|
195
386
|
}
|
|
196
|
-
/** A
|
|
197
|
-
function CopyButton(props) {
|
|
198
|
-
const [copied, setCopied] = useState(false);
|
|
199
|
-
return createElement("div", null, createElement("button", {
|
|
200
|
-
type: "button",
|
|
201
|
-
onClick: () => void navigator.clipboard?.writeText(props.value).then(() => setCopied(true), () => {})
|
|
202
|
-
}, copied ? WORDS.account.copied : props.label));
|
|
203
|
-
}
|
|
204
|
-
/** A destructive action that asks first: its button, then the same words for good, beside Cancel. */
|
|
387
|
+
/** A destructive action that asks first: its button, then the same act named for good, beside Cancel. */
|
|
205
388
|
function Confirm(props) {
|
|
206
389
|
const [asking, setAsking] = useState(false);
|
|
207
390
|
if (!asking) return createElement("button", {
|
|
208
391
|
type: "button",
|
|
209
|
-
className: "msa-
|
|
392
|
+
className: "msa-button msa-ghost msa-small",
|
|
210
393
|
onClick: () => setAsking(true)
|
|
211
394
|
}, props.label);
|
|
212
|
-
return createElement("
|
|
213
|
-
display: "flex",
|
|
214
|
-
gap: 8
|
|
215
|
-
} }, createElement("button", {
|
|
395
|
+
return createElement(Fragment, null, createElement("button", {
|
|
216
396
|
type: "button",
|
|
217
|
-
className: "msa-
|
|
397
|
+
className: "msa-button msa-ghost msa-small",
|
|
218
398
|
onClick: () => setAsking(false)
|
|
219
399
|
}, WORDS.account.cancel), createElement("button", {
|
|
220
400
|
type: "button",
|
|
221
|
-
className: "msa-danger",
|
|
401
|
+
className: "msa-button msa-danger msa-small",
|
|
402
|
+
autoFocus: true,
|
|
222
403
|
disabled: props.busy,
|
|
223
404
|
onClick: () => {
|
|
224
405
|
setAsking(false);
|
|
@@ -230,252 +411,334 @@ function Confirm(props) {
|
|
|
230
411
|
const go = (to) => {
|
|
231
412
|
globalThis.location.href = to;
|
|
232
413
|
};
|
|
414
|
+
/** A bone the size of what will take its place, while the settings load. */
|
|
415
|
+
const bone = (width, className = "msa-bone") => createElement("span", {
|
|
416
|
+
className,
|
|
417
|
+
style: { width }
|
|
418
|
+
});
|
|
233
419
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* load shows none.
|
|
420
|
+
* A screen while the app's settings load: its title, its fields, button and link as bones the size of each, so the form
|
|
421
|
+
* takes their place without anything moving. It shows only after a moment, so a quick load shows none.
|
|
237
422
|
*/
|
|
238
|
-
function
|
|
239
|
-
const
|
|
240
|
-
className,
|
|
241
|
-
style: { width }
|
|
242
|
-
});
|
|
423
|
+
function Loading(props) {
|
|
424
|
+
const root = useRoot(true);
|
|
243
425
|
return createElement("div", {
|
|
244
|
-
|
|
426
|
+
...root,
|
|
245
427
|
role: "status",
|
|
246
428
|
"aria-busy": true,
|
|
247
|
-
"aria-label":
|
|
248
|
-
}, createElement("div", { className: "msa-card msa-loading" }, createElement("
|
|
429
|
+
"aria-label": props.label
|
|
430
|
+
}, createElement("div", { className: "msa-card msa-loading" }, createElement("div", { className: "msa-head" }, createElement("div", { className: "msa-titles" }, createElement("h1", { className: "msa-title" }, bone(props.title)))), createElement("div", { className: "msa-body" }, createElement("div", { className: "msa-form" }, ...Array.from({ length: props.fields }, (_, index) => createElement("div", {
|
|
431
|
+
key: index,
|
|
432
|
+
className: "msa-field"
|
|
433
|
+
}, createElement("span", { className: "msa-label" }, bone("30%")), bone("100%", "msa-bone msa-bone-control"))), bone("100%", "msa-bone msa-bone-control")), createElement("p", { className: "msa-foot" }, bone(props.foot, "msa-bone msa-bone-inline")))));
|
|
249
434
|
}
|
|
250
|
-
/**
|
|
435
|
+
/**
|
|
436
|
+
* Sign-in: a password, a code or a link by mail, a passkey, Google or GitHub, as the app's settings turn them on, with
|
|
437
|
+
* one way leading and the rest quiet. `initialStep` and `initialEmail` open it part way, such as on the code step.
|
|
438
|
+
*/
|
|
251
439
|
function SignIn(props) {
|
|
252
440
|
const { client, settings } = useAuth();
|
|
253
|
-
const
|
|
254
|
-
const [
|
|
441
|
+
const name = useName();
|
|
442
|
+
const [step, setStep] = useState(props.initialStep ?? "start");
|
|
443
|
+
const [email, setEmail] = useState(props.initialEmail ?? ""), [password, setPassword] = useState(""), [code, setCode] = useState(""), [captcha, setCaptcha] = useState("");
|
|
444
|
+
const [wait, setWait] = useCountdown();
|
|
255
445
|
const call = useCall();
|
|
256
446
|
const done = () => go(props.redirectTo ?? "/");
|
|
257
447
|
const [shaped] = useState(() => !settings);
|
|
258
|
-
if (!settings) return createElement(
|
|
259
|
-
|
|
448
|
+
if (!settings) return createElement(Loading, {
|
|
449
|
+
label: WORDS.signIn.loading,
|
|
450
|
+
fields: 2,
|
|
451
|
+
title: "60%",
|
|
452
|
+
foot: "55%"
|
|
453
|
+
});
|
|
454
|
+
const methods = settings.methods;
|
|
260
455
|
const withCaptcha = captcha ? { captcha } : {};
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}, createElement("button", {
|
|
280
|
-
type: "button",
|
|
281
|
-
className: "msa-quiet",
|
|
282
|
-
onClick: () => void call.run(async () => {
|
|
283
|
-
await client.twoFactor.sendCode();
|
|
284
|
-
setCode("");
|
|
285
|
-
setMode("mail-code");
|
|
286
|
-
})
|
|
287
|
-
}, WORDS.twoFactor.byMail), createElement("button", {
|
|
288
|
-
type: "button",
|
|
289
|
-
className: "msa-quiet",
|
|
290
|
-
onClick: () => {
|
|
291
|
-
setCode("");
|
|
292
|
-
setMode("backup");
|
|
456
|
+
const move = (next) => {
|
|
457
|
+
setStep(next);
|
|
458
|
+
setCode("");
|
|
459
|
+
call.setError(null);
|
|
460
|
+
};
|
|
461
|
+
/** Mails a code or a link to the email typed, once there is one. */
|
|
462
|
+
const mail = (way) => call.run(async () => {
|
|
463
|
+
if (!email.trim()) throw new AuthClientError("EMAIL_REQUIRED", "Enter your email first.", 400);
|
|
464
|
+
if (way === "code") {
|
|
465
|
+
await client.signIn.code.send(email.trim(), withCaptcha);
|
|
466
|
+
setWait(30);
|
|
467
|
+
move("code");
|
|
468
|
+
} else {
|
|
469
|
+
await client.signIn.link(email.trim(), {
|
|
470
|
+
callbackURL: props.redirectTo ?? "/",
|
|
471
|
+
...withCaptcha
|
|
472
|
+
});
|
|
473
|
+
move("link");
|
|
293
474
|
}
|
|
294
|
-
}
|
|
295
|
-
if (
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
475
|
+
});
|
|
476
|
+
if (step === "two-factor" || step === "mail-code" || step === "backup") {
|
|
477
|
+
const lead = step === "mail-code" ? WORDS.twoFactor.mailed : step === "backup" ? WORDS.twoFactor.backupLead : WORDS.twoFactor.lead;
|
|
478
|
+
const verify = (typed) => void call.run(async () => {
|
|
479
|
+
await (step === "backup" ? client.twoFactor.verifyBackupCode(typed.trim()) : step === "mail-code" ? client.twoFactor.verifyCode(typed) : client.twoFactor.verifyTotp(typed));
|
|
480
|
+
done();
|
|
481
|
+
});
|
|
482
|
+
return createElement(Screen, {
|
|
483
|
+
title: WORDS.twoFactor.title,
|
|
484
|
+
lead,
|
|
485
|
+
stage: step
|
|
486
|
+
}, createElement("form", {
|
|
487
|
+
className: "msa-form",
|
|
488
|
+
noValidate: true,
|
|
489
|
+
onSubmit: onSubmit(() => verify(code))
|
|
490
|
+
}, step === "backup" ? createElement(Field, {
|
|
491
|
+
label: WORDS.fields.backupCode,
|
|
492
|
+
value: code,
|
|
493
|
+
onChange: setCode,
|
|
494
|
+
autoComplete: "one-time-code",
|
|
495
|
+
placeholder: WORDS.placeholders.backupCode,
|
|
496
|
+
autoFocus: true
|
|
497
|
+
}) : createElement(CodeField, {
|
|
498
|
+
label: WORDS.fields.code,
|
|
499
|
+
value: code,
|
|
500
|
+
onChange: setCode,
|
|
501
|
+
onComplete: verify
|
|
502
|
+
}), createElement(Problem, { message: call.error }), createElement(Submit, {
|
|
503
|
+
busy: call.busy,
|
|
504
|
+
label: WORDS.twoFactor.submit
|
|
505
|
+
})), createElement(Links, null, step === "two-factor" ? null : createElement(LinkButton, { onClick: () => move("two-factor") }, WORDS.twoFactor.app), step === "mail-code" ? null : createElement(LinkButton, { onClick: () => void call.run(async () => {
|
|
506
|
+
await client.twoFactor.sendCode();
|
|
507
|
+
move("mail-code");
|
|
508
|
+
}) }, WORDS.twoFactor.byMail), step === "backup" ? null : createElement(LinkButton, { onClick: () => move("backup") }, WORDS.twoFactor.backup)));
|
|
509
|
+
}
|
|
510
|
+
if (step === "code") {
|
|
511
|
+
const verify = (typed) => void call.run(async () => {
|
|
512
|
+
await client.signIn.code.verify(email.trim(), typed.trim());
|
|
513
|
+
done();
|
|
514
|
+
});
|
|
515
|
+
return createElement(Screen, {
|
|
516
|
+
title: WORDS.code.title,
|
|
517
|
+
lead: [
|
|
518
|
+
WORDS.code.lead,
|
|
519
|
+
" ",
|
|
520
|
+
createElement(Subject, { key: "email" }, email)
|
|
521
|
+
],
|
|
522
|
+
stage: step
|
|
523
|
+
}, createElement("form", {
|
|
524
|
+
className: "msa-form",
|
|
525
|
+
noValidate: true,
|
|
526
|
+
onSubmit: onSubmit(() => verify(code))
|
|
527
|
+
}, createElement(CodeField, {
|
|
528
|
+
label: WORDS.fields.code,
|
|
529
|
+
value: code,
|
|
530
|
+
onChange: setCode,
|
|
531
|
+
onComplete: verify
|
|
532
|
+
}), createElement(Problem, { message: call.error }), createElement(Submit, {
|
|
533
|
+
busy: call.busy,
|
|
534
|
+
label: WORDS.code.submit
|
|
535
|
+
})), createElement(Links, null, createElement(LinkButton, {
|
|
536
|
+
disabled: call.busy || wait > 0,
|
|
537
|
+
onClick: () => void call.run(async () => {
|
|
538
|
+
await client.signIn.code.send(email.trim(), withCaptcha);
|
|
539
|
+
setCode("");
|
|
540
|
+
setWait(30);
|
|
541
|
+
})
|
|
542
|
+
}, wait ? WORDS.code.resendIn(wait) : WORDS.code.resend), createElement(LinkButton, { onClick: () => move("start") }, WORDS.code.differentEmail)));
|
|
543
|
+
}
|
|
544
|
+
if (step === "link") return createElement(Screen, {
|
|
545
|
+
title: WORDS.link.title,
|
|
546
|
+
stage: step
|
|
547
|
+
}, createElement("p", {
|
|
548
|
+
className: "msa-note",
|
|
549
|
+
role: "status"
|
|
550
|
+
}, `${WORDS.link.sent[0]} `, createElement(Subject, { inline: true }, email), WORDS.link.sent[1]), createElement(Links, null, createElement(LinkButton, { onClick: () => move("start") }, WORDS.code.differentEmail)));
|
|
551
|
+
if (step === "confirm") return createElement(Screen, {
|
|
552
|
+
title: WORDS.confirm.title,
|
|
553
|
+
stage: step
|
|
554
|
+
}, createElement("p", {
|
|
555
|
+
className: "msa-note",
|
|
556
|
+
role: "status"
|
|
557
|
+
}, `${WORDS.confirm.sent[0]} `, createElement(Subject, { inline: true }, email), WORDS.confirm.sent[1]), createElement(Links, null, createElement(LinkButton, { onClick: () => move("start") }, WORDS.confirm.back)));
|
|
322
558
|
const byMail = methods.code ? "code" : methods.link ? "link" : null;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
key: provider,
|
|
328
|
-
type: "button",
|
|
559
|
+
const ways = [...["google", "github"].filter((one) => methods[one]).map((provider) => ({
|
|
560
|
+
icon: provider,
|
|
561
|
+
label: WORDS.ways[provider],
|
|
562
|
+
named: WORDS.ways.continueWith(WORDS.ways[provider]),
|
|
329
563
|
onClick: () => void call.run(() => client.signIn.social(provider, { callbackURL: props.redirectTo ?? "/" }))
|
|
330
|
-
}
|
|
331
|
-
|
|
564
|
+
})), ...methods.passkey ? [{
|
|
565
|
+
icon: "passkey",
|
|
566
|
+
label: WORDS.ways.passkey,
|
|
567
|
+
named: WORDS.ways.passkeySignIn,
|
|
332
568
|
onClick: () => void call.run(async () => {
|
|
333
569
|
await client.signIn.passkey();
|
|
334
570
|
done();
|
|
335
571
|
})
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
572
|
+
}] : []];
|
|
573
|
+
const quiet = methods.password ? byMail : methods.code && methods.link ? "link" : null;
|
|
574
|
+
const quietLink = quiet ? createElement(LinkButton, { onClick: () => void mail(quiet) }, quiet === "code" ? WORDS.ways.codeInstead : WORDS.ways.linkInstead) : null;
|
|
575
|
+
return createElement(Screen, {
|
|
576
|
+
title: WORDS.signIn.title(name),
|
|
577
|
+
appear: shaped,
|
|
578
|
+
stage: "start"
|
|
579
|
+
}, createElement(Ways, { ways }), createElement("form", {
|
|
580
|
+
className: "msa-form",
|
|
581
|
+
noValidate: true,
|
|
582
|
+
onSubmit: onSubmit(() => void call.run(async () => {
|
|
583
|
+
if (!methods.password) {
|
|
584
|
+
if (!email.trim()) throw new AuthClientError("EMAIL_REQUIRED", "Enter your email first.", 400);
|
|
585
|
+
if (byMail === "link") {
|
|
586
|
+
await client.signIn.link(email.trim(), {
|
|
587
|
+
callbackURL: props.redirectTo ?? "/",
|
|
588
|
+
...withCaptcha
|
|
589
|
+
});
|
|
590
|
+
move("link");
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
await client.signIn.code.send(email.trim(), withCaptcha);
|
|
594
|
+
setWait(30);
|
|
595
|
+
move("code");
|
|
344
596
|
return;
|
|
345
597
|
}
|
|
346
|
-
await client.signIn.
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
done();
|
|
364
|
-
})) }, createElement(Field, {
|
|
598
|
+
const signed = await client.signIn.password({
|
|
599
|
+
email: email.trim(),
|
|
600
|
+
password,
|
|
601
|
+
...withCaptcha
|
|
602
|
+
});
|
|
603
|
+
if ("twoFactor" in signed) {
|
|
604
|
+
move("two-factor");
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
if ("verifyEmail" in signed) {
|
|
608
|
+
move("confirm");
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
done();
|
|
612
|
+
}))
|
|
613
|
+
}, createElement(Field, {
|
|
365
614
|
label: WORDS.fields.email,
|
|
366
615
|
type: "email",
|
|
367
616
|
value: email,
|
|
368
617
|
onChange: setEmail,
|
|
369
|
-
autoComplete: "email"
|
|
618
|
+
autoComplete: "email",
|
|
619
|
+
placeholder: WORDS.placeholders.email
|
|
370
620
|
}), methods.password ? createElement(Field, {
|
|
371
621
|
label: WORDS.fields.password,
|
|
372
622
|
type: "password",
|
|
373
623
|
value: password,
|
|
374
624
|
onChange: setPassword,
|
|
375
|
-
autoComplete: "current-password"
|
|
625
|
+
autoComplete: "current-password",
|
|
626
|
+
placeholder: WORDS.placeholders.password,
|
|
627
|
+
aside: createElement("a", {
|
|
628
|
+
className: "msa-link",
|
|
629
|
+
href: props.resetUrl ?? "/api/auth/ui/reset-password"
|
|
630
|
+
}, WORDS.signIn.forgot)
|
|
376
631
|
}) : null, createElement(Captcha, { onToken: setCaptcha }), createElement(Problem, { message: call.error }), createElement(Submit, {
|
|
377
632
|
busy: call.busy,
|
|
378
633
|
label: methods.password ? WORDS.signIn.submit : byMail === "link" ? WORDS.ways.link : WORDS.ways.code
|
|
379
|
-
})
|
|
380
|
-
className: "msa-
|
|
381
|
-
|
|
382
|
-
},
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
await client.signIn.code.send(email, withCaptcha);
|
|
387
|
-
setMode("code");
|
|
388
|
-
})
|
|
389
|
-
}, WORDS.ways.code) : null, methods.link ? createElement("button", {
|
|
390
|
-
type: "button",
|
|
391
|
-
className: "msa-quiet",
|
|
392
|
-
onClick: () => void call.run(async () => {
|
|
393
|
-
await client.signIn.link(email, {
|
|
394
|
-
callbackURL: props.redirectTo ?? "/",
|
|
395
|
-
...withCaptcha
|
|
396
|
-
});
|
|
397
|
-
setMode("link");
|
|
398
|
-
})
|
|
399
|
-
}, WORDS.ways.link) : null) : null, createElement("p", { className: "msa-foot" }, methods.password ? createElement(Fragment, null, createElement("a", { href: props.resetUrl ?? "/api/auth/ui/reset-password" }, WORDS.signIn.forgot), " · ") : null, settings.signUp.policy === "invite" ? null : createElement(Fragment, null, `${WORDS.signIn.noAccount} `, createElement("a", { href: props.signUpUrl ?? "/api/auth/ui/sign-up" }, WORDS.signIn.signUp))));
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* The sign-up screen while the app's settings load: its title, three fields, button and link as bones the size of each,
|
|
403
|
-
* so the form takes their place without anything moving. It shows only after a moment, so a quick load shows none.
|
|
404
|
-
*/
|
|
405
|
-
function SignUpLoading() {
|
|
406
|
-
const bone = (width, className = "msa-bone") => createElement("span", {
|
|
407
|
-
className,
|
|
408
|
-
style: { width }
|
|
409
|
-
});
|
|
410
|
-
return createElement("div", {
|
|
411
|
-
className: "msa",
|
|
412
|
-
role: "status",
|
|
413
|
-
"aria-busy": true,
|
|
414
|
-
"aria-label": WORDS.signUp.loading
|
|
415
|
-
}, createElement("div", { className: "msa-card msa-loading" }, createElement("h1", null, bone("70%")), createElement("div", { className: "msa-bones" }, ...[
|
|
416
|
-
WORDS.fields.name,
|
|
417
|
-
WORDS.fields.email,
|
|
418
|
-
WORDS.fields.password
|
|
419
|
-
].map((label) => createElement("label", { key: label }, bone("30%"), bone("100%", "msa-bone msa-bone-control"))), createElement("span", null), bone("100%", "msa-bone msa-bone-control")), createElement("p", { className: "msa-foot" }, bone("60%", "msa-bone msa-bone-inline"))));
|
|
634
|
+
}), quietLink ? createElement("div", {
|
|
635
|
+
className: "msa-links",
|
|
636
|
+
"data-align": "center"
|
|
637
|
+
}, quietLink) : null), settings.signUp.policy === "invite" ? null : createElement("p", { className: "msa-foot" }, `${WORDS.signIn.newHere} `, createElement("a", {
|
|
638
|
+
className: "msa-link",
|
|
639
|
+
href: props.signUpUrl ?? "/api/auth/ui/sign-up"
|
|
640
|
+
}, WORDS.signIn.createAccount)));
|
|
420
641
|
}
|
|
421
642
|
/** Sign-up with a name, an email and a password; under a waitlist, joining it; when the app wants emails confirmed, asking for that. */
|
|
422
643
|
function SignUp(props) {
|
|
423
644
|
const { client, settings } = useAuth();
|
|
424
|
-
const
|
|
425
|
-
const [
|
|
645
|
+
const name = useName();
|
|
646
|
+
const [person, setPerson] = useState(""), [email, setEmail] = useState(""), [password, setPassword] = useState(""), [captcha, setCaptcha] = useState("");
|
|
647
|
+
const [after, setAfter] = useState(null);
|
|
426
648
|
const call = useCall();
|
|
427
649
|
const [shaped] = useState(() => !settings);
|
|
428
|
-
if (!settings) return createElement(
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
650
|
+
if (!settings) return createElement(Loading, {
|
|
651
|
+
label: WORDS.signUp.loading,
|
|
652
|
+
fields: 3,
|
|
653
|
+
title: "70%",
|
|
654
|
+
foot: "50%"
|
|
655
|
+
});
|
|
656
|
+
const policy = settings.signUp.policy;
|
|
657
|
+
const back = createElement(Links, null, createElement("a", {
|
|
658
|
+
className: "msa-link",
|
|
659
|
+
href: props.signInUrl ?? "/api/auth/ui/sign-in"
|
|
660
|
+
}, WORDS.confirm.back));
|
|
661
|
+
if (after === "confirm") return createElement(Screen, {
|
|
662
|
+
title: WORDS.confirm.title,
|
|
663
|
+
stage: after
|
|
664
|
+
}, createElement("p", {
|
|
665
|
+
className: "msa-note",
|
|
666
|
+
role: "status"
|
|
667
|
+
}, `${WORDS.confirm.sent[0]} `, createElement(Subject, { inline: true }, email), WORDS.confirm.sent[1]), back);
|
|
668
|
+
if (after === "waiting") return createElement(Screen, {
|
|
669
|
+
title: WORDS.signUp.waiting,
|
|
670
|
+
stage: after
|
|
671
|
+
}, createElement("p", {
|
|
672
|
+
className: "msa-note",
|
|
673
|
+
role: "status"
|
|
674
|
+
}, `${WORDS.signUp.waitingLead} `, createElement(Subject, { inline: true }, email), ` ${WORDS.signUp.waitingEnd}`), back);
|
|
675
|
+
const ways = policy === "open" || policy === "domains" ? ["google", "github"].filter((one) => settings.methods[one]).map((provider) => ({
|
|
676
|
+
icon: provider,
|
|
677
|
+
label: WORDS.ways[provider],
|
|
678
|
+
named: WORDS.ways.continueWith(WORDS.ways[provider]),
|
|
679
|
+
onClick: () => void call.run(() => client.signIn.social(provider, { callbackURL: props.redirectTo ?? "/" }))
|
|
680
|
+
})) : [];
|
|
681
|
+
return createElement(Screen, {
|
|
682
|
+
title: WORDS.signUp.title(name),
|
|
433
683
|
appear: shaped,
|
|
684
|
+
stage: "start",
|
|
434
685
|
...policy === "invite" ? { lead: WORDS.signUp.invite } : {}
|
|
435
|
-
}, createElement(
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
686
|
+
}, createElement(Ways, { ways }), createElement("form", {
|
|
687
|
+
className: "msa-form",
|
|
688
|
+
noValidate: true,
|
|
689
|
+
onSubmit: onSubmit(() => void call.run(async () => {
|
|
690
|
+
try {
|
|
691
|
+
if ("verifyEmail" in await client.signUp({
|
|
692
|
+
name: person.trim(),
|
|
693
|
+
email: email.trim(),
|
|
694
|
+
password,
|
|
695
|
+
...captcha ? { captcha } : {}
|
|
696
|
+
})) {
|
|
697
|
+
setAfter("confirm");
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
go(props.redirectTo ?? "/");
|
|
701
|
+
} catch (error) {
|
|
702
|
+
if (error instanceof AuthClientError && error.code === "SIGN_UP_WAITLIST") {
|
|
703
|
+
setAfter("waiting");
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
throw error;
|
|
451
707
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
})) }, createElement(Field, {
|
|
708
|
+
}))
|
|
709
|
+
}, createElement(Field, {
|
|
455
710
|
label: WORDS.fields.name,
|
|
456
|
-
value:
|
|
457
|
-
onChange:
|
|
458
|
-
autoComplete: "name"
|
|
711
|
+
value: person,
|
|
712
|
+
onChange: setPerson,
|
|
713
|
+
autoComplete: "name",
|
|
714
|
+
placeholder: WORDS.placeholders.name
|
|
459
715
|
}), createElement(Field, {
|
|
460
716
|
label: WORDS.fields.email,
|
|
461
717
|
type: "email",
|
|
462
718
|
value: email,
|
|
463
719
|
onChange: setEmail,
|
|
464
|
-
autoComplete: "email"
|
|
720
|
+
autoComplete: "email",
|
|
721
|
+
placeholder: WORDS.placeholders.email
|
|
465
722
|
}), createElement(Field, {
|
|
466
723
|
label: WORDS.fields.password,
|
|
467
724
|
type: "password",
|
|
468
725
|
value: password,
|
|
469
726
|
onChange: setPassword,
|
|
470
|
-
autoComplete: "new-password"
|
|
727
|
+
autoComplete: "new-password",
|
|
728
|
+
placeholder: WORDS.placeholders.newPassword,
|
|
729
|
+
minLength: 8
|
|
471
730
|
}), createElement(Captcha, { onToken: setCaptcha }), createElement(Problem, { message: call.error }), createElement(Submit, {
|
|
472
731
|
busy: call.busy,
|
|
473
732
|
label: policy === "waitlist" ? WORDS.signUp.waitlist : WORDS.signUp.submit
|
|
474
|
-
})), createElement("p", { className: "msa-foot" }, `${WORDS.signUp.haveAccount} `, createElement("a", {
|
|
733
|
+
})), createElement("p", { className: "msa-foot" }, `${WORDS.signUp.haveAccount} `, createElement("a", {
|
|
734
|
+
className: "msa-link",
|
|
735
|
+
href: props.signInUrl ?? "/api/auth/ui/sign-in"
|
|
736
|
+
}, WORDS.signUp.signIn)));
|
|
475
737
|
}
|
|
476
738
|
/** The signed-in person's picture or initial, opening a menu: their account, and signing out. */
|
|
477
739
|
function UserButton(props) {
|
|
478
740
|
const { client, signedIn } = useAuth();
|
|
741
|
+
const root = useRoot();
|
|
479
742
|
const [open, setOpen] = useState(false);
|
|
480
743
|
const menu = useRef(null);
|
|
481
744
|
const id = useId();
|
|
@@ -483,35 +746,41 @@ function UserButton(props) {
|
|
|
483
746
|
if (!open) return;
|
|
484
747
|
menu.current?.querySelector("[role=menuitem]")?.focus();
|
|
485
748
|
const away = (event) => {
|
|
486
|
-
if (!menu.current?.parentElement?.contains(event.target)) setOpen(false);
|
|
749
|
+
if (!menu.current?.parentElement?.parentElement?.contains(event.target)) setOpen(false);
|
|
487
750
|
};
|
|
488
751
|
document.addEventListener("mousedown", away);
|
|
489
752
|
return () => document.removeEventListener("mousedown", away);
|
|
490
753
|
}, [open]);
|
|
491
754
|
if (!signedIn) return null;
|
|
492
755
|
const { user } = signedIn;
|
|
756
|
+
const who = user.name || user.email;
|
|
493
757
|
const keys = (event) => {
|
|
494
758
|
const items = [...menu.current?.querySelectorAll("[role=menuitem]") ?? []];
|
|
495
759
|
const at = items.indexOf(document.activeElement);
|
|
496
760
|
if (event.key === "Escape") {
|
|
497
761
|
setOpen(false);
|
|
498
|
-
|
|
762
|
+
event.currentTarget.querySelector("button[aria-haspopup]")?.focus();
|
|
499
763
|
}
|
|
500
764
|
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
501
765
|
event.preventDefault();
|
|
502
766
|
items[(at + (event.key === "ArrowDown" ? 1 : items.length - 1)) % items.length]?.focus();
|
|
503
767
|
}
|
|
768
|
+
if (event.key === "Home" || event.key === "End") {
|
|
769
|
+
event.preventDefault();
|
|
770
|
+
items[event.key === "Home" ? 0 : items.length - 1]?.focus();
|
|
771
|
+
}
|
|
504
772
|
};
|
|
505
773
|
const left = (event) => {
|
|
506
774
|
if (!event.currentTarget.contains(event.relatedTarget)) setOpen(false);
|
|
507
775
|
};
|
|
508
776
|
return createElement("div", {
|
|
777
|
+
...root,
|
|
509
778
|
className: "msa msa-menu",
|
|
510
779
|
onKeyDown: keys,
|
|
511
780
|
onBlur: left
|
|
512
781
|
}, createElement("button", {
|
|
513
782
|
type: "button",
|
|
514
|
-
className: "msa-avatar",
|
|
783
|
+
className: "msa-avatar-button",
|
|
515
784
|
"aria-label": WORDS.user.menu,
|
|
516
785
|
"aria-haspopup": "menu",
|
|
517
786
|
"aria-expanded": open,
|
|
@@ -523,49 +792,134 @@ function UserButton(props) {
|
|
|
523
792
|
setOpen(true);
|
|
524
793
|
}
|
|
525
794
|
}
|
|
526
|
-
},
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
})
|
|
795
|
+
}, createElement(Avatar, {
|
|
796
|
+
name: who,
|
|
797
|
+
image: user.image
|
|
798
|
+
})), open ? createElement("div", { className: "msa-popup" }, createElement("div", { className: "msa-menu-head" }, createElement(Avatar, {
|
|
799
|
+
name: who,
|
|
800
|
+
image: user.image
|
|
801
|
+
}), createElement("span", null, createElement("strong", null, who), user.name ? createElement("small", null, user.email) : null)), createElement("div", {
|
|
802
|
+
className: "msa-separator",
|
|
803
|
+
role: "presentation"
|
|
804
|
+
}), createElement("div", {
|
|
530
805
|
id,
|
|
531
806
|
role: "menu",
|
|
532
807
|
ref: menu,
|
|
533
808
|
"aria-label": WORDS.user.menu
|
|
534
|
-
}, createElement("
|
|
535
|
-
display: "block",
|
|
536
|
-
fontSize: 13
|
|
537
|
-
} }, user.email) : null), createElement("a", {
|
|
809
|
+
}, createElement("a", {
|
|
538
810
|
role: "menuitem",
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}, WORDS.user.manage), createElement("button", {
|
|
811
|
+
className: "msa-item",
|
|
812
|
+
href: props.accountUrl ?? "/api/auth/ui/account"
|
|
813
|
+
}, createElement(Icon, { name: "user" }), WORDS.user.manage), createElement("button", {
|
|
542
814
|
type: "button",
|
|
543
815
|
role: "menuitem",
|
|
816
|
+
className: "msa-item",
|
|
544
817
|
onClick: async () => {
|
|
545
818
|
await client.signOut();
|
|
546
819
|
go(props.afterSignOut ?? "/");
|
|
547
820
|
}
|
|
548
|
-
}, WORDS.user.signOut)) : null);
|
|
821
|
+
}, createElement(Icon, { name: "door" }), WORDS.user.signOut))) : null);
|
|
822
|
+
}
|
|
823
|
+
/** A settings panel in the card material: its title, its rows, and what its last action said when it failed. */
|
|
824
|
+
function Panel(props) {
|
|
825
|
+
const id = useId();
|
|
826
|
+
const head = createElement("header", { className: "msa-panel-head" }, createElement("h2", { id }, props.title), props.line ? createElement("p", null, props.line) : null);
|
|
827
|
+
const problem = createElement("p", {
|
|
828
|
+
className: "msa-feedback",
|
|
829
|
+
role: "alert"
|
|
830
|
+
}, props.problem ?? "");
|
|
831
|
+
const single = !props.children && !props.foot && props.action !== void 0;
|
|
832
|
+
return createElement("section", {
|
|
833
|
+
className: "msa-panel",
|
|
834
|
+
"aria-labelledby": id,
|
|
835
|
+
...props.tone ? { "data-tone": props.tone } : {}
|
|
836
|
+
}, props.header ?? null, single ? createElement("div", { className: "msa-panel-single" }, head, createElement("div", { className: "msa-panel-actions" }, props.action)) : head, props.children ? createElement("div", { className: "msa-rows" }, props.children) : null, props.foot ? createElement("footer", { className: "msa-panel-foot" }, problem, createElement("div", { className: "msa-panel-actions" }, props.foot)) : problem);
|
|
837
|
+
}
|
|
838
|
+
/** One setting: its name and value on the left, its control on the right; `extra` opens under it, such as a form. */
|
|
839
|
+
function Row(props) {
|
|
840
|
+
return createElement("div", {
|
|
841
|
+
className: "msa-row",
|
|
842
|
+
...props.field ? { "data-field": "" } : {}
|
|
843
|
+
}, createElement("div", { className: "msa-row-main" }, createElement("div", { className: "msa-row-copy" }, typeof props.title === "string" ? createElement("span", { className: "msa-row-title" }, props.title) : props.title, props.detail ? createElement("span", { className: "msa-row-detail" }, props.detail) : null), props.control ? createElement("div", { className: "msa-row-control" }, props.control) : null), props.extra ? createElement("div", { className: "msa-row-extra" }, props.extra) : null);
|
|
844
|
+
}
|
|
845
|
+
/** A field as a settings row: its label on the left, the field on the right. */
|
|
846
|
+
function FieldRow(props) {
|
|
847
|
+
const id = useId();
|
|
848
|
+
return createElement(Row, {
|
|
849
|
+
field: true,
|
|
850
|
+
title: createElement("label", {
|
|
851
|
+
htmlFor: id,
|
|
852
|
+
className: "msa-row-title"
|
|
853
|
+
}, props.label),
|
|
854
|
+
control: createElement("input", {
|
|
855
|
+
id,
|
|
856
|
+
className: "msa-input",
|
|
857
|
+
type: props.type ?? "text",
|
|
858
|
+
value: props.value,
|
|
859
|
+
required: true,
|
|
860
|
+
autoComplete: props.autoComplete ?? "off",
|
|
861
|
+
placeholder: props.placeholder,
|
|
862
|
+
autoFocus: props.autoFocus,
|
|
863
|
+
onChange: (event) => props.onChange(event.target.value)
|
|
864
|
+
})
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
/** A panel's buttons for a form inside it: Cancel, quiet, and the act, last. */
|
|
868
|
+
function Actions(props) {
|
|
869
|
+
return createElement("div", { className: "msa-panel-actions" }, props.onCancel ? createElement("button", {
|
|
870
|
+
type: "button",
|
|
871
|
+
className: "msa-button msa-ghost msa-small",
|
|
872
|
+
onClick: props.onCancel
|
|
873
|
+
}, WORDS.account.cancel) : null, createElement("button", {
|
|
874
|
+
type: "submit",
|
|
875
|
+
className: "msa-button msa-primary msa-small",
|
|
876
|
+
"aria-busy": props.busy || void 0,
|
|
877
|
+
disabled: props.disabled
|
|
878
|
+
}, props.busy ? WORDS.busy : props.label));
|
|
879
|
+
}
|
|
880
|
+
/** A settings page while what it shows loads: the header and two panels as bones. */
|
|
881
|
+
function PageLoading(props) {
|
|
882
|
+
const root = useRoot(true);
|
|
883
|
+
return createElement("div", {
|
|
884
|
+
...root,
|
|
885
|
+
role: "status",
|
|
886
|
+
"aria-busy": true,
|
|
887
|
+
"aria-label": props.label
|
|
888
|
+
}, createElement("div", { className: "msa-page msa-loading" }, createElement("div", { className: "msa-identity" }, bone("48px", "msa-bone msa-avatar"), createElement("div", {
|
|
889
|
+
className: "msa-identity-copy",
|
|
890
|
+
style: { flex: 1 }
|
|
891
|
+
}, createElement("span", { className: "msa-identity-name" }, bone("40%")), createElement("span", { className: "msa-identity-detail" }, bone("30%")))), ...[2, 3].map((rows) => createElement("div", {
|
|
892
|
+
key: rows,
|
|
893
|
+
className: "msa-panel"
|
|
894
|
+
}, createElement("div", { className: "msa-panel-head" }, createElement("h2", null, bone("25%"))), createElement("div", { className: "msa-rows" }, ...Array.from({ length: rows }, (_, index) => createElement("div", {
|
|
895
|
+
key: index,
|
|
896
|
+
className: "msa-row"
|
|
897
|
+
}, createElement("div", { className: "msa-row-main" }, createElement("span", {
|
|
898
|
+
className: "msa-row-title",
|
|
899
|
+
style: { flex: 1 }
|
|
900
|
+
}, bone("35%")), bone("96px", "msa-bone msa-bone-control")))))))));
|
|
549
901
|
}
|
|
550
902
|
/** The signed-in person's account: profile, password, two-step sign-in, passkeys, sessions, keys and apps. */
|
|
551
903
|
function UserProfile() {
|
|
552
904
|
const { client, signedIn, settings, refresh } = useAuth();
|
|
905
|
+
const root = useRoot(true);
|
|
553
906
|
const [sessions, setSessions] = useState([]);
|
|
554
907
|
const [passkeys, setPasskeys] = useState([]);
|
|
555
908
|
const [keys, setKeys] = useState([]);
|
|
556
909
|
const [grants, setGrants] = useState([]);
|
|
557
910
|
const [name, setName] = useState(""), [current, setCurrent] = useState(""), [next, setNext] = useState(""), [twoFactorPassword, setTwoFactorPassword] = useState(""), [totpCode, setTotpCode] = useState("");
|
|
558
911
|
const [keyName, setKeyName] = useState(""), [keyScopes, setKeyScopes] = useState([]);
|
|
559
|
-
const [made, setMade] = useState(null), [setup, setSetup] = useState(null)
|
|
912
|
+
const [made, setMade] = useState(null), [setup, setSetup] = useState(null);
|
|
913
|
+
const [open, setOpen] = useState(null);
|
|
914
|
+
const [savedName, showSavedName] = useDone(), [savedPassword, showSavedPassword] = useDone();
|
|
560
915
|
const call = useCall();
|
|
561
916
|
const [at, setAt] = useState("");
|
|
562
|
-
/** Runs one action of `
|
|
563
|
-
const run = (
|
|
564
|
-
|
|
565
|
-
setAt(section);
|
|
917
|
+
/** Runs one action of `panel`, clearing what the last one said. */
|
|
918
|
+
const run = (panel, work) => {
|
|
919
|
+
setAt(panel);
|
|
566
920
|
return call.run(work);
|
|
567
921
|
};
|
|
568
|
-
const problemIn = (
|
|
922
|
+
const problemIn = (panel) => at === panel ? call.error : null;
|
|
569
923
|
const load = useCallback(async () => {
|
|
570
924
|
const scoped = Object.keys(settings?.scopes ?? {}).length > 0;
|
|
571
925
|
const [s, p, k, g] = await Promise.all([
|
|
@@ -585,148 +939,213 @@ function UserProfile() {
|
|
|
585
939
|
load().catch(() => {});
|
|
586
940
|
}
|
|
587
941
|
}, [signedIn, load]);
|
|
588
|
-
if (
|
|
942
|
+
if (signedIn === null) return null;
|
|
943
|
+
if (!signedIn || !settings) return createElement(PageLoading, { label: WORDS.account.title });
|
|
589
944
|
const { user, session } = signedIn;
|
|
590
945
|
const scopes = Object.entries(settings.scopes);
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
946
|
+
const scopeWords = (list) => list.map((scope) => settings.scopes[scope] ?? scope).join(", ");
|
|
947
|
+
const close = () => {
|
|
948
|
+
setOpen(null);
|
|
949
|
+
setCurrent("");
|
|
950
|
+
setNext("");
|
|
951
|
+
setTwoFactorPassword("");
|
|
952
|
+
call.setError(null);
|
|
953
|
+
};
|
|
954
|
+
const profile = createElement("form", {
|
|
955
|
+
noValidate: true,
|
|
956
|
+
onSubmit: onSubmit(() => void run("profile", async () => {
|
|
957
|
+
await client.profile.update({ name: name.trim() });
|
|
958
|
+
await refresh();
|
|
959
|
+
showSavedName();
|
|
960
|
+
}))
|
|
961
|
+
}, createElement(Panel, {
|
|
962
|
+
title: WORDS.account.profile,
|
|
963
|
+
problem: problemIn("profile"),
|
|
964
|
+
foot: createElement("button", {
|
|
965
|
+
type: "submit",
|
|
966
|
+
className: "msa-button msa-secondary msa-small",
|
|
967
|
+
disabled: !savedName && (name.trim() === user.name || !name.trim())
|
|
968
|
+
}, savedName ? WORDS.account.saved : WORDS.account.save)
|
|
969
|
+
}, createElement(FieldRow, {
|
|
600
970
|
label: WORDS.fields.name,
|
|
601
971
|
value: name,
|
|
602
972
|
onChange: setName,
|
|
603
973
|
autoComplete: "name"
|
|
604
|
-
}), createElement(
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
974
|
+
}), createElement(Row, {
|
|
975
|
+
title: WORDS.fields.email,
|
|
976
|
+
control: createElement("span", { className: "msa-value" }, user.email)
|
|
977
|
+
})));
|
|
978
|
+
const passwordRow = settings.methods.password ? createElement(Row, {
|
|
979
|
+
title: WORDS.account.password,
|
|
980
|
+
control: open === "password" ? null : createElement("button", {
|
|
981
|
+
type: "button",
|
|
982
|
+
className: "msa-button msa-secondary msa-small",
|
|
983
|
+
onClick: () => {
|
|
984
|
+
close();
|
|
985
|
+
setOpen("password");
|
|
986
|
+
}
|
|
987
|
+
}, savedPassword ? WORDS.account.saved : WORDS.account.changePassword),
|
|
988
|
+
extra: open === "password" ? createElement("form", {
|
|
989
|
+
noValidate: true,
|
|
990
|
+
onSubmit: onSubmit(() => void run("security", async () => {
|
|
991
|
+
await client.password.change({
|
|
992
|
+
current,
|
|
993
|
+
next,
|
|
994
|
+
signOutOthers: true
|
|
995
|
+
});
|
|
996
|
+
close();
|
|
997
|
+
showSavedPassword();
|
|
998
|
+
}))
|
|
999
|
+
}, createElement(FieldRow, {
|
|
1000
|
+
label: WORDS.fields.currentPassword,
|
|
1001
|
+
type: "password",
|
|
1002
|
+
value: current,
|
|
1003
|
+
onChange: setCurrent,
|
|
1004
|
+
autoComplete: "current-password",
|
|
1005
|
+
autoFocus: true
|
|
1006
|
+
}), createElement(FieldRow, {
|
|
1007
|
+
label: WORDS.fields.newPassword,
|
|
1008
|
+
type: "password",
|
|
1009
|
+
value: next,
|
|
1010
|
+
onChange: setNext,
|
|
1011
|
+
autoComplete: "new-password",
|
|
1012
|
+
placeholder: WORDS.placeholders.newPassword
|
|
1013
|
+
}), createElement(Actions, {
|
|
1014
|
+
busy: call.busy,
|
|
1015
|
+
label: WORDS.account.savePassword,
|
|
1016
|
+
onCancel: close
|
|
1017
|
+
})) : null
|
|
1018
|
+
}) : null;
|
|
1019
|
+
const on = user.twoFactorEnabled === true;
|
|
1020
|
+
const twoFactorRow = createElement(Row, {
|
|
1021
|
+
title: WORDS.account.twoFactor,
|
|
1022
|
+
detail: on ? WORDS.account.on : WORDS.account.off,
|
|
1023
|
+
control: open === "two-factor" || setup ? null : createElement("button", {
|
|
1024
|
+
type: "button",
|
|
1025
|
+
className: "msa-button msa-secondary msa-small",
|
|
1026
|
+
onClick: () => {
|
|
1027
|
+
close();
|
|
1028
|
+
setOpen("two-factor");
|
|
1029
|
+
}
|
|
1030
|
+
}, on ? WORDS.account.turnOff : WORDS.account.turnOn),
|
|
1031
|
+
extra: setup ? createElement("div", { className: "msa-setup" }, createElement("p", { className: "msa-note" }, WORDS.account.twoFactorSetup), createElement(QrCode, { value: setup.totpURI }), createElement("div", { style: { width: "100%" } }, createElement(Secret, {
|
|
1032
|
+
label: WORDS.account.setupKey,
|
|
1033
|
+
value: setupKeyOf(setup.totpURI)
|
|
1034
|
+
})), createElement("a", {
|
|
1035
|
+
className: "msa-link",
|
|
1036
|
+
href: setup.totpURI
|
|
1037
|
+
}, WORDS.account.openInApp), createElement("div", { className: "msa-field" }, createElement("span", { className: "msa-label" }, WORDS.account.backupCodes), createElement("p", { className: "msa-lead" }, WORDS.account.backupCodesLead)), createElement("ul", { className: "msa-codes" }, ...setup.backupCodes.map((one) => createElement("li", { key: one }, createElement("code", null, one)))), createElement(CopyButton, {
|
|
1038
|
+
label: WORDS.account.copyCodes,
|
|
1039
|
+
value: setup.backupCodes.join("\n")
|
|
1040
|
+
}), createElement("form", {
|
|
1041
|
+
noValidate: true,
|
|
1042
|
+
style: { width: "100%" },
|
|
1043
|
+
onSubmit: onSubmit(() => void run("security", async () => {
|
|
1044
|
+
await client.twoFactor.verifyTotp(totpCode);
|
|
1045
|
+
setSetup(null);
|
|
1046
|
+
setTotpCode("");
|
|
643
1047
|
await refresh();
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
label: WORDS.account.remove,
|
|
681
|
-
confirm: WORDS.account.removeForGood,
|
|
682
|
-
busy: call.busy,
|
|
683
|
-
onConfirm: () => void run("passkeys", async () => {
|
|
684
|
-
await client.passkeys.remove(one.id);
|
|
685
|
-
await load();
|
|
686
|
-
})
|
|
687
|
-
}))) : createElement("p", { className: "msa-note" }, WORDS.account.noPasskeys), createElement("div", { style: { marginTop: 12 } }, createElement("button", {
|
|
1048
|
+
}))
|
|
1049
|
+
}, createElement(FieldRow, {
|
|
1050
|
+
label: WORDS.fields.code,
|
|
1051
|
+
value: totpCode,
|
|
1052
|
+
onChange: setTotpCode,
|
|
1053
|
+
autoComplete: "one-time-code"
|
|
1054
|
+
}), createElement(Actions, {
|
|
1055
|
+
busy: call.busy,
|
|
1056
|
+
label: WORDS.account.finish
|
|
1057
|
+
}))) : open === "two-factor" ? createElement("form", {
|
|
1058
|
+
noValidate: true,
|
|
1059
|
+
onSubmit: onSubmit(() => void run("security", async () => {
|
|
1060
|
+
if (on) {
|
|
1061
|
+
await client.twoFactor.disable(twoFactorPassword);
|
|
1062
|
+
await refresh();
|
|
1063
|
+
} else setSetup(await client.twoFactor.enable(twoFactorPassword));
|
|
1064
|
+
close();
|
|
1065
|
+
}))
|
|
1066
|
+
}, createElement(FieldRow, {
|
|
1067
|
+
label: WORDS.fields.yourPassword,
|
|
1068
|
+
type: "password",
|
|
1069
|
+
value: twoFactorPassword,
|
|
1070
|
+
onChange: setTwoFactorPassword,
|
|
1071
|
+
autoComplete: "current-password",
|
|
1072
|
+
autoFocus: true
|
|
1073
|
+
}), createElement(Actions, {
|
|
1074
|
+
busy: call.busy,
|
|
1075
|
+
label: on ? WORDS.account.turnOff : WORDS.account.turnOn,
|
|
1076
|
+
onCancel: close
|
|
1077
|
+
})) : null
|
|
1078
|
+
});
|
|
1079
|
+
const security = createElement(Panel, {
|
|
1080
|
+
title: WORDS.account.security,
|
|
1081
|
+
problem: problemIn("security")
|
|
1082
|
+
}, passwordRow, twoFactorRow);
|
|
1083
|
+
const addPasskey = createElement("button", {
|
|
688
1084
|
type: "button",
|
|
1085
|
+
className: "msa-button msa-secondary msa-small",
|
|
689
1086
|
onClick: () => void run("passkeys", async () => {
|
|
690
1087
|
await client.passkeys.add();
|
|
691
1088
|
await load();
|
|
692
1089
|
})
|
|
693
|
-
},
|
|
1090
|
+
}, createElement(Icon, { name: "plus" }), WORDS.account.addPasskey);
|
|
1091
|
+
const passkeyPanel = settings.methods.passkey ? passkeys.length ? createElement(Panel, {
|
|
1092
|
+
title: WORDS.account.passkeys,
|
|
1093
|
+
problem: problemIn("passkeys"),
|
|
1094
|
+
foot: addPasskey
|
|
1095
|
+
}, ...passkeys.map((one) => createElement(Row, {
|
|
694
1096
|
key: one.id,
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
await load();
|
|
1097
|
+
title: one.name || WORDS.account.passkey,
|
|
1098
|
+
detail: one.createdAt ? WORDS.account.added(ago(one.createdAt)) : void 0,
|
|
1099
|
+
control: createElement(Confirm, {
|
|
1100
|
+
label: WORDS.account.remove,
|
|
1101
|
+
confirm: WORDS.account.removeForGood,
|
|
1102
|
+
busy: call.busy,
|
|
1103
|
+
onConfirm: () => void run("passkeys", async () => {
|
|
1104
|
+
await client.passkeys.remove(one.id);
|
|
1105
|
+
await load();
|
|
1106
|
+
})
|
|
706
1107
|
})
|
|
707
|
-
}
|
|
1108
|
+
}))) : createElement(Panel, {
|
|
1109
|
+
title: WORDS.account.passkeys,
|
|
1110
|
+
line: WORDS.account.noPasskeys,
|
|
1111
|
+
problem: problemIn("passkeys"),
|
|
1112
|
+
action: addPasskey
|
|
1113
|
+
}) : null;
|
|
1114
|
+
const others = sessions.filter((one) => one.id !== session.id);
|
|
1115
|
+
const sessionPanel = createElement(Panel, {
|
|
1116
|
+
title: WORDS.account.sessions,
|
|
1117
|
+
problem: problemIn("sessions"),
|
|
1118
|
+
...others.length ? { foot: createElement("button", {
|
|
1119
|
+
type: "button",
|
|
1120
|
+
className: "msa-button msa-secondary msa-small",
|
|
1121
|
+
onClick: () => void run("sessions", async () => {
|
|
1122
|
+
await client.sessions.revokeOthers();
|
|
1123
|
+
await load();
|
|
1124
|
+
})
|
|
1125
|
+
}, WORDS.account.signOutOthers) } : {}
|
|
1126
|
+
}, ...[...sessions].sort((a, b) => Number(b.id === session.id) - Number(a.id === session.id)).map((one) => createElement(Row, {
|
|
708
1127
|
key: one.id,
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
onSubmit: onSubmit(() => void run("
|
|
1128
|
+
title: deviceOf(one.userAgent) ?? WORDS.account.unknownDevice,
|
|
1129
|
+
detail: [
|
|
1130
|
+
one.impersonatedBy ? WORDS.account.signedInBy(one.impersonatedBy) : null,
|
|
1131
|
+
WORDS.account.signedIn(ago(one.createdAt)),
|
|
1132
|
+
one.ipAddress
|
|
1133
|
+
].filter(Boolean).join(" · "),
|
|
1134
|
+
control: one.id === session.id ? createElement("span", { className: "msa-tag" }, WORDS.account.thisDevice) : createElement("button", {
|
|
1135
|
+
type: "button",
|
|
1136
|
+
className: "msa-button msa-ghost msa-small",
|
|
1137
|
+
onClick: () => void run("sessions", async () => {
|
|
1138
|
+
await client.sessions.revoke(one.token);
|
|
1139
|
+
await load();
|
|
1140
|
+
})
|
|
1141
|
+
}, WORDS.account.signOut)
|
|
1142
|
+
})));
|
|
1143
|
+
const keyPanel = scopes.length ? createElement("form", {
|
|
1144
|
+
noValidate: true,
|
|
1145
|
+
onSubmit: onSubmit(() => void run("keys", async () => {
|
|
727
1146
|
setMade(null);
|
|
728
1147
|
const key = await client.keys.create({
|
|
729
|
-
name: keyName,
|
|
1148
|
+
name: keyName.trim(),
|
|
730
1149
|
scopes: keyScopes
|
|
731
1150
|
});
|
|
732
1151
|
setMade(key.key);
|
|
@@ -734,55 +1153,103 @@ function UserProfile() {
|
|
|
734
1153
|
setKeyScopes([]);
|
|
735
1154
|
await load();
|
|
736
1155
|
}))
|
|
737
|
-
}, createElement(
|
|
1156
|
+
}, createElement(Panel, {
|
|
1157
|
+
title: WORDS.account.keys,
|
|
1158
|
+
line: keys.length ? void 0 : WORDS.account.noKeys,
|
|
1159
|
+
problem: problemIn("keys"),
|
|
1160
|
+
foot: createElement("button", {
|
|
1161
|
+
type: "submit",
|
|
1162
|
+
className: "msa-button msa-secondary msa-small",
|
|
1163
|
+
disabled: !keyScopes.length || !keyName.trim()
|
|
1164
|
+
}, createElement(Icon, { name: "plus" }), WORDS.account.createKey)
|
|
1165
|
+
}, ...keys.map((one) => createElement(Row, {
|
|
1166
|
+
key: one.id,
|
|
1167
|
+
title: one.name ?? one.start ?? one.id,
|
|
1168
|
+
detail: [scopeWords(one.scopes), one.lastUsedAt ? WORDS.account.lastUsed(ago(one.lastUsedAt)) : WORDS.account.neverUsed].join(" · "),
|
|
1169
|
+
control: createElement(Confirm, {
|
|
1170
|
+
label: WORDS.account.revoke,
|
|
1171
|
+
confirm: WORDS.account.revokeForGood,
|
|
1172
|
+
busy: call.busy,
|
|
1173
|
+
onConfirm: () => void run("keys", async () => {
|
|
1174
|
+
await client.keys.revoke(one.id);
|
|
1175
|
+
await load();
|
|
1176
|
+
})
|
|
1177
|
+
})
|
|
1178
|
+
})), made ? createElement(Row, {
|
|
1179
|
+
title: WORDS.account.keyShown,
|
|
1180
|
+
extra: createElement(Secret, {
|
|
1181
|
+
label: WORDS.account.keys,
|
|
1182
|
+
value: made
|
|
1183
|
+
})
|
|
1184
|
+
}) : null, createElement(FieldRow, {
|
|
738
1185
|
label: WORDS.fields.keyName,
|
|
739
1186
|
value: keyName,
|
|
740
|
-
onChange: setKeyName
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
fontWeight: 400
|
|
758
|
-
}
|
|
759
|
-
}, createElement("input", {
|
|
760
|
-
type: "checkbox",
|
|
761
|
-
style: {
|
|
762
|
-
width: "auto",
|
|
763
|
-
minHeight: 0
|
|
764
|
-
},
|
|
765
|
-
checked: keyScopes.includes(scope),
|
|
766
|
-
onChange: () => setKeyScopes(keyScopes.includes(scope) ? keyScopes.filter((one) => one !== scope) : [...keyScopes, scope])
|
|
767
|
-
}), what))), createElement("div", null, createElement("button", {
|
|
768
|
-
type: "submit",
|
|
769
|
-
disabled: call.busy || !keyScopes.length
|
|
770
|
-
}, WORDS.account.createKey)))) : null, createElement("h2", { style: { marginTop: 20 } }, WORDS.account.apps), grants.length ? grants.map((one) => createElement("div", {
|
|
1187
|
+
onChange: setKeyName,
|
|
1188
|
+
placeholder: WORDS.placeholders.keyName
|
|
1189
|
+
}), createElement(Row, {
|
|
1190
|
+
title: WORDS.account.scopes,
|
|
1191
|
+
control: createElement("div", { className: "msa-scopes" }, ...scopes.map(([scope, what]) => createElement("label", {
|
|
1192
|
+
key: scope,
|
|
1193
|
+
className: "msa-check"
|
|
1194
|
+
}, createElement("input", {
|
|
1195
|
+
type: "checkbox",
|
|
1196
|
+
checked: keyScopes.includes(scope),
|
|
1197
|
+
onChange: () => setKeyScopes(keyScopes.includes(scope) ? keyScopes.filter((one) => one !== scope) : [...keyScopes, scope])
|
|
1198
|
+
}), what)))
|
|
1199
|
+
}))) : null;
|
|
1200
|
+
const appPanel = scopes.length || grants.length ? grants.length ? createElement(Panel, {
|
|
1201
|
+
title: WORDS.account.apps,
|
|
1202
|
+
problem: problemIn("apps")
|
|
1203
|
+
}, ...grants.map((one) => createElement(Row, {
|
|
771
1204
|
key: one.id,
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
1205
|
+
title: one.client ?? one.clientId,
|
|
1206
|
+
detail: scopeWords(one.scopes),
|
|
1207
|
+
control: createElement(Confirm, {
|
|
1208
|
+
label: WORDS.account.removeAccess,
|
|
1209
|
+
confirm: WORDS.account.removeAccessForGood,
|
|
1210
|
+
busy: call.busy,
|
|
1211
|
+
onConfirm: () => void run("apps", async () => {
|
|
1212
|
+
await client.grants.revoke(one.id);
|
|
1213
|
+
await load();
|
|
1214
|
+
})
|
|
780
1215
|
})
|
|
781
|
-
}))) : createElement(
|
|
1216
|
+
}))) : createElement(Panel, {
|
|
1217
|
+
title: WORDS.account.apps,
|
|
1218
|
+
line: WORDS.account.noApps
|
|
1219
|
+
}) : null;
|
|
1220
|
+
return createElement("div", root, createElement("div", { className: "msa-page" }, createElement("header", { className: "msa-identity" }, createElement(Avatar, {
|
|
1221
|
+
name: user.name || user.email,
|
|
1222
|
+
image: user.image,
|
|
1223
|
+
size: "large"
|
|
1224
|
+
}), createElement("div", { className: "msa-identity-copy" }, createElement("h1", { className: "msa-identity-name" }, user.name || user.email), user.name ? createElement("p", { className: "msa-identity-detail" }, user.email) : null)), profile, security, passkeyPanel, sessionPanel, keyPanel, appPanel));
|
|
1225
|
+
}
|
|
1226
|
+
/** A Copy button for a value that isn't on one line, such as backup codes. */
|
|
1227
|
+
function CopyButton(props) {
|
|
1228
|
+
const [copied, copy] = useDone();
|
|
1229
|
+
return createElement("button", {
|
|
1230
|
+
type: "button",
|
|
1231
|
+
className: "msa-button msa-secondary msa-small",
|
|
1232
|
+
onClick: () => void navigator.clipboard?.writeText(props.value).then(copy, () => {})
|
|
1233
|
+
}, copied ? WORDS.account.copied : props.label);
|
|
1234
|
+
}
|
|
1235
|
+
/** A choice from a list in Midsummer's select: the value, and a chevron. */
|
|
1236
|
+
function Select(props) {
|
|
1237
|
+
return createElement("span", {
|
|
1238
|
+
className: "msa-select",
|
|
1239
|
+
...props.small ? { "data-size": "small" } : {}
|
|
1240
|
+
}, createElement("select", {
|
|
1241
|
+
"aria-label": props.label,
|
|
1242
|
+
value: props.value,
|
|
1243
|
+
onChange: (event) => props.onChange(event.target.value)
|
|
1244
|
+
}, ...props.options.map(([value, words]) => createElement("option", {
|
|
1245
|
+
key: value,
|
|
1246
|
+
value
|
|
1247
|
+
}, words))), createElement(Icon, { name: "grabber" }));
|
|
782
1248
|
}
|
|
783
1249
|
/** Which organization the person works in, or their personal account; and making a new one. */
|
|
784
1250
|
function OrganizationSwitcher() {
|
|
785
1251
|
const { client, signedIn, refresh } = useAuth();
|
|
1252
|
+
const root = useRoot();
|
|
786
1253
|
const [organizations, setOrganizations] = useState([]);
|
|
787
1254
|
const [creating, setCreating] = useState(false), [name, setName] = useState("");
|
|
788
1255
|
const call = useCall();
|
|
@@ -791,51 +1258,70 @@ function OrganizationSwitcher() {
|
|
|
791
1258
|
}, [client, signedIn]);
|
|
792
1259
|
if (!signedIn) return null;
|
|
793
1260
|
const active = signedIn.session.activeOrganizationId ?? "";
|
|
794
|
-
const slug = name.trim().toLowerCase().replace(/[^a-z0-9]+/
|
|
1261
|
+
const slug = name.trim().toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-+|-+$/gu, "").slice(0, 48);
|
|
795
1262
|
return createElement("div", {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
}
|
|
801
|
-
}, createElement("label", null, WORDS.organizations.switch, createElement("select", {
|
|
1263
|
+
...root,
|
|
1264
|
+
className: "msa msa-switcher"
|
|
1265
|
+
}, createElement(Select, {
|
|
1266
|
+
label: WORDS.organizations.switch,
|
|
802
1267
|
value: active,
|
|
803
|
-
onChange: (
|
|
804
|
-
await client.organizations.setActive(
|
|
1268
|
+
onChange: (value) => void call.run(async () => {
|
|
1269
|
+
await client.organizations.setActive(value || null);
|
|
805
1270
|
await refresh();
|
|
806
|
-
})
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
1271
|
+
}),
|
|
1272
|
+
options: [["", WORDS.organizations.personal], ...organizations.map((one) => [one.id, one.name])]
|
|
1273
|
+
}), creating ? createElement("form", {
|
|
1274
|
+
className: "msa-switcher-form",
|
|
1275
|
+
noValidate: true,
|
|
1276
|
+
onSubmit: onSubmit(() => void call.run(async () => {
|
|
1277
|
+
const made = await client.organizations.create({
|
|
1278
|
+
name: name.trim(),
|
|
1279
|
+
slug
|
|
1280
|
+
});
|
|
1281
|
+
await client.organizations.setActive(made.id);
|
|
1282
|
+
setOrganizations([...organizations, made]);
|
|
1283
|
+
setCreating(false);
|
|
1284
|
+
setName("");
|
|
1285
|
+
await refresh();
|
|
1286
|
+
}))
|
|
1287
|
+
}, createElement(Field, {
|
|
821
1288
|
label: WORDS.fields.organization,
|
|
822
1289
|
value: name,
|
|
823
|
-
onChange: setName
|
|
824
|
-
|
|
1290
|
+
onChange: setName,
|
|
1291
|
+
placeholder: WORDS.placeholders.organization,
|
|
1292
|
+
autoFocus: true
|
|
1293
|
+
}), createElement("button", {
|
|
1294
|
+
type: "button",
|
|
1295
|
+
className: "msa-button msa-ghost",
|
|
1296
|
+
onClick: () => {
|
|
1297
|
+
setCreating(false);
|
|
1298
|
+
setName("");
|
|
1299
|
+
}
|
|
1300
|
+
}, WORDS.account.cancel), createElement("button", {
|
|
825
1301
|
type: "submit",
|
|
826
|
-
|
|
827
|
-
|
|
1302
|
+
className: "msa-button msa-primary",
|
|
1303
|
+
disabled: !slug,
|
|
1304
|
+
"aria-busy": call.busy || void 0
|
|
1305
|
+
}, WORDS.organizations.create)) : createElement("button", {
|
|
828
1306
|
type: "button",
|
|
829
|
-
className: "msa-
|
|
1307
|
+
className: "msa-button msa-secondary",
|
|
830
1308
|
onClick: () => setCreating(true)
|
|
831
|
-
}, WORDS.organizations.create)
|
|
1309
|
+
}, createElement(Icon, { name: "plus" }), WORDS.organizations.create), createElement(Problem, { message: call.error }));
|
|
832
1310
|
}
|
|
833
1311
|
/** One organization: its name, its members and their roles, and its invitations. The active one unless `organizationId` names another. */
|
|
834
1312
|
function OrganizationProfile(props) {
|
|
835
1313
|
const { client, signedIn, refresh } = useAuth();
|
|
836
|
-
const
|
|
1314
|
+
const root = useRoot(true);
|
|
1315
|
+
const [organization, setOrganization] = useState(void 0);
|
|
837
1316
|
const [email, setEmail] = useState(""), [role, setRole] = useState("member"), [name, setName] = useState("");
|
|
1317
|
+
const [saved, showSaved] = useDone();
|
|
838
1318
|
const call = useCall();
|
|
1319
|
+
const [at, setAt] = useState("");
|
|
1320
|
+
const run = (panel, work) => {
|
|
1321
|
+
setAt(panel);
|
|
1322
|
+
return call.run(work);
|
|
1323
|
+
};
|
|
1324
|
+
const problemIn = (panel) => at === panel ? call.error : null;
|
|
839
1325
|
const id = props.organizationId ?? signedIn?.session.activeOrganizationId ?? void 0;
|
|
840
1326
|
const load = useCallback(async () => {
|
|
841
1327
|
const found = await client.organizations.get(id);
|
|
@@ -843,98 +1329,127 @@ function OrganizationProfile(props) {
|
|
|
843
1329
|
setName(found?.name ?? "");
|
|
844
1330
|
}, [client, id]);
|
|
845
1331
|
useEffect(() => {
|
|
846
|
-
if (signedIn && id) load().catch(() =>
|
|
1332
|
+
if (signedIn && id) load().catch(() => setOrganization(null));
|
|
847
1333
|
}, [
|
|
848
1334
|
signedIn,
|
|
849
1335
|
id,
|
|
850
1336
|
load
|
|
851
1337
|
]);
|
|
852
|
-
if (
|
|
1338
|
+
if (signedIn === null || !id || organization === null) return null;
|
|
1339
|
+
if (!signedIn || !organization) return createElement(PageLoading, { label: WORDS.organizations.settings });
|
|
853
1340
|
const me = organization.members.find((member) => member.userId === signedIn.user.id);
|
|
854
1341
|
const manages = me?.role === "owner" || me?.role === "admin";
|
|
855
1342
|
const roles = WORDS.organizations.roles;
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1343
|
+
const roleOptions = Object.keys(roles).map((one) => [one, roles[one]]);
|
|
1344
|
+
const pending = organization.invitations.filter((one) => one.status === "pending");
|
|
1345
|
+
return createElement("div", root, createElement("div", { className: "msa-page" }, createElement("header", { className: "msa-identity" }, createElement(Avatar, {
|
|
1346
|
+
name: organization.name,
|
|
1347
|
+
image: organization.logo,
|
|
1348
|
+
size: "large",
|
|
1349
|
+
square: true
|
|
1350
|
+
}), createElement("div", { className: "msa-identity-copy" }, createElement("h1", { className: "msa-identity-name" }, organization.name), createElement("p", { className: "msa-identity-detail" }, organization.slug))), manages ? createElement("form", {
|
|
1351
|
+
noValidate: true,
|
|
1352
|
+
onSubmit: onSubmit(() => void run("organization", async () => {
|
|
1353
|
+
await client.organizations.update(organization.id, { name: name.trim() });
|
|
1354
|
+
await load();
|
|
1355
|
+
showSaved();
|
|
1356
|
+
}))
|
|
1357
|
+
}, createElement(Panel, {
|
|
1358
|
+
title: WORDS.organizations.settings,
|
|
1359
|
+
problem: problemIn("organization"),
|
|
1360
|
+
foot: createElement("button", {
|
|
1361
|
+
type: "submit",
|
|
1362
|
+
className: "msa-button msa-secondary msa-small",
|
|
1363
|
+
disabled: !saved && (!name.trim() || name.trim() === organization.name)
|
|
1364
|
+
}, saved ? WORDS.account.saved : WORDS.organizations.save)
|
|
1365
|
+
}, createElement(FieldRow, {
|
|
863
1366
|
label: WORDS.fields.organization,
|
|
864
1367
|
value: name,
|
|
865
1368
|
onChange: setName
|
|
866
|
-
})
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
},
|
|
1369
|
+
}))) : null, createElement(Panel, {
|
|
1370
|
+
title: WORDS.organizations.members,
|
|
1371
|
+
problem: problemIn("members")
|
|
1372
|
+
}, ...organization.members.map((member) => createElement(Row, {
|
|
870
1373
|
key: member.id,
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
})
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
})) : createElement("span", null, roles[member.role] ?? member.role)))), manages ? createElement("section", { "aria-labelledby": "msa-invitations" }, createElement("h2", { id: "msa-invitations" }, WORDS.organizations.invitations), organization.invitations.filter((one) => one.status === "pending").map((one) => createElement("div", {
|
|
895
|
-
key: one.id,
|
|
896
|
-
className: "msa-row"
|
|
897
|
-
}, createElement("div", null, createElement("strong", null, one.email), createElement("span", null, roles[one.role ?? "member"])), createElement("button", {
|
|
898
|
-
type: "button",
|
|
899
|
-
className: "msa-quiet msa-danger",
|
|
900
|
-
onClick: () => void call.run(async () => {
|
|
901
|
-
await client.organizations.cancelInvitation(one.id);
|
|
902
|
-
await load();
|
|
903
|
-
})
|
|
904
|
-
}, WORDS.organizations.cancel))), createElement("form", {
|
|
905
|
-
style: { marginTop: 12 },
|
|
906
|
-
onSubmit: onSubmit(() => void call.run(async () => {
|
|
1374
|
+
title: member.user.name || member.user.email,
|
|
1375
|
+
detail: member.user.name ? member.user.email : void 0,
|
|
1376
|
+
control: manages && member.userId !== signedIn.user.id ? createElement(Fragment, null, createElement(Select, {
|
|
1377
|
+
small: true,
|
|
1378
|
+
label: `${WORDS.fields.role}, ${member.user.email}`,
|
|
1379
|
+
value: member.role,
|
|
1380
|
+
options: roleOptions,
|
|
1381
|
+
onChange: (value) => void run("members", async () => {
|
|
1382
|
+
await client.organizations.setRole(organization.id, member.id, value);
|
|
1383
|
+
await load();
|
|
1384
|
+
})
|
|
1385
|
+
}), createElement(Confirm, {
|
|
1386
|
+
label: WORDS.organizations.remove,
|
|
1387
|
+
confirm: WORDS.organizations.removeForGood,
|
|
1388
|
+
busy: call.busy,
|
|
1389
|
+
onConfirm: () => void run("members", async () => {
|
|
1390
|
+
await client.organizations.removeMember(organization.id, member.id);
|
|
1391
|
+
await load();
|
|
1392
|
+
})
|
|
1393
|
+
})) : createElement("span", { className: "msa-tag" }, member.userId === signedIn.user.id ? `${WORDS.organizations.you} · ${roles[member.role] ?? member.role}` : roles[member.role] ?? member.role)
|
|
1394
|
+
}))), manages ? createElement("form", {
|
|
1395
|
+
noValidate: true,
|
|
1396
|
+
onSubmit: onSubmit(() => void run("invitations", async () => {
|
|
907
1397
|
await client.organizations.invite(organization.id, {
|
|
908
|
-
email,
|
|
1398
|
+
email: email.trim(),
|
|
909
1399
|
role
|
|
910
1400
|
});
|
|
911
1401
|
setEmail("");
|
|
912
1402
|
await load();
|
|
913
1403
|
}))
|
|
914
|
-
}, createElement(
|
|
1404
|
+
}, createElement(Panel, {
|
|
1405
|
+
title: WORDS.organizations.invitations,
|
|
1406
|
+
problem: problemIn("invitations"),
|
|
1407
|
+
foot: createElement("button", {
|
|
1408
|
+
type: "submit",
|
|
1409
|
+
className: "msa-button msa-secondary msa-small",
|
|
1410
|
+
disabled: !email.trim()
|
|
1411
|
+
}, WORDS.organizations.invite)
|
|
1412
|
+
}, ...pending.map((one) => createElement(Row, {
|
|
1413
|
+
key: one.id,
|
|
1414
|
+
title: one.email,
|
|
1415
|
+
detail: roles[one.role ?? "member"],
|
|
1416
|
+
control: createElement("button", {
|
|
1417
|
+
type: "button",
|
|
1418
|
+
className: "msa-button msa-ghost msa-small",
|
|
1419
|
+
onClick: () => void run("invitations", async () => {
|
|
1420
|
+
await client.organizations.cancelInvitation(one.id);
|
|
1421
|
+
await load();
|
|
1422
|
+
})
|
|
1423
|
+
}, WORDS.organizations.cancel)
|
|
1424
|
+
})), createElement(FieldRow, {
|
|
915
1425
|
label: WORDS.fields.inviteEmail,
|
|
916
1426
|
type: "email",
|
|
917
1427
|
value: email,
|
|
918
1428
|
onChange: setEmail,
|
|
919
|
-
|
|
920
|
-
}), createElement(
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1429
|
+
placeholder: WORDS.placeholders.email
|
|
1430
|
+
}), createElement(Row, {
|
|
1431
|
+
title: WORDS.fields.role,
|
|
1432
|
+
control: createElement(Select, {
|
|
1433
|
+
small: true,
|
|
1434
|
+
label: WORDS.fields.role,
|
|
1435
|
+
value: role,
|
|
1436
|
+
options: roleOptions,
|
|
1437
|
+
onChange: (value) => setRole(value)
|
|
1438
|
+
})
|
|
1439
|
+
}))) : null, me && me.role !== "owner" ? createElement(Panel, {
|
|
1440
|
+
title: WORDS.organizations.leave,
|
|
1441
|
+
tone: "danger",
|
|
1442
|
+
problem: problemIn("leave"),
|
|
1443
|
+
action: createElement(Confirm, {
|
|
1444
|
+
label: WORDS.organizations.leave,
|
|
1445
|
+
confirm: WORDS.organizations.leaveForGood,
|
|
1446
|
+
busy: call.busy,
|
|
1447
|
+
onConfirm: () => void run("leave", async () => {
|
|
1448
|
+
await client.organizations.leave(organization.id);
|
|
1449
|
+
await refresh();
|
|
1450
|
+
})
|
|
936
1451
|
})
|
|
937
|
-
})
|
|
1452
|
+
}) : null));
|
|
938
1453
|
}
|
|
939
1454
|
//#endregion
|
|
940
1455
|
export { AuthProvider, OrganizationProfile, OrganizationSwitcher, SignIn, SignUp, UserButton, UserProfile, useAuth };
|