@nexys/user-management-web 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -0
- package/components.json +21 -0
- package/package.json +66 -0
- package/src/components/audit/audit-log-table.test.tsx +91 -0
- package/src/components/audit/audit-log-table.tsx +226 -0
- package/src/components/auth/accept-invitation-card.tsx +100 -0
- package/src/components/auth/forgot-password-form.tsx +92 -0
- package/src/components/auth/reset-password-form.tsx +143 -0
- package/src/components/auth/sign-in-form.test.tsx +140 -0
- package/src/components/auth/sign-in-form.tsx +509 -0
- package/src/components/auth/sign-up-form.tsx +123 -0
- package/src/components/layout/app-shell.tsx +189 -0
- package/src/components/layout/auth-shell.tsx +28 -0
- package/src/components/layout/theme-toggle.tsx +55 -0
- package/src/components/layout/user-menu.tsx +84 -0
- package/src/components/primitives/empty-state.tsx +40 -0
- package/src/components/primitives/page-header.tsx +27 -0
- package/src/components/primitives/spinner.tsx +28 -0
- package/src/components/profile/api-tokens-card.tsx +235 -0
- package/src/components/profile/change-password-form.tsx +158 -0
- package/src/components/profile/passkeys-card.tsx +180 -0
- package/src/components/profile/profile-card.tsx +33 -0
- package/src/components/profile/two-factor-card.tsx +226 -0
- package/src/components/projects/project-consents.tsx +572 -0
- package/src/components/projects/project-create-dialog.tsx +209 -0
- package/src/components/projects/project-detail-tabs.tsx +63 -0
- package/src/components/projects/project-email-templates.tsx +282 -0
- package/src/components/projects/project-notices.tsx +458 -0
- package/src/components/projects/project-settings.tsx +1133 -0
- package/src/components/projects/project-tenants.tsx +107 -0
- package/src/components/projects/projects-table.test.tsx +95 -0
- package/src/components/projects/projects-table.tsx +240 -0
- package/src/components/roles/role-badge.tsx +91 -0
- package/src/components/roles/role-select.tsx +76 -0
- package/src/components/tenants/tenant-create-dialog.tsx +163 -0
- package/src/components/tenants/tenant-detail-tabs.tsx +51 -0
- package/src/components/tenants/tenant-members.tsx +578 -0
- package/src/components/tenants/tenant-roles.test.tsx +91 -0
- package/src/components/tenants/tenant-roles.tsx +414 -0
- package/src/components/tenants/tenant-settings.tsx +385 -0
- package/src/components/tenants/tenants-table.test.tsx +71 -0
- package/src/components/tenants/tenants-table.tsx +245 -0
- package/src/components/ui/alert.tsx +52 -0
- package/src/components/ui/avatar.tsx +46 -0
- package/src/components/ui/badge.tsx +32 -0
- package/src/components/ui/button.tsx +64 -0
- package/src/components/ui/card.tsx +65 -0
- package/src/components/ui/dialog.tsx +99 -0
- package/src/components/ui/dropdown-menu.tsx +97 -0
- package/src/components/ui/field.tsx +44 -0
- package/src/components/ui/input.tsx +23 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/select.tsx +87 -0
- package/src/components/ui/separator.tsx +22 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/table.tsx +87 -0
- package/src/components/ui/tabs.tsx +51 -0
- package/src/components/ui/textarea.tsx +22 -0
- package/src/components/ui/tooltip.tsx +27 -0
- package/src/components/users/user-create-dialog.tsx +267 -0
- package/src/components/users/user-delete-dialog.tsx +88 -0
- package/src/components/users/user-detail.tsx +843 -0
- package/src/components/users/users-table.test.tsx +97 -0
- package/src/components/users/users-table.tsx +382 -0
- package/src/context/auth-context.tsx +124 -0
- package/src/context/theme-context.test.tsx +78 -0
- package/src/context/theme-context.tsx +110 -0
- package/src/hooks/use-call.ts +64 -0
- package/src/index.ts +159 -0
- package/src/lib/error-message.ts +16 -0
- package/src/lib/utils.test.ts +61 -0
- package/src/lib/utils.ts +79 -0
- package/src/lib/webauthn.ts +36 -0
- package/src/styles.css +107 -0
- package/src/test-setup.ts +5 -0
- package/tailwind.preset.cjs +15 -0
|
@@ -0,0 +1,1133 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type SocialConnectionRow,
|
|
3
|
+
type TenancyMode,
|
|
4
|
+
} from "@nexys/user-management-client";
|
|
5
|
+
import { AlertCircle, Check, Copy, Pencil, Save, Trash2 } from "lucide-react";
|
|
6
|
+
import { useEffect, useState, type FormEvent } from "react";
|
|
7
|
+
|
|
8
|
+
import { useUmClient } from "../../context/auth-context.js";
|
|
9
|
+
import { useCall } from "../../hooks/use-call.js";
|
|
10
|
+
import { errorMessage } from "../../lib/error-message.js";
|
|
11
|
+
import { Alert, AlertDescription } from "../ui/alert.js";
|
|
12
|
+
import { Badge } from "../ui/badge.js";
|
|
13
|
+
import { Button } from "../ui/button.js";
|
|
14
|
+
import {
|
|
15
|
+
Card,
|
|
16
|
+
CardContent,
|
|
17
|
+
CardDescription,
|
|
18
|
+
CardHeader,
|
|
19
|
+
CardTitle,
|
|
20
|
+
} from "../ui/card.js";
|
|
21
|
+
import {
|
|
22
|
+
Dialog,
|
|
23
|
+
DialogClose,
|
|
24
|
+
DialogContent,
|
|
25
|
+
DialogDescription,
|
|
26
|
+
DialogFooter,
|
|
27
|
+
DialogHeader,
|
|
28
|
+
DialogTitle,
|
|
29
|
+
DialogTrigger,
|
|
30
|
+
} from "../ui/dialog.js";
|
|
31
|
+
import { Field } from "../ui/field.js";
|
|
32
|
+
import { Input } from "../ui/input.js";
|
|
33
|
+
import { Label } from "../ui/label.js";
|
|
34
|
+
import {
|
|
35
|
+
Select,
|
|
36
|
+
SelectContent,
|
|
37
|
+
SelectItem,
|
|
38
|
+
SelectTrigger,
|
|
39
|
+
SelectValue,
|
|
40
|
+
} from "../ui/select.js";
|
|
41
|
+
import { Skeleton } from "../ui/skeleton.js";
|
|
42
|
+
import { Textarea } from "../ui/textarea.js";
|
|
43
|
+
import { Switch } from "../ui/switch.js";
|
|
44
|
+
|
|
45
|
+
export interface ProjectSettingsProps {
|
|
46
|
+
projectId: string;
|
|
47
|
+
/** Allow editing (project owner or superadmin). */
|
|
48
|
+
canManage?: boolean;
|
|
49
|
+
canDelete?: boolean;
|
|
50
|
+
onDeleted?: () => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const ProjectSettings = ({
|
|
54
|
+
projectId,
|
|
55
|
+
canManage = false,
|
|
56
|
+
canDelete = false,
|
|
57
|
+
onDeleted,
|
|
58
|
+
}: ProjectSettingsProps) => {
|
|
59
|
+
const client = useUmClient();
|
|
60
|
+
const { data, loading, error, refresh } = useCall("getProject", { projectId });
|
|
61
|
+
const [copied, setCopied] = useState(false);
|
|
62
|
+
const [deleting, setDeleting] = useState(false);
|
|
63
|
+
const [deleteError, setDeleteError] = useState<string | null>(null);
|
|
64
|
+
|
|
65
|
+
const copyId = async () => {
|
|
66
|
+
await navigator.clipboard.writeText(projectId);
|
|
67
|
+
setCopied(true);
|
|
68
|
+
setTimeout(() => setCopied(false), 2000);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const handleDelete = async () => {
|
|
72
|
+
setDeleting(true);
|
|
73
|
+
setDeleteError(null);
|
|
74
|
+
const res = await client.deleteProject({ projectId });
|
|
75
|
+
setDeleting(false);
|
|
76
|
+
if (res.ok) {
|
|
77
|
+
onDeleted?.();
|
|
78
|
+
} else {
|
|
79
|
+
setDeleteError(errorMessage(res.error, "Failed to delete product."));
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
if (error) {
|
|
84
|
+
return (
|
|
85
|
+
<Alert variant="destructive">
|
|
86
|
+
<AlertCircle />
|
|
87
|
+
<AlertDescription>{errorMessage(error)}</AlertDescription>
|
|
88
|
+
</Alert>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div className="grid gap-6">
|
|
94
|
+
<Card>
|
|
95
|
+
<CardHeader>
|
|
96
|
+
<CardTitle>General</CardTitle>
|
|
97
|
+
<CardDescription>
|
|
98
|
+
{canManage ? "Update product information" : "Product information"}
|
|
99
|
+
</CardDescription>
|
|
100
|
+
</CardHeader>
|
|
101
|
+
<CardContent className="grid gap-4">
|
|
102
|
+
{loading ? (
|
|
103
|
+
<>
|
|
104
|
+
<Skeleton className="h-5 w-48" />
|
|
105
|
+
<Skeleton className="h-5 w-32" />
|
|
106
|
+
<Skeleton className="h-5 w-64" />
|
|
107
|
+
</>
|
|
108
|
+
) : data ? (
|
|
109
|
+
<>
|
|
110
|
+
{canManage ? (
|
|
111
|
+
<GeneralForm
|
|
112
|
+
projectId={projectId}
|
|
113
|
+
name={data.name}
|
|
114
|
+
slug={data.slug}
|
|
115
|
+
onSaved={refresh}
|
|
116
|
+
/>
|
|
117
|
+
) : (
|
|
118
|
+
<>
|
|
119
|
+
<div className="grid gap-1">
|
|
120
|
+
<Label className="text-muted-foreground text-xs">Name</Label>
|
|
121
|
+
<p className="text-sm font-medium">{data.name}</p>
|
|
122
|
+
</div>
|
|
123
|
+
<div className="grid gap-1">
|
|
124
|
+
<Label className="text-muted-foreground text-xs">Slug</Label>
|
|
125
|
+
<p className="font-mono text-sm">{data.slug}</p>
|
|
126
|
+
</div>
|
|
127
|
+
</>
|
|
128
|
+
)}
|
|
129
|
+
<div className="grid gap-1">
|
|
130
|
+
<Label className="text-muted-foreground text-xs">UUID</Label>
|
|
131
|
+
<div className="flex items-center gap-2">
|
|
132
|
+
<code className="rounded bg-muted px-2 py-1 font-mono text-xs">
|
|
133
|
+
{projectId}
|
|
134
|
+
</code>
|
|
135
|
+
<Button
|
|
136
|
+
variant="ghost"
|
|
137
|
+
size="icon"
|
|
138
|
+
className="size-7"
|
|
139
|
+
onClick={copyId}
|
|
140
|
+
aria-label="Copy UUID"
|
|
141
|
+
>
|
|
142
|
+
{copied ? (
|
|
143
|
+
<Check className="size-3.5 text-green-600" />
|
|
144
|
+
) : (
|
|
145
|
+
<Copy className="size-3.5" />
|
|
146
|
+
)}
|
|
147
|
+
</Button>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
</>
|
|
151
|
+
) : null}
|
|
152
|
+
</CardContent>
|
|
153
|
+
</Card>
|
|
154
|
+
|
|
155
|
+
{data ? (
|
|
156
|
+
<Card>
|
|
157
|
+
<CardHeader>
|
|
158
|
+
<CardTitle>Tenancy & access</CardTitle>
|
|
159
|
+
<CardDescription>
|
|
160
|
+
How tenants and sign-ups behave inside this product.
|
|
161
|
+
</CardDescription>
|
|
162
|
+
</CardHeader>
|
|
163
|
+
<CardContent>
|
|
164
|
+
<TenancyForm
|
|
165
|
+
key={data.updatedAt}
|
|
166
|
+
projectId={projectId}
|
|
167
|
+
tenancyMode={data.tenancyMode}
|
|
168
|
+
allowSignup={data.allowSignup}
|
|
169
|
+
allowTenantCreation={data.allowTenantCreation}
|
|
170
|
+
canManage={canManage}
|
|
171
|
+
onSaved={refresh}
|
|
172
|
+
/>
|
|
173
|
+
</CardContent>
|
|
174
|
+
</Card>
|
|
175
|
+
) : null}
|
|
176
|
+
|
|
177
|
+
{data ? (
|
|
178
|
+
<Card>
|
|
179
|
+
<CardHeader>
|
|
180
|
+
<CardTitle>Localisation & retention</CardTitle>
|
|
181
|
+
<CardDescription>
|
|
182
|
+
The locale users inherit when they set none of their own, and
|
|
183
|
+
how long this product keeps its audit logs.
|
|
184
|
+
</CardDescription>
|
|
185
|
+
</CardHeader>
|
|
186
|
+
<CardContent>
|
|
187
|
+
<LocaleRetentionForm
|
|
188
|
+
key={data.updatedAt}
|
|
189
|
+
projectId={projectId}
|
|
190
|
+
defaultLocale={data.defaultLocale}
|
|
191
|
+
logRetentionDays={data.logRetentionDays}
|
|
192
|
+
canManage={canManage}
|
|
193
|
+
onSaved={refresh}
|
|
194
|
+
/>
|
|
195
|
+
</CardContent>
|
|
196
|
+
</Card>
|
|
197
|
+
) : null}
|
|
198
|
+
|
|
199
|
+
{data ? (
|
|
200
|
+
<Card>
|
|
201
|
+
<CardHeader>
|
|
202
|
+
<CardTitle>Trusted origins</CardTitle>
|
|
203
|
+
<CardDescription>
|
|
204
|
+
Where this product's apps run. Requests naming this product
|
|
205
|
+
from one of these origins can scope passkeys to it, receive the
|
|
206
|
+
emailed sign-in link through it, land back on it and pass CORS,
|
|
207
|
+
without touching the deployment's own TRUSTED_ORIGINS.
|
|
208
|
+
</CardDescription>
|
|
209
|
+
</CardHeader>
|
|
210
|
+
<CardContent>
|
|
211
|
+
<TrustedOriginsForm
|
|
212
|
+
key={data.updatedAt}
|
|
213
|
+
projectId={projectId}
|
|
214
|
+
trustedOrigins={data.trustedOrigins}
|
|
215
|
+
canManage={canManage}
|
|
216
|
+
onSaved={refresh}
|
|
217
|
+
/>
|
|
218
|
+
</CardContent>
|
|
219
|
+
</Card>
|
|
220
|
+
) : null}
|
|
221
|
+
|
|
222
|
+
{data ? (
|
|
223
|
+
<Card>
|
|
224
|
+
<CardHeader>
|
|
225
|
+
<CardTitle>Single sign-on</CardTitle>
|
|
226
|
+
<CardDescription>
|
|
227
|
+
Social login providers for this product, each with its own
|
|
228
|
+
OAuth client.
|
|
229
|
+
</CardDescription>
|
|
230
|
+
</CardHeader>
|
|
231
|
+
<CardContent>
|
|
232
|
+
<SocialConnections projectId={projectId} canManage={canManage} />
|
|
233
|
+
</CardContent>
|
|
234
|
+
</Card>
|
|
235
|
+
) : null}
|
|
236
|
+
|
|
237
|
+
{canDelete && (
|
|
238
|
+
<Card className="border-destructive/50">
|
|
239
|
+
<CardHeader>
|
|
240
|
+
<CardTitle className="text-destructive">Danger zone</CardTitle>
|
|
241
|
+
<CardDescription>
|
|
242
|
+
Deleting a product removes every tenant inside it (cascade).
|
|
243
|
+
This action cannot be undone.
|
|
244
|
+
</CardDescription>
|
|
245
|
+
</CardHeader>
|
|
246
|
+
<CardContent>
|
|
247
|
+
{deleteError && (
|
|
248
|
+
<Alert variant="destructive" className="mb-4">
|
|
249
|
+
<AlertCircle />
|
|
250
|
+
<AlertDescription>{deleteError}</AlertDescription>
|
|
251
|
+
</Alert>
|
|
252
|
+
)}
|
|
253
|
+
<Dialog>
|
|
254
|
+
<DialogTrigger asChild>
|
|
255
|
+
<Button variant="destructive">
|
|
256
|
+
<Trash2 /> Delete product
|
|
257
|
+
</Button>
|
|
258
|
+
</DialogTrigger>
|
|
259
|
+
<DialogContent>
|
|
260
|
+
<DialogHeader>
|
|
261
|
+
<DialogTitle>Delete product?</DialogTitle>
|
|
262
|
+
<DialogDescription>
|
|
263
|
+
This will permanently delete{" "}
|
|
264
|
+
<strong>{data?.name ?? "this product"}</strong> and every
|
|
265
|
+
tenant inside it. This action cannot be undone.
|
|
266
|
+
</DialogDescription>
|
|
267
|
+
</DialogHeader>
|
|
268
|
+
<DialogFooter>
|
|
269
|
+
<DialogClose asChild>
|
|
270
|
+
<Button variant="outline">Cancel</Button>
|
|
271
|
+
</DialogClose>
|
|
272
|
+
<Button
|
|
273
|
+
variant="destructive"
|
|
274
|
+
onClick={handleDelete}
|
|
275
|
+
loading={deleting}
|
|
276
|
+
>
|
|
277
|
+
Delete permanently
|
|
278
|
+
</Button>
|
|
279
|
+
</DialogFooter>
|
|
280
|
+
</DialogContent>
|
|
281
|
+
</Dialog>
|
|
282
|
+
</CardContent>
|
|
283
|
+
</Card>
|
|
284
|
+
)}
|
|
285
|
+
</div>
|
|
286
|
+
);
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const GeneralForm = ({
|
|
290
|
+
projectId,
|
|
291
|
+
name: initialName,
|
|
292
|
+
slug: initialSlug,
|
|
293
|
+
onSaved,
|
|
294
|
+
}: {
|
|
295
|
+
projectId: string;
|
|
296
|
+
name: string;
|
|
297
|
+
slug: string;
|
|
298
|
+
onSaved: () => void;
|
|
299
|
+
}) => {
|
|
300
|
+
const client = useUmClient();
|
|
301
|
+
const [name, setName] = useState(initialName);
|
|
302
|
+
const [slug, setSlug] = useState(initialSlug);
|
|
303
|
+
const [saving, setSaving] = useState(false);
|
|
304
|
+
const [saved, setSaved] = useState(false);
|
|
305
|
+
const [error, setError] = useState<string | null>(null);
|
|
306
|
+
|
|
307
|
+
// Server data refreshed underneath us (e.g. another tab saved) —
|
|
308
|
+
// resync untouched fields.
|
|
309
|
+
useEffect(() => setName(initialName), [initialName]);
|
|
310
|
+
useEffect(() => setSlug(initialSlug), [initialSlug]);
|
|
311
|
+
|
|
312
|
+
const dirty = name.trim() !== initialName || slug.trim() !== initialSlug;
|
|
313
|
+
|
|
314
|
+
const submit = async (e: FormEvent) => {
|
|
315
|
+
e.preventDefault();
|
|
316
|
+
setSaving(true);
|
|
317
|
+
setError(null);
|
|
318
|
+
setSaved(false);
|
|
319
|
+
const res = await client.updateProject({
|
|
320
|
+
projectId,
|
|
321
|
+
name: name.trim(),
|
|
322
|
+
slug: slug.trim(),
|
|
323
|
+
});
|
|
324
|
+
setSaving(false);
|
|
325
|
+
if (res.ok) {
|
|
326
|
+
setSaved(true);
|
|
327
|
+
setTimeout(() => setSaved(false), 2000);
|
|
328
|
+
onSaved();
|
|
329
|
+
} else {
|
|
330
|
+
setError(errorMessage(res.error, "Couldn't save product settings."));
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
return (
|
|
335
|
+
<form onSubmit={submit} className="grid gap-4">
|
|
336
|
+
{error ? (
|
|
337
|
+
<Alert variant="destructive">
|
|
338
|
+
<AlertCircle />
|
|
339
|
+
<AlertDescription>{error}</AlertDescription>
|
|
340
|
+
</Alert>
|
|
341
|
+
) : null}
|
|
342
|
+
<div className="grid gap-4 sm:grid-cols-2">
|
|
343
|
+
<Field label="Name" htmlFor="project-name">
|
|
344
|
+
<Input
|
|
345
|
+
id="project-name"
|
|
346
|
+
required
|
|
347
|
+
value={name}
|
|
348
|
+
onChange={(e) => setName(e.target.value)}
|
|
349
|
+
/>
|
|
350
|
+
</Field>
|
|
351
|
+
<Field label="Slug" htmlFor="project-slug">
|
|
352
|
+
<Input
|
|
353
|
+
id="project-slug"
|
|
354
|
+
required
|
|
355
|
+
value={slug}
|
|
356
|
+
onChange={(e) => setSlug(e.target.value)}
|
|
357
|
+
className="font-mono"
|
|
358
|
+
/>
|
|
359
|
+
</Field>
|
|
360
|
+
</div>
|
|
361
|
+
<div className="flex items-center gap-3">
|
|
362
|
+
<Button
|
|
363
|
+
type="submit"
|
|
364
|
+
loading={saving}
|
|
365
|
+
disabled={!dirty || !name.trim() || !slug.trim()}
|
|
366
|
+
>
|
|
367
|
+
{saved ? <Check /> : <Save />}
|
|
368
|
+
{saved ? "Saved" : "Save changes"}
|
|
369
|
+
</Button>
|
|
370
|
+
</div>
|
|
371
|
+
</form>
|
|
372
|
+
);
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
const TenancyForm = ({
|
|
376
|
+
projectId,
|
|
377
|
+
tenancyMode: initialMode,
|
|
378
|
+
allowSignup: initialSignup,
|
|
379
|
+
allowTenantCreation: initialTenantCreation,
|
|
380
|
+
canManage,
|
|
381
|
+
onSaved,
|
|
382
|
+
}: {
|
|
383
|
+
projectId: string;
|
|
384
|
+
tenancyMode: TenancyMode;
|
|
385
|
+
allowSignup: boolean;
|
|
386
|
+
allowTenantCreation: boolean;
|
|
387
|
+
canManage: boolean;
|
|
388
|
+
onSaved: () => void;
|
|
389
|
+
}) => {
|
|
390
|
+
const client = useUmClient();
|
|
391
|
+
const [mode, setMode] = useState<TenancyMode>(initialMode);
|
|
392
|
+
const [signup, setSignup] = useState(initialSignup);
|
|
393
|
+
const [tenantCreation, setTenantCreation] = useState(initialTenantCreation);
|
|
394
|
+
const [saving, setSaving] = useState(false);
|
|
395
|
+
const [saved, setSaved] = useState(false);
|
|
396
|
+
const [error, setError] = useState<string | null>(null);
|
|
397
|
+
|
|
398
|
+
const dirty =
|
|
399
|
+
mode !== initialMode ||
|
|
400
|
+
signup !== initialSignup ||
|
|
401
|
+
tenantCreation !== initialTenantCreation;
|
|
402
|
+
|
|
403
|
+
const submit = async (e: FormEvent) => {
|
|
404
|
+
e.preventDefault();
|
|
405
|
+
setSaving(true);
|
|
406
|
+
setError(null);
|
|
407
|
+
setSaved(false);
|
|
408
|
+
const res = await client.updateProject({
|
|
409
|
+
projectId,
|
|
410
|
+
tenancyMode: mode,
|
|
411
|
+
allowSignup: signup,
|
|
412
|
+
allowTenantCreation: tenantCreation,
|
|
413
|
+
});
|
|
414
|
+
setSaving(false);
|
|
415
|
+
if (res.ok) {
|
|
416
|
+
setSaved(true);
|
|
417
|
+
setTimeout(() => setSaved(false), 2000);
|
|
418
|
+
onSaved();
|
|
419
|
+
} else {
|
|
420
|
+
setError(errorMessage(res.error, "Couldn't save tenancy settings."));
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
return (
|
|
425
|
+
<form onSubmit={submit} className="grid gap-4">
|
|
426
|
+
{error ? (
|
|
427
|
+
<Alert variant="destructive">
|
|
428
|
+
<AlertCircle />
|
|
429
|
+
<AlertDescription>{error}</AlertDescription>
|
|
430
|
+
</Alert>
|
|
431
|
+
) : null}
|
|
432
|
+
<Field
|
|
433
|
+
label="Tenancy mode"
|
|
434
|
+
htmlFor="project-tenancy-mode"
|
|
435
|
+
description="Single keeps the product to exactly one tenant. Narrowing to single is refused while the product holds more than one tenant."
|
|
436
|
+
>
|
|
437
|
+
<Select
|
|
438
|
+
value={mode}
|
|
439
|
+
onValueChange={(v) => setMode(v as TenancyMode)}
|
|
440
|
+
disabled={!canManage}
|
|
441
|
+
>
|
|
442
|
+
<SelectTrigger id="project-tenancy-mode" className="w-[12rem]">
|
|
443
|
+
<SelectValue />
|
|
444
|
+
</SelectTrigger>
|
|
445
|
+
<SelectContent>
|
|
446
|
+
<SelectItem value="multi">Multi-tenant</SelectItem>
|
|
447
|
+
<SelectItem value="single">Single tenant</SelectItem>
|
|
448
|
+
</SelectContent>
|
|
449
|
+
</Select>
|
|
450
|
+
</Field>
|
|
451
|
+
<div className="flex items-center justify-between gap-4">
|
|
452
|
+
<div className="grid gap-0.5">
|
|
453
|
+
<Label htmlFor="project-signup">Open sign-up</Label>
|
|
454
|
+
<p className="text-muted-foreground text-xs">
|
|
455
|
+
Allow self-service sign-up scoped to this product.
|
|
456
|
+
</p>
|
|
457
|
+
</div>
|
|
458
|
+
<Switch
|
|
459
|
+
id="project-signup"
|
|
460
|
+
checked={signup}
|
|
461
|
+
onCheckedChange={setSignup}
|
|
462
|
+
disabled={!canManage}
|
|
463
|
+
/>
|
|
464
|
+
</div>
|
|
465
|
+
<div className="flex items-center justify-between gap-4">
|
|
466
|
+
<div className="grid gap-0.5">
|
|
467
|
+
<Label htmlFor="project-tenant-creation">Self-serve tenants</Label>
|
|
468
|
+
<p className="text-muted-foreground text-xs">
|
|
469
|
+
Allow any authenticated user to create a tenant inside this
|
|
470
|
+
product.
|
|
471
|
+
</p>
|
|
472
|
+
</div>
|
|
473
|
+
<Switch
|
|
474
|
+
id="project-tenant-creation"
|
|
475
|
+
checked={tenantCreation}
|
|
476
|
+
onCheckedChange={setTenantCreation}
|
|
477
|
+
disabled={!canManage}
|
|
478
|
+
/>
|
|
479
|
+
</div>
|
|
480
|
+
{canManage ? (
|
|
481
|
+
<div className="flex items-center gap-3">
|
|
482
|
+
<Button type="submit" loading={saving} disabled={!dirty}>
|
|
483
|
+
{saved ? <Check /> : <Save />}
|
|
484
|
+
{saved ? "Saved" : "Save changes"}
|
|
485
|
+
</Button>
|
|
486
|
+
</div>
|
|
487
|
+
) : null}
|
|
488
|
+
</form>
|
|
489
|
+
);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
/// Product default locale (which email-template variant its users get)
|
|
493
|
+
/// plus how long its audit logs are kept.
|
|
494
|
+
const LocaleRetentionForm = ({
|
|
495
|
+
projectId,
|
|
496
|
+
defaultLocale: initialLocale,
|
|
497
|
+
logRetentionDays: initialRetention,
|
|
498
|
+
canManage,
|
|
499
|
+
onSaved,
|
|
500
|
+
}: {
|
|
501
|
+
projectId: string;
|
|
502
|
+
defaultLocale: string;
|
|
503
|
+
logRetentionDays: number;
|
|
504
|
+
canManage: boolean;
|
|
505
|
+
onSaved: () => void;
|
|
506
|
+
}) => {
|
|
507
|
+
const client = useUmClient();
|
|
508
|
+
const [locale, setLocale] = useState(initialLocale);
|
|
509
|
+
const [retention, setRetention] = useState(String(initialRetention));
|
|
510
|
+
const [saving, setSaving] = useState(false);
|
|
511
|
+
const [saved, setSaved] = useState(false);
|
|
512
|
+
const [error, setError] = useState<string | null>(null);
|
|
513
|
+
|
|
514
|
+
const retentionNum = Number(retention);
|
|
515
|
+
const retentionValid =
|
|
516
|
+
retention.trim() !== "" &&
|
|
517
|
+
Number.isInteger(retentionNum) &&
|
|
518
|
+
retentionNum >= 0 &&
|
|
519
|
+
retentionNum <= 3650;
|
|
520
|
+
const dirty =
|
|
521
|
+
locale.trim().toLowerCase() !== initialLocale ||
|
|
522
|
+
retentionNum !== initialRetention;
|
|
523
|
+
|
|
524
|
+
const submit = async (e: FormEvent) => {
|
|
525
|
+
e.preventDefault();
|
|
526
|
+
setSaving(true);
|
|
527
|
+
setError(null);
|
|
528
|
+
setSaved(false);
|
|
529
|
+
const res = await client.updateProject({
|
|
530
|
+
projectId,
|
|
531
|
+
defaultLocale: locale.trim().toLowerCase(),
|
|
532
|
+
logRetentionDays: retentionNum,
|
|
533
|
+
});
|
|
534
|
+
setSaving(false);
|
|
535
|
+
if (res.ok) {
|
|
536
|
+
setSaved(true);
|
|
537
|
+
setTimeout(() => setSaved(false), 2000);
|
|
538
|
+
onSaved();
|
|
539
|
+
} else {
|
|
540
|
+
setError(errorMessage(res.error, "Couldn't save these settings."));
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
return (
|
|
545
|
+
<form onSubmit={submit} className="grid gap-4">
|
|
546
|
+
{error ? (
|
|
547
|
+
<Alert variant="destructive">
|
|
548
|
+
<AlertCircle />
|
|
549
|
+
<AlertDescription>{error}</AlertDescription>
|
|
550
|
+
</Alert>
|
|
551
|
+
) : null}
|
|
552
|
+
<div className="grid gap-4 sm:grid-cols-2">
|
|
553
|
+
<Field
|
|
554
|
+
label="Default locale"
|
|
555
|
+
htmlFor="project-locale"
|
|
556
|
+
description="Language tag (e.g. en, fr-CA) for users who set none of their own."
|
|
557
|
+
>
|
|
558
|
+
<Input
|
|
559
|
+
id="project-locale"
|
|
560
|
+
value={locale}
|
|
561
|
+
onChange={(e) => setLocale(e.target.value)}
|
|
562
|
+
disabled={!canManage}
|
|
563
|
+
placeholder="en"
|
|
564
|
+
className="font-mono"
|
|
565
|
+
/>
|
|
566
|
+
</Field>
|
|
567
|
+
<Field
|
|
568
|
+
label="Log retention (days)"
|
|
569
|
+
htmlFor="project-log-retention"
|
|
570
|
+
description="How long audit logs for this product's tenants are kept. 0 keeps them forever."
|
|
571
|
+
>
|
|
572
|
+
<Input
|
|
573
|
+
id="project-log-retention"
|
|
574
|
+
type="number"
|
|
575
|
+
min={0}
|
|
576
|
+
max={3650}
|
|
577
|
+
value={retention}
|
|
578
|
+
onChange={(e) => setRetention(e.target.value)}
|
|
579
|
+
disabled={!canManage}
|
|
580
|
+
aria-invalid={!retentionValid}
|
|
581
|
+
/>
|
|
582
|
+
</Field>
|
|
583
|
+
</div>
|
|
584
|
+
{canManage ? (
|
|
585
|
+
<div className="flex items-center gap-3">
|
|
586
|
+
<Button
|
|
587
|
+
type="submit"
|
|
588
|
+
loading={saving}
|
|
589
|
+
disabled={!dirty || !locale.trim() || !retentionValid}
|
|
590
|
+
>
|
|
591
|
+
{saved ? <Check /> : <Save />}
|
|
592
|
+
{saved ? "Saved" : "Save changes"}
|
|
593
|
+
</Button>
|
|
594
|
+
</div>
|
|
595
|
+
) : null}
|
|
596
|
+
</form>
|
|
597
|
+
);
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
/// The product's trusted origins, one per line.
|
|
601
|
+
const TrustedOriginsForm = ({
|
|
602
|
+
projectId,
|
|
603
|
+
trustedOrigins: initialOrigins,
|
|
604
|
+
canManage,
|
|
605
|
+
onSaved,
|
|
606
|
+
}: {
|
|
607
|
+
projectId: string;
|
|
608
|
+
trustedOrigins: string[];
|
|
609
|
+
canManage: boolean;
|
|
610
|
+
onSaved: () => void;
|
|
611
|
+
}) => {
|
|
612
|
+
const client = useUmClient();
|
|
613
|
+
const [text, setText] = useState(initialOrigins.join("\n"));
|
|
614
|
+
const [saving, setSaving] = useState(false);
|
|
615
|
+
const [saved, setSaved] = useState(false);
|
|
616
|
+
const [error, setError] = useState<string | null>(null);
|
|
617
|
+
|
|
618
|
+
const origins = parseUrlLines(text);
|
|
619
|
+
const dirty = origins.join("\n") !== initialOrigins.join("\n");
|
|
620
|
+
|
|
621
|
+
const submit = async (e: FormEvent) => {
|
|
622
|
+
e.preventDefault();
|
|
623
|
+
setSaving(true);
|
|
624
|
+
setError(null);
|
|
625
|
+
setSaved(false);
|
|
626
|
+
const res = await client.updateProject({ projectId, trustedOrigins: origins });
|
|
627
|
+
setSaving(false);
|
|
628
|
+
if (res.ok) {
|
|
629
|
+
setSaved(true);
|
|
630
|
+
setTimeout(() => setSaved(false), 2000);
|
|
631
|
+
onSaved();
|
|
632
|
+
} else {
|
|
633
|
+
setError(errorMessage(res.error, "Couldn't save the trusted origins."));
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
return (
|
|
638
|
+
<form onSubmit={submit} className="grid gap-4">
|
|
639
|
+
{error ? (
|
|
640
|
+
<Alert variant="destructive">
|
|
641
|
+
<AlertCircle />
|
|
642
|
+
<AlertDescription>{error}</AlertDescription>
|
|
643
|
+
</Alert>
|
|
644
|
+
) : null}
|
|
645
|
+
<Field
|
|
646
|
+
label="Origins"
|
|
647
|
+
htmlFor="project-trusted-origins"
|
|
648
|
+
description="One per line, scheme and host only (e.g. https://app.example.com, http://localhost:3000). Apps pass this product's id on sign-in and passkey calls for these to apply."
|
|
649
|
+
>
|
|
650
|
+
<Textarea
|
|
651
|
+
id="project-trusted-origins"
|
|
652
|
+
value={text}
|
|
653
|
+
onChange={(e) => setText(e.target.value)}
|
|
654
|
+
rows={3}
|
|
655
|
+
placeholder="https://app.example.com"
|
|
656
|
+
className="font-mono"
|
|
657
|
+
disabled={!canManage}
|
|
658
|
+
/>
|
|
659
|
+
</Field>
|
|
660
|
+
{canManage ? (
|
|
661
|
+
<div className="flex items-center gap-3">
|
|
662
|
+
<Button type="submit" loading={saving} disabled={!dirty}>
|
|
663
|
+
{saved ? <Check /> : <Save />}
|
|
664
|
+
{saved ? "Saved" : "Save changes"}
|
|
665
|
+
</Button>
|
|
666
|
+
</div>
|
|
667
|
+
) : null}
|
|
668
|
+
</form>
|
|
669
|
+
);
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
/// One redirect URL per textarea line, trimmed, blanks dropped.
|
|
673
|
+
const parseUrlLines = (text: string): string[] =>
|
|
674
|
+
text
|
|
675
|
+
.split("\n")
|
|
676
|
+
.map((l) => l.trim())
|
|
677
|
+
.filter((l) => l.length > 0);
|
|
678
|
+
|
|
679
|
+
/// The redirect URL this deployment's own callback route answers on —
|
|
680
|
+
/// the value to register (and paste here) when the product runs
|
|
681
|
+
/// directly on this deployment. The console is served by the API, so
|
|
682
|
+
/// its origin is the server's. Proxied products (e.g. mounted at /um)
|
|
683
|
+
/// use their own full URL instead; either way the list mirrors the
|
|
684
|
+
/// provider console verbatim.
|
|
685
|
+
const suggestedRedirectUrl = (provider: string): string =>
|
|
686
|
+
typeof window === "undefined" || !provider
|
|
687
|
+
? ""
|
|
688
|
+
: `${window.location.origin}/api/auth/callback/${provider}`;
|
|
689
|
+
|
|
690
|
+
const REDIRECT_URLS_HELP =
|
|
691
|
+
"The exact authorized redirect URIs registered with the provider — full URLs, one per line, copied verbatim from the provider console (e.g. https://app.example.com/um/api/auth/callback/google). Sign-ins send the entry matching the caller's origin, byte for byte; the first entry is the default, and users may only land back on these origins.";
|
|
692
|
+
|
|
693
|
+
/// Per-product social-login connection manager: list existing
|
|
694
|
+
/// connections, add one (provider dropdown from the catalog + client
|
|
695
|
+
/// id/secret/redirect URLs), edit, toggle enabled, delete. Secrets are
|
|
696
|
+
/// write-only.
|
|
697
|
+
const SocialConnections = ({
|
|
698
|
+
projectId,
|
|
699
|
+
canManage,
|
|
700
|
+
}: {
|
|
701
|
+
projectId: string;
|
|
702
|
+
canManage: boolean;
|
|
703
|
+
}) => {
|
|
704
|
+
const client = useUmClient();
|
|
705
|
+
const { data, loading, error, refresh } = useCall("listSocialConnections", {
|
|
706
|
+
projectId,
|
|
707
|
+
});
|
|
708
|
+
const catalog = useCall("getProviders");
|
|
709
|
+
const [busyId, setBusyId] = useState<string | null>(null);
|
|
710
|
+
|
|
711
|
+
const connections = data?.connections ?? [];
|
|
712
|
+
|
|
713
|
+
const toggleEnabled = async (c: SocialConnectionRow) => {
|
|
714
|
+
setBusyId(c.id);
|
|
715
|
+
await client.updateSocialConnection({
|
|
716
|
+
projectId,
|
|
717
|
+
connectionId: c.id,
|
|
718
|
+
enabled: !c.enabled,
|
|
719
|
+
});
|
|
720
|
+
setBusyId(null);
|
|
721
|
+
refresh();
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
const remove = async (c: SocialConnectionRow) => {
|
|
725
|
+
setBusyId(c.id);
|
|
726
|
+
await client.deleteSocialConnection({ projectId, connectionId: c.id });
|
|
727
|
+
setBusyId(null);
|
|
728
|
+
refresh();
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
if (error) {
|
|
732
|
+
return (
|
|
733
|
+
<Alert variant="destructive">
|
|
734
|
+
<AlertCircle />
|
|
735
|
+
<AlertDescription>{errorMessage(error)}</AlertDescription>
|
|
736
|
+
</Alert>
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
return (
|
|
741
|
+
<div className="grid gap-4">
|
|
742
|
+
{loading ? (
|
|
743
|
+
<Skeleton className="h-16 w-full" />
|
|
744
|
+
) : connections.length === 0 ? (
|
|
745
|
+
<p className="text-muted-foreground text-sm">
|
|
746
|
+
No social login providers configured for this product yet.
|
|
747
|
+
</p>
|
|
748
|
+
) : (
|
|
749
|
+
<div className="grid gap-2">
|
|
750
|
+
{connections.map((c) => (
|
|
751
|
+
<div
|
|
752
|
+
key={c.id}
|
|
753
|
+
className="flex items-center justify-between gap-3 rounded-lg border bg-card p-3"
|
|
754
|
+
>
|
|
755
|
+
<div className="min-w-0">
|
|
756
|
+
<div className="flex items-center gap-2">
|
|
757
|
+
<span className="text-sm font-medium capitalize">{c.provider}</span>
|
|
758
|
+
<Badge variant={c.enabled ? "default" : "muted"}>
|
|
759
|
+
{c.enabled ? "enabled" : "disabled"}
|
|
760
|
+
</Badge>
|
|
761
|
+
</div>
|
|
762
|
+
<p className="truncate font-mono text-xs text-muted-foreground">
|
|
763
|
+
{c.clientId}
|
|
764
|
+
</p>
|
|
765
|
+
{c.redirectUrls.length > 0 ? (
|
|
766
|
+
<p className="truncate font-mono text-xs text-muted-foreground">
|
|
767
|
+
→ {c.redirectUrls.join(", ")}
|
|
768
|
+
</p>
|
|
769
|
+
) : null}
|
|
770
|
+
</div>
|
|
771
|
+
{canManage ? (
|
|
772
|
+
<div className="flex shrink-0 items-center gap-2">
|
|
773
|
+
<Switch
|
|
774
|
+
checked={c.enabled}
|
|
775
|
+
onCheckedChange={() => void toggleEnabled(c)}
|
|
776
|
+
disabled={busyId === c.id}
|
|
777
|
+
aria-label="Toggle enabled"
|
|
778
|
+
/>
|
|
779
|
+
<EditConnectionDialog
|
|
780
|
+
projectId={projectId}
|
|
781
|
+
connection={c}
|
|
782
|
+
onSaved={refresh}
|
|
783
|
+
/>
|
|
784
|
+
<Button
|
|
785
|
+
variant="ghost"
|
|
786
|
+
size="icon"
|
|
787
|
+
className="size-8"
|
|
788
|
+
onClick={() => void remove(c)}
|
|
789
|
+
disabled={busyId === c.id}
|
|
790
|
+
aria-label="Delete connection"
|
|
791
|
+
>
|
|
792
|
+
<Trash2 className="size-4" />
|
|
793
|
+
</Button>
|
|
794
|
+
</div>
|
|
795
|
+
) : null}
|
|
796
|
+
</div>
|
|
797
|
+
))}
|
|
798
|
+
</div>
|
|
799
|
+
)}
|
|
800
|
+
{canManage ? (
|
|
801
|
+
<AddConnectionDialog
|
|
802
|
+
projectId={projectId}
|
|
803
|
+
catalog={catalog.data?.providers ?? []}
|
|
804
|
+
existing={connections.map((c) => c.provider)}
|
|
805
|
+
onAdded={refresh}
|
|
806
|
+
/>
|
|
807
|
+
) : null}
|
|
808
|
+
</div>
|
|
809
|
+
);
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
const AddConnectionDialog = ({
|
|
813
|
+
projectId,
|
|
814
|
+
catalog,
|
|
815
|
+
existing,
|
|
816
|
+
onAdded,
|
|
817
|
+
}: {
|
|
818
|
+
projectId: string;
|
|
819
|
+
catalog: string[];
|
|
820
|
+
existing: string[];
|
|
821
|
+
onAdded: () => void;
|
|
822
|
+
}) => {
|
|
823
|
+
const client = useUmClient();
|
|
824
|
+
const available = catalog.filter((p) => !existing.includes(p));
|
|
825
|
+
const [open, setOpen] = useState(false);
|
|
826
|
+
const [provider, setProvider] = useState("");
|
|
827
|
+
const [clientId, setClientId] = useState("");
|
|
828
|
+
const [clientSecret, setClientSecret] = useState("");
|
|
829
|
+
const [redirectUrls, setRedirectUrls] = useState("");
|
|
830
|
+
const [scopes, setScopes] = useState("");
|
|
831
|
+
const [loading, setLoading] = useState(false);
|
|
832
|
+
const [error, setError] = useState<string | null>(null);
|
|
833
|
+
|
|
834
|
+
const reset = () => {
|
|
835
|
+
setProvider("");
|
|
836
|
+
setClientId("");
|
|
837
|
+
setClientSecret("");
|
|
838
|
+
setRedirectUrls("");
|
|
839
|
+
setScopes("");
|
|
840
|
+
setError(null);
|
|
841
|
+
setLoading(false);
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
const submit = async (e: FormEvent) => {
|
|
845
|
+
e.preventDefault();
|
|
846
|
+
setLoading(true);
|
|
847
|
+
setError(null);
|
|
848
|
+
const res = await client.createSocialConnection({
|
|
849
|
+
projectId,
|
|
850
|
+
provider,
|
|
851
|
+
clientId: clientId.trim(),
|
|
852
|
+
clientSecret,
|
|
853
|
+
redirectUrls: parseUrlLines(redirectUrls),
|
|
854
|
+
scopes: scopes.trim() || null,
|
|
855
|
+
});
|
|
856
|
+
setLoading(false);
|
|
857
|
+
if (res.ok) {
|
|
858
|
+
onAdded();
|
|
859
|
+
reset();
|
|
860
|
+
setOpen(false);
|
|
861
|
+
} else {
|
|
862
|
+
setError(errorMessage(res.error, "Couldn't add the connection."));
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
|
|
866
|
+
return (
|
|
867
|
+
<Dialog
|
|
868
|
+
open={open}
|
|
869
|
+
onOpenChange={(o) => {
|
|
870
|
+
setOpen(o);
|
|
871
|
+
if (!o) reset();
|
|
872
|
+
}}
|
|
873
|
+
>
|
|
874
|
+
<DialogTrigger asChild>
|
|
875
|
+
<Button variant="outline" size="sm" disabled={available.length === 0}>
|
|
876
|
+
Add social login
|
|
877
|
+
</Button>
|
|
878
|
+
</DialogTrigger>
|
|
879
|
+
<DialogContent>
|
|
880
|
+
<DialogHeader>
|
|
881
|
+
<DialogTitle>Add a social login</DialogTitle>
|
|
882
|
+
<DialogDescription>
|
|
883
|
+
Pick a provider and paste this product's own OAuth client. The
|
|
884
|
+
secret is stored encrypted and never shown again.
|
|
885
|
+
</DialogDescription>
|
|
886
|
+
</DialogHeader>
|
|
887
|
+
<form onSubmit={submit} className="grid gap-4" noValidate>
|
|
888
|
+
<Field label="Provider" htmlFor="conn-provider" required>
|
|
889
|
+
<Select value={provider} onValueChange={setProvider}>
|
|
890
|
+
<SelectTrigger id="conn-provider">
|
|
891
|
+
<SelectValue placeholder="Choose a provider" />
|
|
892
|
+
</SelectTrigger>
|
|
893
|
+
<SelectContent>
|
|
894
|
+
{available.map((p) => (
|
|
895
|
+
<SelectItem key={p} value={p} className="capitalize">
|
|
896
|
+
{p}
|
|
897
|
+
</SelectItem>
|
|
898
|
+
))}
|
|
899
|
+
</SelectContent>
|
|
900
|
+
</Select>
|
|
901
|
+
</Field>
|
|
902
|
+
<Field label="Client ID" htmlFor="conn-client-id" required>
|
|
903
|
+
<Input
|
|
904
|
+
id="conn-client-id"
|
|
905
|
+
value={clientId}
|
|
906
|
+
onChange={(e) => setClientId(e.target.value)}
|
|
907
|
+
className="font-mono"
|
|
908
|
+
/>
|
|
909
|
+
</Field>
|
|
910
|
+
<Field label="Client secret" htmlFor="conn-client-secret" required>
|
|
911
|
+
<Input
|
|
912
|
+
id="conn-client-secret"
|
|
913
|
+
type="password"
|
|
914
|
+
value={clientSecret}
|
|
915
|
+
onChange={(e) => setClientSecret(e.target.value)}
|
|
916
|
+
className="font-mono"
|
|
917
|
+
/>
|
|
918
|
+
</Field>
|
|
919
|
+
<Field
|
|
920
|
+
label="Redirect URLs"
|
|
921
|
+
htmlFor="conn-redirect-urls"
|
|
922
|
+
required
|
|
923
|
+
description={REDIRECT_URLS_HELP}
|
|
924
|
+
>
|
|
925
|
+
<Textarea
|
|
926
|
+
id="conn-redirect-urls"
|
|
927
|
+
value={redirectUrls}
|
|
928
|
+
onChange={(e) => setRedirectUrls(e.target.value)}
|
|
929
|
+
rows={3}
|
|
930
|
+
placeholder={
|
|
931
|
+
suggestedRedirectUrl(provider) || "Choose a provider first"
|
|
932
|
+
}
|
|
933
|
+
className="font-mono"
|
|
934
|
+
/>
|
|
935
|
+
</Field>
|
|
936
|
+
<Field
|
|
937
|
+
label="Scopes"
|
|
938
|
+
htmlFor="conn-scopes"
|
|
939
|
+
description="Optional space-separated override; leave blank for the provider defaults."
|
|
940
|
+
>
|
|
941
|
+
<Input
|
|
942
|
+
id="conn-scopes"
|
|
943
|
+
value={scopes}
|
|
944
|
+
onChange={(e) => setScopes(e.target.value)}
|
|
945
|
+
className="font-mono"
|
|
946
|
+
/>
|
|
947
|
+
</Field>
|
|
948
|
+
{error ? (
|
|
949
|
+
<Alert variant="destructive">
|
|
950
|
+
<AlertCircle />
|
|
951
|
+
<AlertDescription>{error}</AlertDescription>
|
|
952
|
+
</Alert>
|
|
953
|
+
) : null}
|
|
954
|
+
<DialogFooter>
|
|
955
|
+
<Button type="button" variant="ghost" onClick={() => setOpen(false)} disabled={loading}>
|
|
956
|
+
Cancel
|
|
957
|
+
</Button>
|
|
958
|
+
<Button
|
|
959
|
+
type="submit"
|
|
960
|
+
loading={loading}
|
|
961
|
+
disabled={
|
|
962
|
+
!provider ||
|
|
963
|
+
!clientId.trim() ||
|
|
964
|
+
!clientSecret ||
|
|
965
|
+
parseUrlLines(redirectUrls).length === 0
|
|
966
|
+
}
|
|
967
|
+
>
|
|
968
|
+
Add connection
|
|
969
|
+
</Button>
|
|
970
|
+
</DialogFooter>
|
|
971
|
+
</form>
|
|
972
|
+
</DialogContent>
|
|
973
|
+
</Dialog>
|
|
974
|
+
);
|
|
975
|
+
};
|
|
976
|
+
|
|
977
|
+
/// Edit an existing connection: client id, a replacement secret
|
|
978
|
+
/// (blank keeps the stored one), the redirect URL list and scopes.
|
|
979
|
+
const EditConnectionDialog = ({
|
|
980
|
+
projectId,
|
|
981
|
+
connection,
|
|
982
|
+
onSaved,
|
|
983
|
+
}: {
|
|
984
|
+
projectId: string;
|
|
985
|
+
connection: SocialConnectionRow;
|
|
986
|
+
onSaved: () => void;
|
|
987
|
+
}) => {
|
|
988
|
+
const client = useUmClient();
|
|
989
|
+
const [open, setOpen] = useState(false);
|
|
990
|
+
const [clientId, setClientId] = useState(connection.clientId);
|
|
991
|
+
const [clientSecret, setClientSecret] = useState("");
|
|
992
|
+
const [redirectUrls, setRedirectUrls] = useState(
|
|
993
|
+
connection.redirectUrls.join("\n")
|
|
994
|
+
);
|
|
995
|
+
const [scopes, setScopes] = useState(connection.scopes ?? "");
|
|
996
|
+
const [loading, setLoading] = useState(false);
|
|
997
|
+
const [error, setError] = useState<string | null>(null);
|
|
998
|
+
|
|
999
|
+
const reset = () => {
|
|
1000
|
+
setClientId(connection.clientId);
|
|
1001
|
+
setClientSecret("");
|
|
1002
|
+
setRedirectUrls(connection.redirectUrls.join("\n"));
|
|
1003
|
+
setScopes(connection.scopes ?? "");
|
|
1004
|
+
setError(null);
|
|
1005
|
+
setLoading(false);
|
|
1006
|
+
};
|
|
1007
|
+
|
|
1008
|
+
const submit = async (e: FormEvent) => {
|
|
1009
|
+
e.preventDefault();
|
|
1010
|
+
setLoading(true);
|
|
1011
|
+
setError(null);
|
|
1012
|
+
const res = await client.updateSocialConnection({
|
|
1013
|
+
projectId,
|
|
1014
|
+
connectionId: connection.id,
|
|
1015
|
+
clientId: clientId.trim(),
|
|
1016
|
+
// Blank keeps the stored secret.
|
|
1017
|
+
...(clientSecret ? { clientSecret } : {}),
|
|
1018
|
+
redirectUrls: parseUrlLines(redirectUrls),
|
|
1019
|
+
scopes: scopes.trim() || null,
|
|
1020
|
+
});
|
|
1021
|
+
setLoading(false);
|
|
1022
|
+
if (res.ok) {
|
|
1023
|
+
onSaved();
|
|
1024
|
+
setOpen(false);
|
|
1025
|
+
} else {
|
|
1026
|
+
setError(errorMessage(res.error, "Couldn't save the connection."));
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
return (
|
|
1031
|
+
<Dialog
|
|
1032
|
+
open={open}
|
|
1033
|
+
onOpenChange={(o) => {
|
|
1034
|
+
setOpen(o);
|
|
1035
|
+
if (o) reset();
|
|
1036
|
+
}}
|
|
1037
|
+
>
|
|
1038
|
+
<DialogTrigger asChild>
|
|
1039
|
+
<Button
|
|
1040
|
+
variant="ghost"
|
|
1041
|
+
size="icon"
|
|
1042
|
+
className="size-8"
|
|
1043
|
+
aria-label={`Edit ${connection.provider} connection`}
|
|
1044
|
+
>
|
|
1045
|
+
<Pencil className="size-4" />
|
|
1046
|
+
</Button>
|
|
1047
|
+
</DialogTrigger>
|
|
1048
|
+
<DialogContent>
|
|
1049
|
+
<DialogHeader>
|
|
1050
|
+
<DialogTitle className="capitalize">
|
|
1051
|
+
Edit {connection.provider} connection
|
|
1052
|
+
</DialogTitle>
|
|
1053
|
+
<DialogDescription>
|
|
1054
|
+
The client secret is write-only: leave it blank to keep the
|
|
1055
|
+
stored one.
|
|
1056
|
+
</DialogDescription>
|
|
1057
|
+
</DialogHeader>
|
|
1058
|
+
<form onSubmit={submit} className="grid gap-4" noValidate>
|
|
1059
|
+
<Field label="Client ID" htmlFor="edit-conn-client-id" required>
|
|
1060
|
+
<Input
|
|
1061
|
+
id="edit-conn-client-id"
|
|
1062
|
+
value={clientId}
|
|
1063
|
+
onChange={(e) => setClientId(e.target.value)}
|
|
1064
|
+
className="font-mono"
|
|
1065
|
+
/>
|
|
1066
|
+
</Field>
|
|
1067
|
+
<Field label="Client secret" htmlFor="edit-conn-client-secret">
|
|
1068
|
+
<Input
|
|
1069
|
+
id="edit-conn-client-secret"
|
|
1070
|
+
type="password"
|
|
1071
|
+
value={clientSecret}
|
|
1072
|
+
onChange={(e) => setClientSecret(e.target.value)}
|
|
1073
|
+
placeholder="Unchanged"
|
|
1074
|
+
className="font-mono"
|
|
1075
|
+
/>
|
|
1076
|
+
</Field>
|
|
1077
|
+
<Field
|
|
1078
|
+
label="Redirect URLs"
|
|
1079
|
+
htmlFor="edit-conn-redirect-urls"
|
|
1080
|
+
required
|
|
1081
|
+
description={REDIRECT_URLS_HELP}
|
|
1082
|
+
>
|
|
1083
|
+
<Textarea
|
|
1084
|
+
id="edit-conn-redirect-urls"
|
|
1085
|
+
value={redirectUrls}
|
|
1086
|
+
onChange={(e) => setRedirectUrls(e.target.value)}
|
|
1087
|
+
rows={3}
|
|
1088
|
+
placeholder={suggestedRedirectUrl(connection.provider)}
|
|
1089
|
+
className="font-mono"
|
|
1090
|
+
/>
|
|
1091
|
+
</Field>
|
|
1092
|
+
<Field
|
|
1093
|
+
label="Scopes"
|
|
1094
|
+
htmlFor="edit-conn-scopes"
|
|
1095
|
+
description="Optional space-separated override; leave blank for the provider defaults."
|
|
1096
|
+
>
|
|
1097
|
+
<Input
|
|
1098
|
+
id="edit-conn-scopes"
|
|
1099
|
+
value={scopes}
|
|
1100
|
+
onChange={(e) => setScopes(e.target.value)}
|
|
1101
|
+
className="font-mono"
|
|
1102
|
+
/>
|
|
1103
|
+
</Field>
|
|
1104
|
+
{error ? (
|
|
1105
|
+
<Alert variant="destructive">
|
|
1106
|
+
<AlertCircle />
|
|
1107
|
+
<AlertDescription>{error}</AlertDescription>
|
|
1108
|
+
</Alert>
|
|
1109
|
+
) : null}
|
|
1110
|
+
<DialogFooter>
|
|
1111
|
+
<Button
|
|
1112
|
+
type="button"
|
|
1113
|
+
variant="ghost"
|
|
1114
|
+
onClick={() => setOpen(false)}
|
|
1115
|
+
disabled={loading}
|
|
1116
|
+
>
|
|
1117
|
+
Cancel
|
|
1118
|
+
</Button>
|
|
1119
|
+
<Button
|
|
1120
|
+
type="submit"
|
|
1121
|
+
loading={loading}
|
|
1122
|
+
disabled={
|
|
1123
|
+
!clientId.trim() || parseUrlLines(redirectUrls).length === 0
|
|
1124
|
+
}
|
|
1125
|
+
>
|
|
1126
|
+
Save
|
|
1127
|
+
</Button>
|
|
1128
|
+
</DialogFooter>
|
|
1129
|
+
</form>
|
|
1130
|
+
</DialogContent>
|
|
1131
|
+
</Dialog>
|
|
1132
|
+
);
|
|
1133
|
+
};
|