@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,144 @@
|
|
|
1
|
+
import { resetPassword } from "@nexys/user-management-client";
|
|
2
|
+
import { AlertCircle, KeyRound, ShieldCheck } 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 { Alert, AlertDescription } from "../ui/alert.js";
|
|
8
|
+
import { Button } from "../ui/button.js";
|
|
9
|
+
import {
|
|
10
|
+
Card,
|
|
11
|
+
CardContent,
|
|
12
|
+
CardDescription,
|
|
13
|
+
CardHeader,
|
|
14
|
+
CardTitle,
|
|
15
|
+
} from "../ui/card.js";
|
|
16
|
+
import { Field } from "../ui/field.js";
|
|
17
|
+
import { Input } from "../ui/input.js";
|
|
18
|
+
|
|
19
|
+
export interface ResetPasswordFormProps {
|
|
20
|
+
/** The token from the reset email's `?token=` query param. */
|
|
21
|
+
token: string;
|
|
22
|
+
/** Rendered after a successful reset (e.g. a sign-in link). */
|
|
23
|
+
successSlot?: ReactNode;
|
|
24
|
+
minLength?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Sets a new password from an emailed reset link. */
|
|
28
|
+
export const ResetPasswordForm = ({
|
|
29
|
+
token,
|
|
30
|
+
successSlot,
|
|
31
|
+
minLength = 8,
|
|
32
|
+
}: ResetPasswordFormProps) => {
|
|
33
|
+
const client = useUmClient();
|
|
34
|
+
const [next, setNext] = useState("");
|
|
35
|
+
const [confirm, setConfirm] = useState("");
|
|
36
|
+
const [loading, setLoading] = useState(false);
|
|
37
|
+
const [error, setError] = useState<string | null>(null);
|
|
38
|
+
const [done, setDone] = useState(false);
|
|
39
|
+
|
|
40
|
+
const mismatched = confirm.length > 0 && confirm !== next;
|
|
41
|
+
const tooShort = next.length > 0 && next.length < minLength;
|
|
42
|
+
|
|
43
|
+
const submit = async (e: FormEvent) => {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
if (mismatched || tooShort) return;
|
|
46
|
+
setLoading(true);
|
|
47
|
+
setError(null);
|
|
48
|
+
const res = await client.call(resetPassword, { token, newPassword: next });
|
|
49
|
+
setLoading(false);
|
|
50
|
+
if (res.ok) {
|
|
51
|
+
setDone(true);
|
|
52
|
+
} else {
|
|
53
|
+
setError(
|
|
54
|
+
errorMessage(
|
|
55
|
+
res.error,
|
|
56
|
+
"This reset link is invalid or has expired. Request a new one."
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
if (done) {
|
|
63
|
+
return (
|
|
64
|
+
<Card className="w-full max-w-md">
|
|
65
|
+
<CardHeader className="space-y-1.5">
|
|
66
|
+
<CardTitle className="flex items-center gap-2 text-2xl">
|
|
67
|
+
<ShieldCheck className="size-5 text-green-600" />
|
|
68
|
+
Password updated
|
|
69
|
+
</CardTitle>
|
|
70
|
+
<CardDescription>
|
|
71
|
+
Your password has been changed. You can sign in with it now.
|
|
72
|
+
</CardDescription>
|
|
73
|
+
</CardHeader>
|
|
74
|
+
{successSlot ? <CardContent>{successSlot}</CardContent> : null}
|
|
75
|
+
</Card>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Card className="w-full max-w-md">
|
|
81
|
+
<CardHeader className="space-y-1.5">
|
|
82
|
+
<CardTitle className="flex items-center gap-2 text-2xl">
|
|
83
|
+
<KeyRound className="size-5 text-muted-foreground" />
|
|
84
|
+
Choose a new password
|
|
85
|
+
</CardTitle>
|
|
86
|
+
<CardDescription>
|
|
87
|
+
Enter a new password for your account.
|
|
88
|
+
</CardDescription>
|
|
89
|
+
</CardHeader>
|
|
90
|
+
<CardContent>
|
|
91
|
+
<form onSubmit={submit} className="grid gap-4" noValidate>
|
|
92
|
+
<Field
|
|
93
|
+
label="New password"
|
|
94
|
+
htmlFor="reset-pw"
|
|
95
|
+
required
|
|
96
|
+
description={`At least ${minLength} characters.`}
|
|
97
|
+
error={tooShort ? "New password is too short." : undefined}
|
|
98
|
+
>
|
|
99
|
+
<Input
|
|
100
|
+
id="reset-pw"
|
|
101
|
+
type="password"
|
|
102
|
+
autoComplete="new-password"
|
|
103
|
+
required
|
|
104
|
+
autoFocus
|
|
105
|
+
value={next}
|
|
106
|
+
onChange={(e) => setNext(e.target.value)}
|
|
107
|
+
aria-invalid={tooShort || undefined}
|
|
108
|
+
/>
|
|
109
|
+
</Field>
|
|
110
|
+
<Field
|
|
111
|
+
label="Confirm new password"
|
|
112
|
+
htmlFor="reset-pw-confirm"
|
|
113
|
+
required
|
|
114
|
+
error={mismatched ? "Passwords don't match." : undefined}
|
|
115
|
+
>
|
|
116
|
+
<Input
|
|
117
|
+
id="reset-pw-confirm"
|
|
118
|
+
type="password"
|
|
119
|
+
autoComplete="new-password"
|
|
120
|
+
required
|
|
121
|
+
value={confirm}
|
|
122
|
+
onChange={(e) => setConfirm(e.target.value)}
|
|
123
|
+
aria-invalid={mismatched || undefined}
|
|
124
|
+
/>
|
|
125
|
+
</Field>
|
|
126
|
+
{error ? (
|
|
127
|
+
<Alert variant="destructive">
|
|
128
|
+
<AlertCircle />
|
|
129
|
+
<AlertDescription>{error}</AlertDescription>
|
|
130
|
+
</Alert>
|
|
131
|
+
) : null}
|
|
132
|
+
<Button
|
|
133
|
+
type="submit"
|
|
134
|
+
className="w-full"
|
|
135
|
+
loading={loading}
|
|
136
|
+
disabled={mismatched || tooShort || !next}
|
|
137
|
+
>
|
|
138
|
+
Set new password
|
|
139
|
+
</Button>
|
|
140
|
+
</form>
|
|
141
|
+
</CardContent>
|
|
142
|
+
</Card>
|
|
143
|
+
);
|
|
144
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { afterEach, describe, expect, mock, test } from "bun:test";
|
|
3
|
+
|
|
4
|
+
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
5
|
+
|
|
6
|
+
import { createClient } from "@nexys/user-management-client";
|
|
7
|
+
|
|
8
|
+
import { AuthProvider } from "../../context/auth-context.js";
|
|
9
|
+
import { SignInForm } from "./sign-in-form.js";
|
|
10
|
+
|
|
11
|
+
const makeFetcher = (responder: (url: string, init: RequestInit) => Response) =>
|
|
12
|
+
mock(async (input: RequestInfo | URL, init?: RequestInit) =>
|
|
13
|
+
responder(input.toString(), init ?? {})
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
document.body.innerHTML = "";
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("<SignInForm /> with Result-based call pattern", () => {
|
|
21
|
+
test("submits the form and calls onSuccess with the returned user", async () => {
|
|
22
|
+
const onSuccess = mock(() => {});
|
|
23
|
+
const fetcher = makeFetcher((url) => {
|
|
24
|
+
if (url.endsWith("/api/me")) {
|
|
25
|
+
return new Response(JSON.stringify({ code: "unauth" }), { status: 401 });
|
|
26
|
+
}
|
|
27
|
+
if (url.endsWith("/api/auth/sign-in/email")) {
|
|
28
|
+
return new Response(
|
|
29
|
+
JSON.stringify({ user: { id: "u1", email: "a@b.co" } }),
|
|
30
|
+
{ status: 200, headers: { "content-type": "application/json" } }
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
return new Response("nope", { status: 404 });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const client = createClient({
|
|
37
|
+
baseUrl: "https://auth.example.com",
|
|
38
|
+
fetch: fetcher as unknown as typeof fetch,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
render(
|
|
42
|
+
<AuthProvider client={client} refreshIntervalMs={0}>
|
|
43
|
+
<SignInForm onSuccess={onSuccess} />
|
|
44
|
+
</AuthProvider>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
fireEvent.change(screen.getByLabelText(/email/i), {
|
|
48
|
+
target: { value: "a@b.co" },
|
|
49
|
+
});
|
|
50
|
+
fireEvent.change(screen.getByLabelText(/password/i), {
|
|
51
|
+
target: { value: "hunter2hunter" },
|
|
52
|
+
});
|
|
53
|
+
fireEvent.click(screen.getByRole("button", { name: /sign in/i }));
|
|
54
|
+
|
|
55
|
+
await waitFor(() => expect(onSuccess).toHaveBeenCalled());
|
|
56
|
+
expect(onSuccess).toHaveBeenCalledWith({ id: "u1", email: "a@b.co" });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("surfaces the API error message inline (no thrown ApiError)", async () => {
|
|
60
|
+
const fetcher = makeFetcher((url) => {
|
|
61
|
+
if (url.endsWith("/api/me")) {
|
|
62
|
+
return new Response(JSON.stringify({}), { status: 401 });
|
|
63
|
+
}
|
|
64
|
+
return new Response(
|
|
65
|
+
JSON.stringify({
|
|
66
|
+
code: "INVALID_EMAIL_OR_PASSWORD",
|
|
67
|
+
message: "Invalid email or password.",
|
|
68
|
+
}),
|
|
69
|
+
{ status: 401, headers: { "content-type": "application/json" } }
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
const client = createClient({
|
|
73
|
+
baseUrl: "https://auth.example.com",
|
|
74
|
+
fetch: fetcher as unknown as typeof fetch,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
render(
|
|
78
|
+
<AuthProvider client={client} refreshIntervalMs={0}>
|
|
79
|
+
<SignInForm />
|
|
80
|
+
</AuthProvider>
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
fireEvent.change(screen.getByLabelText(/email/i), {
|
|
84
|
+
target: { value: "wrong@example.com" },
|
|
85
|
+
});
|
|
86
|
+
fireEvent.change(screen.getByLabelText(/password/i), {
|
|
87
|
+
target: { value: "badpass1" },
|
|
88
|
+
});
|
|
89
|
+
fireEvent.click(screen.getByRole("button", { name: /sign in/i }));
|
|
90
|
+
|
|
91
|
+
await waitFor(() =>
|
|
92
|
+
expect(screen.getByText("Invalid email or password.")).toBeDefined()
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("magic-link flow: requests a link and shows the check-inbox state", async () => {
|
|
97
|
+
const requests: string[] = [];
|
|
98
|
+
const fetcher = makeFetcher((url) => {
|
|
99
|
+
requests.push(url);
|
|
100
|
+
if (url.endsWith("/api/me")) {
|
|
101
|
+
return new Response(JSON.stringify({ code: "unauth" }), { status: 401 });
|
|
102
|
+
}
|
|
103
|
+
if (url.endsWith("/api/auth/sign-in/magic-link")) {
|
|
104
|
+
return new Response(JSON.stringify({ status: true }), {
|
|
105
|
+
status: 200,
|
|
106
|
+
headers: { "content-type": "application/json" },
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return new Response("nope", { status: 404 });
|
|
110
|
+
});
|
|
111
|
+
const client = createClient({
|
|
112
|
+
baseUrl: "https://auth.example.com",
|
|
113
|
+
fetch: fetcher as unknown as typeof fetch,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
render(
|
|
117
|
+
<AuthProvider client={client} refreshIntervalMs={0}>
|
|
118
|
+
<SignInForm />
|
|
119
|
+
</AuthProvider>
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
fireEvent.click(screen.getByRole("button", { name: /email me a sign-in link/i }));
|
|
123
|
+
fireEvent.change(screen.getByLabelText(/email/i), {
|
|
124
|
+
target: { value: "a@b.co" },
|
|
125
|
+
});
|
|
126
|
+
fireEvent.click(screen.getByRole("button", { name: /send sign-in link/i }));
|
|
127
|
+
|
|
128
|
+
await waitFor(() => expect(screen.getByText(/check your inbox/i)).toBeDefined());
|
|
129
|
+
expect(
|
|
130
|
+
requests.some((u) => u.endsWith("/api/auth/sign-in/magic-link"))
|
|
131
|
+
).toBe(true);
|
|
132
|
+
|
|
133
|
+
// "Back to sign-in" returns to the password form.
|
|
134
|
+
fireEvent.click(screen.getByRole("button", { name: /back to sign-in/i }));
|
|
135
|
+
await waitFor(() => expect(screen.getByLabelText(/password/i)).toBeDefined());
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("surfaces a friendly network-error string when fetch throws", async () => {
|
|
139
|
+
const fetcher = makeFetcher((url) => {
|
|
140
|
+
if (url.endsWith("/api/me")) {
|
|
141
|
+
return new Response(JSON.stringify({}), { status: 401 });
|
|
142
|
+
}
|
|
143
|
+
throw new Error("connect ECONNREFUSED");
|
|
144
|
+
});
|
|
145
|
+
const client = createClient({
|
|
146
|
+
baseUrl: "https://auth.example.com",
|
|
147
|
+
fetch: fetcher as unknown as typeof fetch,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
render(
|
|
151
|
+
<AuthProvider client={client} refreshIntervalMs={0}>
|
|
152
|
+
<SignInForm />
|
|
153
|
+
</AuthProvider>
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
fireEvent.change(screen.getByLabelText(/email/i), { target: { value: "a@b.co" } });
|
|
157
|
+
fireEvent.change(screen.getByLabelText(/password/i), {
|
|
158
|
+
target: { value: "hunter2hunter" },
|
|
159
|
+
});
|
|
160
|
+
fireEvent.click(screen.getByRole("button", { name: /sign in/i }));
|
|
161
|
+
|
|
162
|
+
await waitFor(() => expect(screen.getByText(/network error/i)).toBeDefined());
|
|
163
|
+
});
|
|
164
|
+
});
|