@nexys/user-management-web 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -0
- package/components.json +21 -0
- package/package.json +66 -0
- package/src/components/audit/audit-log-table.test.tsx +98 -0
- package/src/components/audit/audit-log-table.tsx +227 -0
- package/src/components/auth/accept-invitation-card.tsx +104 -0
- package/src/components/auth/forgot-password-form.tsx +93 -0
- package/src/components/auth/reset-password-form.tsx +144 -0
- package/src/components/auth/sign-in-form.test.tsx +164 -0
- package/src/components/auth/sign-in-form.tsx +504 -0
- package/src/components/auth/sign-up-form.tsx +124 -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 +238 -0
- package/src/components/profile/change-password-form.tsx +159 -0
- package/src/components/profile/passkeys-card.tsx +186 -0
- package/src/components/profile/profile-card.tsx +107 -0
- package/src/components/profile/refresh-tokens-list.tsx +176 -0
- package/src/components/profile/two-factor-card.tsx +230 -0
- package/src/components/projects/project-consents.tsx +577 -0
- package/src/components/projects/project-create-dialog.tsx +193 -0
- package/src/components/projects/project-detail-tabs.tsx +64 -0
- package/src/components/projects/project-email-templates.tsx +285 -0
- package/src/components/projects/project-notices.tsx +461 -0
- package/src/components/projects/project-settings.tsx +1059 -0
- package/src/components/projects/project-tenants.tsx +108 -0
- package/src/components/projects/projects-table.test.tsx +109 -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 +164 -0
- package/src/components/tenants/tenant-detail-tabs.tsx +51 -0
- package/src/components/tenants/tenant-members.tsx +587 -0
- package/src/components/tenants/tenant-roles.test.tsx +107 -0
- package/src/components/tenants/tenant-roles.tsx +418 -0
- package/src/components/tenants/tenant-settings.tsx +392 -0
- package/src/components/tenants/tenants-table.test.tsx +81 -0
- package/src/components/tenants/tenants-table.tsx +247 -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 +229 -0
- package/src/components/users/user-delete-dialog.tsx +88 -0
- package/src/components/users/user-detail.tsx +818 -0
- package/src/components/users/users-table.test.tsx +107 -0
- package/src/components/users/users-table.tsx +386 -0
- package/src/context/auth-context.tsx +127 -0
- package/src/context/theme-context.test.tsx +78 -0
- package/src/context/theme-context.tsx +110 -0
- package/src/hooks/use-call.ts +60 -0
- package/src/index.ts +160 -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,229 @@
|
|
|
1
|
+
import { adminCreateUser, type UserRole } from "@nexys/user-management-client";
|
|
2
|
+
import { AlertCircle, UserPlus } from "lucide-react";
|
|
3
|
+
import { useState, type FormEvent, type ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
import { useUmClient } from "../../context/auth-context.js";
|
|
6
|
+
import { errorMessage } from "../../lib/error-message.js";
|
|
7
|
+
import { UserRoleSelect } from "../roles/role-select.js";
|
|
8
|
+
import { Alert, AlertDescription } from "../ui/alert.js";
|
|
9
|
+
import { Button } from "../ui/button.js";
|
|
10
|
+
import {
|
|
11
|
+
Dialog,
|
|
12
|
+
DialogContent,
|
|
13
|
+
DialogDescription,
|
|
14
|
+
DialogFooter,
|
|
15
|
+
DialogHeader,
|
|
16
|
+
DialogTitle,
|
|
17
|
+
DialogTrigger,
|
|
18
|
+
} from "../ui/dialog.js";
|
|
19
|
+
import { Field } from "../ui/field.js";
|
|
20
|
+
import { Input } from "../ui/input.js";
|
|
21
|
+
import {
|
|
22
|
+
Select,
|
|
23
|
+
SelectContent,
|
|
24
|
+
SelectItem,
|
|
25
|
+
SelectTrigger,
|
|
26
|
+
SelectValue,
|
|
27
|
+
} from "../ui/select.js";
|
|
28
|
+
|
|
29
|
+
const SOCIAL_PROVIDERS = ["google", "microsoft", "github", "discord", "facebook"];
|
|
30
|
+
|
|
31
|
+
const providerLabel: Record<string, string> = {
|
|
32
|
+
google: "Google",
|
|
33
|
+
microsoft: "Microsoft",
|
|
34
|
+
github: "GitHub",
|
|
35
|
+
discord: "Discord",
|
|
36
|
+
facebook: "Facebook",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export interface UserCreateDialogProps {
|
|
40
|
+
/** Override the trigger button. */
|
|
41
|
+
trigger?: ReactNode;
|
|
42
|
+
onCreated?: (user: { id: string; email: string }) => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Superadmin-only direct user creation. */
|
|
46
|
+
export const UserCreateDialog = ({ trigger, onCreated }: UserCreateDialogProps) => {
|
|
47
|
+
const client = useUmClient();
|
|
48
|
+
const [open, setOpen] = useState(false);
|
|
49
|
+
const [firstName, setFirstName] = useState("");
|
|
50
|
+
const [lastName, setLastName] = useState("");
|
|
51
|
+
const [email, setEmail] = useState("");
|
|
52
|
+
// "password" or a social provider id — mirrors the server's
|
|
53
|
+
// password-XOR-provider contract on create-user.
|
|
54
|
+
const [signInMethod, setSignInMethod] = useState("password");
|
|
55
|
+
const [password, setPassword] = useState("");
|
|
56
|
+
const [role, setRole] = useState<UserRole>("user");
|
|
57
|
+
const [loading, setLoading] = useState(false);
|
|
58
|
+
const [error, setError] = useState<string | null>(null);
|
|
59
|
+
|
|
60
|
+
const usesPassword = signInMethod === "password";
|
|
61
|
+
|
|
62
|
+
const reset = () => {
|
|
63
|
+
setFirstName("");
|
|
64
|
+
setLastName("");
|
|
65
|
+
setEmail("");
|
|
66
|
+
setSignInMethod("password");
|
|
67
|
+
setPassword("");
|
|
68
|
+
setRole("user");
|
|
69
|
+
setError(null);
|
|
70
|
+
setLoading(false);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const submit = async (e: FormEvent) => {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
setLoading(true);
|
|
76
|
+
setError(null);
|
|
77
|
+
const res = await client.call(adminCreateUser, {
|
|
78
|
+
firstName: firstName.trim(),
|
|
79
|
+
lastName: lastName.trim() || undefined,
|
|
80
|
+
email: email.trim(),
|
|
81
|
+
...(usesPassword ? { password } : { provider: signInMethod }),
|
|
82
|
+
role,
|
|
83
|
+
});
|
|
84
|
+
setLoading(false);
|
|
85
|
+
if (res.ok) {
|
|
86
|
+
onCreated?.(res.data.user);
|
|
87
|
+
reset();
|
|
88
|
+
setOpen(false);
|
|
89
|
+
} else {
|
|
90
|
+
setError(errorMessage(res.error, "Couldn't create user."));
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<Dialog
|
|
96
|
+
open={open}
|
|
97
|
+
onOpenChange={(o) => {
|
|
98
|
+
setOpen(o);
|
|
99
|
+
if (!o) reset();
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
<DialogTrigger asChild>
|
|
103
|
+
{trigger ?? (
|
|
104
|
+
<Button>
|
|
105
|
+
<UserPlus />
|
|
106
|
+
New user
|
|
107
|
+
</Button>
|
|
108
|
+
)}
|
|
109
|
+
</DialogTrigger>
|
|
110
|
+
<DialogContent>
|
|
111
|
+
<DialogHeader>
|
|
112
|
+
<DialogTitle>Create a new user</DialogTitle>
|
|
113
|
+
<DialogDescription>
|
|
114
|
+
{usesPassword
|
|
115
|
+
? "The account is created active and email-verified. Share the " +
|
|
116
|
+
"password securely — the user can change it from their profile."
|
|
117
|
+
: "The account is created active and email-verified, with no " +
|
|
118
|
+
"password — the user signs in with " +
|
|
119
|
+
`${providerLabel[signInMethod]} using this email address.`}
|
|
120
|
+
</DialogDescription>
|
|
121
|
+
</DialogHeader>
|
|
122
|
+
<form onSubmit={submit} className="grid gap-4" noValidate>
|
|
123
|
+
<div className="grid gap-4 sm:grid-cols-2">
|
|
124
|
+
<Field label="First name" htmlFor="new-user-first-name" required>
|
|
125
|
+
<Input
|
|
126
|
+
id="new-user-first-name"
|
|
127
|
+
autoFocus
|
|
128
|
+
required
|
|
129
|
+
value={firstName}
|
|
130
|
+
onChange={(e) => setFirstName(e.target.value)}
|
|
131
|
+
placeholder="Ada"
|
|
132
|
+
/>
|
|
133
|
+
</Field>
|
|
134
|
+
<Field label="Last name" htmlFor="new-user-last-name">
|
|
135
|
+
<Input
|
|
136
|
+
id="new-user-last-name"
|
|
137
|
+
value={lastName}
|
|
138
|
+
onChange={(e) => setLastName(e.target.value)}
|
|
139
|
+
placeholder="Lovelace"
|
|
140
|
+
/>
|
|
141
|
+
</Field>
|
|
142
|
+
</div>
|
|
143
|
+
<Field label="Email" htmlFor="new-user-email" required>
|
|
144
|
+
<Input
|
|
145
|
+
id="new-user-email"
|
|
146
|
+
type="email"
|
|
147
|
+
required
|
|
148
|
+
value={email}
|
|
149
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
150
|
+
placeholder="ada@example.com"
|
|
151
|
+
/>
|
|
152
|
+
</Field>
|
|
153
|
+
<Field
|
|
154
|
+
label="Sign-in method"
|
|
155
|
+
htmlFor="new-user-sign-in-method"
|
|
156
|
+
description={
|
|
157
|
+
usesPassword
|
|
158
|
+
? undefined
|
|
159
|
+
: `No password — their first ${providerLabel[signInMethod]} ` +
|
|
160
|
+
"sign-in with this email lands on this account."
|
|
161
|
+
}
|
|
162
|
+
>
|
|
163
|
+
<Select value={signInMethod} onValueChange={setSignInMethod}>
|
|
164
|
+
<SelectTrigger id="new-user-sign-in-method">
|
|
165
|
+
<SelectValue />
|
|
166
|
+
</SelectTrigger>
|
|
167
|
+
<SelectContent>
|
|
168
|
+
<SelectItem value="password">Password</SelectItem>
|
|
169
|
+
{SOCIAL_PROVIDERS.map((p) => (
|
|
170
|
+
<SelectItem key={p} value={p}>
|
|
171
|
+
{providerLabel[p]}
|
|
172
|
+
</SelectItem>
|
|
173
|
+
))}
|
|
174
|
+
</SelectContent>
|
|
175
|
+
</Select>
|
|
176
|
+
</Field>
|
|
177
|
+
{usesPassword ? (
|
|
178
|
+
<Field
|
|
179
|
+
label="Password"
|
|
180
|
+
htmlFor="new-user-password"
|
|
181
|
+
description="At least 8 characters."
|
|
182
|
+
required
|
|
183
|
+
>
|
|
184
|
+
<Input
|
|
185
|
+
id="new-user-password"
|
|
186
|
+
type="password"
|
|
187
|
+
required
|
|
188
|
+
minLength={8}
|
|
189
|
+
value={password}
|
|
190
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
191
|
+
autoComplete="new-password"
|
|
192
|
+
/>
|
|
193
|
+
</Field>
|
|
194
|
+
) : null}
|
|
195
|
+
<Field label="Role" htmlFor="new-user-role">
|
|
196
|
+
<UserRoleSelect value={role} onChange={setRole} />
|
|
197
|
+
</Field>
|
|
198
|
+
{error ? (
|
|
199
|
+
<Alert variant="destructive">
|
|
200
|
+
<AlertCircle />
|
|
201
|
+
<AlertDescription>{error}</AlertDescription>
|
|
202
|
+
</Alert>
|
|
203
|
+
) : null}
|
|
204
|
+
<DialogFooter>
|
|
205
|
+
<Button
|
|
206
|
+
type="button"
|
|
207
|
+
variant="ghost"
|
|
208
|
+
onClick={() => setOpen(false)}
|
|
209
|
+
disabled={loading}
|
|
210
|
+
>
|
|
211
|
+
Cancel
|
|
212
|
+
</Button>
|
|
213
|
+
<Button
|
|
214
|
+
type="submit"
|
|
215
|
+
loading={loading}
|
|
216
|
+
disabled={
|
|
217
|
+
!firstName.trim() ||
|
|
218
|
+
!email.trim() ||
|
|
219
|
+
(usesPassword && password.length < 8)
|
|
220
|
+
}
|
|
221
|
+
>
|
|
222
|
+
Create user
|
|
223
|
+
</Button>
|
|
224
|
+
</DialogFooter>
|
|
225
|
+
</form>
|
|
226
|
+
</DialogContent>
|
|
227
|
+
</Dialog>
|
|
228
|
+
);
|
|
229
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { adminRemoveUser, type AdminUserRow } from "@nexys/user-management-client";
|
|
2
|
+
import { AlertCircle, Trash2 } from "lucide-react";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
|
|
5
|
+
import { useUmClient } from "../../context/auth-context.js";
|
|
6
|
+
import { errorMessage } from "../../lib/error-message.js";
|
|
7
|
+
import { Alert, AlertDescription } from "../ui/alert.js";
|
|
8
|
+
import { Button } from "../ui/button.js";
|
|
9
|
+
import {
|
|
10
|
+
Dialog,
|
|
11
|
+
DialogContent,
|
|
12
|
+
DialogDescription,
|
|
13
|
+
DialogFooter,
|
|
14
|
+
DialogHeader,
|
|
15
|
+
DialogTitle,
|
|
16
|
+
} from "../ui/dialog.js";
|
|
17
|
+
|
|
18
|
+
export interface UserDeleteDialogProps {
|
|
19
|
+
/** The user to delete; null hides the dialog. */
|
|
20
|
+
user: AdminUserRow | null;
|
|
21
|
+
onOpenChange: (open: boolean) => void;
|
|
22
|
+
onDeleted?: () => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Confirm-then-delete (soft delete — the server sets `deletedAt` and
|
|
27
|
+
* revokes the user's sessions; the row stays for audit).
|
|
28
|
+
*/
|
|
29
|
+
export const UserDeleteDialog = ({ user, onOpenChange, onDeleted }: UserDeleteDialogProps) => {
|
|
30
|
+
const client = useUmClient();
|
|
31
|
+
const [loading, setLoading] = useState(false);
|
|
32
|
+
const [error, setError] = useState<string | null>(null);
|
|
33
|
+
|
|
34
|
+
const confirm = async () => {
|
|
35
|
+
if (!user) return;
|
|
36
|
+
setLoading(true);
|
|
37
|
+
setError(null);
|
|
38
|
+
const res = await client.call(adminRemoveUser, { userId: user.id });
|
|
39
|
+
setLoading(false);
|
|
40
|
+
if (res.ok) {
|
|
41
|
+
onDeleted?.();
|
|
42
|
+
onOpenChange(false);
|
|
43
|
+
} else {
|
|
44
|
+
setError(errorMessage(res.error, "Couldn't delete user."));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Dialog
|
|
50
|
+
open={user !== null}
|
|
51
|
+
onOpenChange={(o) => {
|
|
52
|
+
if (!o) setError(null);
|
|
53
|
+
onOpenChange(o);
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
<DialogContent>
|
|
57
|
+
<DialogHeader>
|
|
58
|
+
<DialogTitle>Delete {user?.name || user?.email}?</DialogTitle>
|
|
59
|
+
<DialogDescription>
|
|
60
|
+
The account is deactivated and all of its sessions are revoked.
|
|
61
|
+
The user can no longer sign in. This keeps the record for audit
|
|
62
|
+
purposes (soft delete).
|
|
63
|
+
</DialogDescription>
|
|
64
|
+
</DialogHeader>
|
|
65
|
+
{error ? (
|
|
66
|
+
<Alert variant="destructive">
|
|
67
|
+
<AlertCircle />
|
|
68
|
+
<AlertDescription>{error}</AlertDescription>
|
|
69
|
+
</Alert>
|
|
70
|
+
) : null}
|
|
71
|
+
<DialogFooter>
|
|
72
|
+
<Button
|
|
73
|
+
type="button"
|
|
74
|
+
variant="ghost"
|
|
75
|
+
onClick={() => onOpenChange(false)}
|
|
76
|
+
disabled={loading}
|
|
77
|
+
>
|
|
78
|
+
Cancel
|
|
79
|
+
</Button>
|
|
80
|
+
<Button type="button" variant="destructive" onClick={() => void confirm()} loading={loading}>
|
|
81
|
+
<Trash2 />
|
|
82
|
+
Delete user
|
|
83
|
+
</Button>
|
|
84
|
+
</DialogFooter>
|
|
85
|
+
</DialogContent>
|
|
86
|
+
</Dialog>
|
|
87
|
+
);
|
|
88
|
+
};
|