@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.
Files changed (78) hide show
  1. package/README.md +61 -0
  2. package/components.json +21 -0
  3. package/package.json +66 -0
  4. package/src/components/audit/audit-log-table.test.tsx +98 -0
  5. package/src/components/audit/audit-log-table.tsx +227 -0
  6. package/src/components/auth/accept-invitation-card.tsx +104 -0
  7. package/src/components/auth/forgot-password-form.tsx +93 -0
  8. package/src/components/auth/reset-password-form.tsx +144 -0
  9. package/src/components/auth/sign-in-form.test.tsx +164 -0
  10. package/src/components/auth/sign-in-form.tsx +504 -0
  11. package/src/components/auth/sign-up-form.tsx +124 -0
  12. package/src/components/layout/app-shell.tsx +189 -0
  13. package/src/components/layout/auth-shell.tsx +28 -0
  14. package/src/components/layout/theme-toggle.tsx +55 -0
  15. package/src/components/layout/user-menu.tsx +84 -0
  16. package/src/components/primitives/empty-state.tsx +40 -0
  17. package/src/components/primitives/page-header.tsx +27 -0
  18. package/src/components/primitives/spinner.tsx +28 -0
  19. package/src/components/profile/api-tokens-card.tsx +238 -0
  20. package/src/components/profile/change-password-form.tsx +159 -0
  21. package/src/components/profile/passkeys-card.tsx +186 -0
  22. package/src/components/profile/profile-card.tsx +107 -0
  23. package/src/components/profile/refresh-tokens-list.tsx +176 -0
  24. package/src/components/profile/two-factor-card.tsx +230 -0
  25. package/src/components/projects/project-consents.tsx +577 -0
  26. package/src/components/projects/project-create-dialog.tsx +193 -0
  27. package/src/components/projects/project-detail-tabs.tsx +64 -0
  28. package/src/components/projects/project-email-templates.tsx +285 -0
  29. package/src/components/projects/project-notices.tsx +461 -0
  30. package/src/components/projects/project-settings.tsx +1059 -0
  31. package/src/components/projects/project-tenants.tsx +108 -0
  32. package/src/components/projects/projects-table.test.tsx +109 -0
  33. package/src/components/projects/projects-table.tsx +240 -0
  34. package/src/components/roles/role-badge.tsx +91 -0
  35. package/src/components/roles/role-select.tsx +76 -0
  36. package/src/components/tenants/tenant-create-dialog.tsx +164 -0
  37. package/src/components/tenants/tenant-detail-tabs.tsx +51 -0
  38. package/src/components/tenants/tenant-members.tsx +587 -0
  39. package/src/components/tenants/tenant-roles.test.tsx +107 -0
  40. package/src/components/tenants/tenant-roles.tsx +418 -0
  41. package/src/components/tenants/tenant-settings.tsx +392 -0
  42. package/src/components/tenants/tenants-table.test.tsx +81 -0
  43. package/src/components/tenants/tenants-table.tsx +247 -0
  44. package/src/components/ui/alert.tsx +52 -0
  45. package/src/components/ui/avatar.tsx +46 -0
  46. package/src/components/ui/badge.tsx +32 -0
  47. package/src/components/ui/button.tsx +64 -0
  48. package/src/components/ui/card.tsx +65 -0
  49. package/src/components/ui/dialog.tsx +99 -0
  50. package/src/components/ui/dropdown-menu.tsx +97 -0
  51. package/src/components/ui/field.tsx +44 -0
  52. package/src/components/ui/input.tsx +23 -0
  53. package/src/components/ui/label.tsx +19 -0
  54. package/src/components/ui/select.tsx +87 -0
  55. package/src/components/ui/separator.tsx +22 -0
  56. package/src/components/ui/skeleton.tsx +13 -0
  57. package/src/components/ui/switch.tsx +29 -0
  58. package/src/components/ui/table.tsx +87 -0
  59. package/src/components/ui/tabs.tsx +51 -0
  60. package/src/components/ui/textarea.tsx +22 -0
  61. package/src/components/ui/tooltip.tsx +27 -0
  62. package/src/components/users/user-create-dialog.tsx +229 -0
  63. package/src/components/users/user-delete-dialog.tsx +88 -0
  64. package/src/components/users/user-detail.tsx +818 -0
  65. package/src/components/users/users-table.test.tsx +107 -0
  66. package/src/components/users/users-table.tsx +386 -0
  67. package/src/context/auth-context.tsx +127 -0
  68. package/src/context/theme-context.test.tsx +78 -0
  69. package/src/context/theme-context.tsx +110 -0
  70. package/src/hooks/use-call.ts +60 -0
  71. package/src/index.ts +160 -0
  72. package/src/lib/error-message.ts +16 -0
  73. package/src/lib/utils.test.ts +61 -0
  74. package/src/lib/utils.ts +79 -0
  75. package/src/lib/webauthn.ts +36 -0
  76. package/src/styles.css +107 -0
  77. package/src/test-setup.ts +5 -0
  78. package/tailwind.preset.cjs +15 -0
@@ -0,0 +1,159 @@
1
+ import { changePassword } from "@nexys/user-management-client";
2
+ import { AlertCircle, KeyRound, ShieldCheck } from "lucide-react";
3
+ import { useState, type FormEvent } 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 const ChangePasswordForm = ({
20
+ minLength = 8,
21
+ }: {
22
+ minLength?: number;
23
+ }) => {
24
+ const client = useUmClient();
25
+ const [current, setCurrent] = useState("");
26
+ const [next, setNext] = useState("");
27
+ const [confirm, setConfirm] = useState("");
28
+ const [loading, setLoading] = useState(false);
29
+ const [error, setError] = useState<string | null>(null);
30
+ const [success, setSuccess] = useState(false);
31
+ const [noPassword, setNoPassword] = useState(false);
32
+
33
+ const mismatched = confirm.length > 0 && confirm !== next;
34
+ const tooShort = next.length > 0 && next.length < minLength;
35
+
36
+ const submit = async (e: FormEvent) => {
37
+ e.preventDefault();
38
+ if (mismatched || tooShort) return;
39
+ setLoading(true);
40
+ setError(null);
41
+ setSuccess(false);
42
+ const res = await client.call(changePassword, {
43
+ currentPassword: current,
44
+ newPassword: next,
45
+ });
46
+ setLoading(false);
47
+ if (res.ok) {
48
+ setSuccess(true);
49
+ setCurrent("");
50
+ setNext("");
51
+ setConfirm("");
52
+ } else if (res.error.kind === "http" && res.error.code === "no_password_set") {
53
+ // Social/passkey-only account — there is no password to change.
54
+ setNoPassword(true);
55
+ } else {
56
+ setError(errorMessage(res.error, "Couldn't change password."));
57
+ }
58
+ };
59
+
60
+ if (noPassword) {
61
+ return (
62
+ <Card>
63
+ <CardHeader>
64
+ <CardTitle className="flex items-center gap-2">
65
+ <KeyRound className="size-4 text-muted-foreground" />
66
+ Change password
67
+ </CardTitle>
68
+ <CardDescription>
69
+ This account has no password — you sign in with a social provider
70
+ or passkey. Ask an administrator to email you a set-password link
71
+ if you'd like one.
72
+ </CardDescription>
73
+ </CardHeader>
74
+ </Card>
75
+ );
76
+ }
77
+
78
+ return (
79
+ <Card>
80
+ <CardHeader>
81
+ <CardTitle className="flex items-center gap-2">
82
+ <KeyRound className="size-4 text-muted-foreground" />
83
+ Change password
84
+ </CardTitle>
85
+ <CardDescription>
86
+ Use a long, unique password. We'll keep you signed in on this device.
87
+ </CardDescription>
88
+ </CardHeader>
89
+ <CardContent>
90
+ <form onSubmit={submit} className="grid gap-4">
91
+ <Field label="Current password" htmlFor="current-pw" required>
92
+ <Input
93
+ id="current-pw"
94
+ type="password"
95
+ autoComplete="current-password"
96
+ required
97
+ value={current}
98
+ onChange={(e) => setCurrent(e.target.value)}
99
+ />
100
+ </Field>
101
+ <Field
102
+ label="New password"
103
+ htmlFor="next-pw"
104
+ required
105
+ description={`At least ${minLength} characters.`}
106
+ error={tooShort ? `New password is too short.` : undefined}
107
+ >
108
+ <Input
109
+ id="next-pw"
110
+ type="password"
111
+ autoComplete="new-password"
112
+ required
113
+ value={next}
114
+ onChange={(e) => setNext(e.target.value)}
115
+ aria-invalid={tooShort || undefined}
116
+ />
117
+ </Field>
118
+ <Field
119
+ label="Confirm new password"
120
+ htmlFor="confirm-pw"
121
+ required
122
+ error={mismatched ? "Passwords don't match." : undefined}
123
+ >
124
+ <Input
125
+ id="confirm-pw"
126
+ type="password"
127
+ autoComplete="new-password"
128
+ required
129
+ value={confirm}
130
+ onChange={(e) => setConfirm(e.target.value)}
131
+ aria-invalid={mismatched || undefined}
132
+ />
133
+ </Field>
134
+ {success ? (
135
+ <Alert variant="success">
136
+ <ShieldCheck />
137
+ <AlertDescription>Your password has been updated.</AlertDescription>
138
+ </Alert>
139
+ ) : null}
140
+ {error ? (
141
+ <Alert variant="destructive">
142
+ <AlertCircle />
143
+ <AlertDescription>{error}</AlertDescription>
144
+ </Alert>
145
+ ) : null}
146
+ <div className="flex justify-end">
147
+ <Button
148
+ type="submit"
149
+ loading={loading}
150
+ disabled={mismatched || tooShort || !current || !next}
151
+ >
152
+ Update password
153
+ </Button>
154
+ </div>
155
+ </form>
156
+ </CardContent>
157
+ </Card>
158
+ );
159
+ };
@@ -0,0 +1,186 @@
1
+ import {
2
+ deleteOwnPasskey,
3
+ listPasskeys,
4
+ passkeyRegisterFinish,
5
+ passkeyRegisterStart,
6
+ } from "@nexys/user-management-client";
7
+ import { AlertCircle, Fingerprint, Plus, Trash2 } from "lucide-react";
8
+ import { useState, type FormEvent } from "react";
9
+
10
+ import { useUmClient } from "../../context/auth-context.js";
11
+ import { useCall } from "../../hooks/use-call.js";
12
+ import { errorMessage } from "../../lib/error-message.js";
13
+ import { formatRelative } from "../../lib/utils.js";
14
+ import {
15
+ createPasskey,
16
+ webauthnErrorMessage,
17
+ webauthnSupported,
18
+ } from "../../lib/webauthn.js";
19
+ import { EmptyState } from "../primitives/empty-state.js";
20
+ import { Alert, AlertDescription } from "../ui/alert.js";
21
+ import { Button } from "../ui/button.js";
22
+ import {
23
+ Card,
24
+ CardContent,
25
+ CardDescription,
26
+ CardHeader,
27
+ CardTitle,
28
+ } from "../ui/card.js";
29
+ import { Input } from "../ui/input.js";
30
+ import {
31
+ Table,
32
+ TableBody,
33
+ TableCell,
34
+ TableRow,
35
+ } from "../ui/table.js";
36
+
37
+ /** List, add and remove the signed-in user's passkeys. */
38
+ export const PasskeysCard = () => {
39
+ const client = useUmClient();
40
+ const { data, loading, error, refresh } = useCall(listPasskeys);
41
+ const [name, setName] = useState("");
42
+ const [adding, setAdding] = useState(false);
43
+ const [busy, setBusy] = useState<string | null>(null);
44
+ const [actionError, setActionError] = useState<string | null>(null);
45
+
46
+ const supported = webauthnSupported();
47
+ const passkeys = data?.passkeys ?? [];
48
+
49
+ const add = async (e: FormEvent) => {
50
+ e.preventDefault();
51
+ setAdding(true);
52
+ setActionError(null);
53
+ try {
54
+ const start = await client.call(passkeyRegisterStart);
55
+ if (!start.ok) {
56
+ setActionError(errorMessage(start.error, "Couldn't start passkey setup."));
57
+ return;
58
+ }
59
+ const credential = await createPasskey(start.data.options);
60
+ const finish = await client.call(passkeyRegisterFinish, {
61
+ challenge: start.data.challenge,
62
+ response: credential,
63
+ name: name.trim() || undefined,
64
+ });
65
+ if (!finish.ok) {
66
+ setActionError(errorMessage(finish.error, "Couldn't save the passkey."));
67
+ return;
68
+ }
69
+ setName("");
70
+ await refresh();
71
+ } catch (err) {
72
+ // The browser throws when the user cancels the dialog — and with
73
+ // a cryptic InvalidStateError when this device already holds a
74
+ // passkey for the site; translate those into plain language.
75
+ setActionError(webauthnErrorMessage(err, "Passkey setup failed."));
76
+ } finally {
77
+ setAdding(false);
78
+ }
79
+ };
80
+
81
+ const remove = async (id: string) => {
82
+ setBusy(id);
83
+ setActionError(null);
84
+ const res = await client.call(deleteOwnPasskey, { id });
85
+ setBusy(null);
86
+ if (res.ok) {
87
+ await refresh();
88
+ } else {
89
+ setActionError(errorMessage(res.error, "Couldn't remove the passkey."));
90
+ }
91
+ };
92
+
93
+ return (
94
+ <Card>
95
+ <CardHeader>
96
+ <CardTitle className="flex items-center gap-2">
97
+ <Fingerprint className="size-4 text-muted-foreground" />
98
+ Passkeys
99
+ </CardTitle>
100
+ <CardDescription>
101
+ Sign in with your device's fingerprint, face or PIN instead of a
102
+ password.
103
+ </CardDescription>
104
+ </CardHeader>
105
+ <CardContent className="grid gap-4">
106
+ {error ? (
107
+ <Alert variant="destructive">
108
+ <AlertCircle />
109
+ <AlertDescription>{errorMessage(error)}</AlertDescription>
110
+ </Alert>
111
+ ) : null}
112
+ {actionError ? (
113
+ <Alert variant="destructive">
114
+ <AlertCircle />
115
+ <AlertDescription>{actionError}</AlertDescription>
116
+ </Alert>
117
+ ) : null}
118
+ {!supported ? (
119
+ <Alert>
120
+ <AlertCircle />
121
+ <AlertDescription>
122
+ This browser doesn't support passkeys.
123
+ </AlertDescription>
124
+ </Alert>
125
+ ) : (
126
+ <form onSubmit={add} className="flex items-end gap-3">
127
+ <div className="grid flex-1 gap-1.5">
128
+ <label
129
+ htmlFor="passkey-name"
130
+ className="text-sm font-medium leading-none"
131
+ >
132
+ Name (optional)
133
+ </label>
134
+ <Input
135
+ id="passkey-name"
136
+ value={name}
137
+ onChange={(e) => setName(e.target.value)}
138
+ placeholder="e.g. MacBook Touch ID"
139
+ />
140
+ </div>
141
+ <Button type="submit" loading={adding}>
142
+ <Plus />
143
+ Add passkey
144
+ </Button>
145
+ </form>
146
+ )}
147
+
148
+ {loading ? null : passkeys.length === 0 ? (
149
+ <EmptyState
150
+ icon={Fingerprint}
151
+ title="No passkeys yet"
152
+ description="Add one to sign in without a password."
153
+ />
154
+ ) : (
155
+ <div className="overflow-hidden rounded-lg border">
156
+ <Table>
157
+ <TableBody>
158
+ {passkeys.map((p) => (
159
+ <TableRow key={p.id}>
160
+ <TableCell className="font-medium">
161
+ {p.name || "Unnamed passkey"}
162
+ </TableCell>
163
+ <TableCell className="text-sm text-muted-foreground">
164
+ {p.createdAt ? `Added ${formatRelative(p.createdAt)}` : ""}
165
+ </TableCell>
166
+ <TableCell className="text-right">
167
+ <Button
168
+ variant="ghost"
169
+ size="icon"
170
+ onClick={() => remove(p.id)}
171
+ loading={busy === p.id}
172
+ aria-label={`Remove passkey ${p.name ?? p.id}`}
173
+ >
174
+ <Trash2 className="text-destructive" />
175
+ </Button>
176
+ </TableCell>
177
+ </TableRow>
178
+ ))}
179
+ </TableBody>
180
+ </Table>
181
+ </div>
182
+ )}
183
+ </CardContent>
184
+ </Card>
185
+ );
186
+ };
@@ -0,0 +1,107 @@
1
+ import { updateProfile } from "@nexys/user-management-client";
2
+ import { AlertCircle, Check, Pencil, X } from "lucide-react";
3
+ import { useState, type FormEvent } from "react";
4
+
5
+ import { useAuth } from "../../context/auth-context.js";
6
+ import { errorMessage } from "../../lib/error-message.js";
7
+ import { initialsOf } from "../../lib/utils.js";
8
+ import { Alert, AlertDescription } from "../ui/alert.js";
9
+ import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar.js";
10
+ import { Badge } from "../ui/badge.js";
11
+ import { Button } from "../ui/button.js";
12
+ import {
13
+ Card,
14
+ CardContent,
15
+ CardDescription,
16
+ CardHeader,
17
+ CardTitle,
18
+ } from "../ui/card.js";
19
+ import { Field } from "../ui/field.js";
20
+ import { Input } from "../ui/input.js";
21
+
22
+ export const ProfileCard = ({ image }: { image?: string | null }) => {
23
+ const { client, data, refresh } = useAuth();
24
+ const [editing, setEditing] = useState(false);
25
+ const [name, setName] = useState(data?.user.name ?? "");
26
+ const [saving, setSaving] = useState(false);
27
+ const [error, setError] = useState<string | null>(null);
28
+
29
+ if (!data) return null;
30
+ const { user } = data;
31
+
32
+ const save = async (e: FormEvent) => {
33
+ e.preventDefault();
34
+ setSaving(true);
35
+ setError(null);
36
+ const res = await client.call(updateProfile, { name: name.trim() });
37
+ setSaving(false);
38
+ if (res.ok) {
39
+ await refresh();
40
+ setEditing(false);
41
+ } else {
42
+ setError(errorMessage(res.error, "Couldn't save changes."));
43
+ }
44
+ };
45
+
46
+ return (
47
+ <Card>
48
+ <CardHeader className="flex flex-row items-start gap-4 space-y-0">
49
+ <Avatar className="size-14 ring-2 ring-background">
50
+ {image ? <AvatarImage src={image} alt={user.name ?? user.email} /> : null}
51
+ <AvatarFallback>{initialsOf(user.name, user.email)}</AvatarFallback>
52
+ </Avatar>
53
+ <div className="flex flex-1 flex-col gap-1">
54
+ <CardTitle className="leading-tight">{user.name ?? user.email}</CardTitle>
55
+ <CardDescription className="flex flex-wrap items-center gap-2 text-xs">
56
+ <span>{user.email}</span>
57
+ <Badge variant="muted">{user.role}</Badge>
58
+ </CardDescription>
59
+ </div>
60
+ {!editing && (
61
+ <Button size="sm" variant="outline" onClick={() => setEditing(true)}>
62
+ <Pencil />
63
+ Edit
64
+ </Button>
65
+ )}
66
+ </CardHeader>
67
+ {editing && (
68
+ <CardContent>
69
+ <form onSubmit={save} className="grid gap-4">
70
+ <Field label="Display name" htmlFor="display-name" required>
71
+ <Input
72
+ id="display-name"
73
+ value={name}
74
+ onChange={(e) => setName(e.target.value)}
75
+ autoFocus
76
+ />
77
+ </Field>
78
+ {error ? (
79
+ <Alert variant="destructive">
80
+ <AlertCircle />
81
+ <AlertDescription>{error}</AlertDescription>
82
+ </Alert>
83
+ ) : null}
84
+ <div className="flex justify-end gap-2">
85
+ <Button
86
+ type="button"
87
+ variant="ghost"
88
+ onClick={() => {
89
+ setName(user.name ?? "");
90
+ setEditing(false);
91
+ setError(null);
92
+ }}
93
+ >
94
+ <X />
95
+ Cancel
96
+ </Button>
97
+ <Button type="submit" loading={saving} disabled={!name.trim()}>
98
+ <Check />
99
+ Save
100
+ </Button>
101
+ </div>
102
+ </form>
103
+ </CardContent>
104
+ )}
105
+ </Card>
106
+ );
107
+ };
@@ -0,0 +1,176 @@
1
+ import {
2
+ listRefreshTokens,
3
+ revokeAllRefreshTokens,
4
+ revokeRefreshToken,
5
+ } from "@nexys/user-management-client";
6
+ import {
7
+ AlertCircle,
8
+ Globe,
9
+ Laptop,
10
+ ShieldOff,
11
+ Smartphone,
12
+ } from "lucide-react";
13
+ import { useState } from "react";
14
+
15
+ import { useUmClient } from "../../context/auth-context.js";
16
+ import { useCall } from "../../hooks/use-call.js";
17
+ import { errorMessage } from "../../lib/error-message.js";
18
+ import { formatDateTime, formatRelative, parseUserAgent } from "../../lib/utils.js";
19
+ import { EmptyState } from "../primitives/empty-state.js";
20
+ import { Spinner } from "../primitives/spinner.js";
21
+ import { Alert, AlertDescription } from "../ui/alert.js";
22
+ import { Badge } from "../ui/badge.js";
23
+ import { Button } from "../ui/button.js";
24
+ import {
25
+ Card,
26
+ CardContent,
27
+ CardDescription,
28
+ CardHeader,
29
+ CardTitle,
30
+ } from "../ui/card.js";
31
+ import { Skeleton } from "../ui/skeleton.js";
32
+ import {
33
+ Table,
34
+ TableBody,
35
+ TableCell,
36
+ TableHead,
37
+ TableHeader,
38
+ TableRow,
39
+ } from "../ui/table.js";
40
+
41
+ const Device = ({ ua }: { ua: string | null }) => {
42
+ const { browser, os } = parseUserAgent(ua);
43
+ const Icon = /Android|iOS/.test(ua ?? "") ? Smartphone : Laptop;
44
+ return (
45
+ <div className="flex items-center gap-2">
46
+ <Icon className="size-4 text-muted-foreground" aria-hidden />
47
+ <div className="flex flex-col leading-tight">
48
+ <span className="text-sm font-medium">{browser}</span>
49
+ <span className="text-xs text-muted-foreground">{os}</span>
50
+ </div>
51
+ </div>
52
+ );
53
+ };
54
+
55
+ export const RefreshTokensList = () => {
56
+ const client = useUmClient();
57
+ const { data, error, loading, refresh, setData } = useCall(listRefreshTokens);
58
+ const [revokingId, setRevokingId] = useState<string | null>(null);
59
+ const [revokingAll, setRevokingAll] = useState(false);
60
+
61
+ const revokeOne = async (id: string) => {
62
+ setRevokingId(id);
63
+ const res = await client.call(revokeRefreshToken, { id });
64
+ setRevokingId(null);
65
+ if (res.ok) setData((data ?? []).filter((t) => t.id !== id));
66
+ };
67
+
68
+ const revokeOthers = async () => {
69
+ setRevokingAll(true);
70
+ const res = await client.call(revokeAllRefreshTokens);
71
+ setRevokingAll(false);
72
+ if (res.ok) await refresh();
73
+ };
74
+
75
+ const tokens = (data ?? []).filter((t) => !t.revokedAt);
76
+ const others = tokens.filter((t) => !t.current);
77
+
78
+ return (
79
+ <Card>
80
+ <CardHeader className="flex flex-row items-center justify-between space-y-0">
81
+ <div>
82
+ <CardTitle className="flex items-center gap-2">
83
+ <Globe className="size-4 text-muted-foreground" />
84
+ Active sessions
85
+ </CardTitle>
86
+ <CardDescription>
87
+ Devices currently signed in with your account.
88
+ </CardDescription>
89
+ </div>
90
+ {others.length > 0 && (
91
+ <Button
92
+ variant="outline"
93
+ size="sm"
94
+ onClick={revokeOthers}
95
+ loading={revokingAll}
96
+ >
97
+ <ShieldOff />
98
+ Sign out other sessions
99
+ </Button>
100
+ )}
101
+ </CardHeader>
102
+ <CardContent>
103
+ {loading ? (
104
+ <div className="grid gap-2">
105
+ <Skeleton className="h-12" />
106
+ <Skeleton className="h-12" />
107
+ <Skeleton className="h-12" />
108
+ </div>
109
+ ) : error ? (
110
+ <Alert variant="destructive">
111
+ <AlertCircle />
112
+ <AlertDescription>{errorMessage(error)}</AlertDescription>
113
+ </Alert>
114
+ ) : tokens.length === 0 ? (
115
+ <EmptyState
116
+ icon={Globe}
117
+ title="No active sessions"
118
+ description="Sign-ins from new devices will appear here."
119
+ />
120
+ ) : (
121
+ <Table>
122
+ <TableHeader>
123
+ <TableRow>
124
+ <TableHead>Device</TableHead>
125
+ <TableHead>IP</TableHead>
126
+ <TableHead>Created</TableHead>
127
+ <TableHead>Expires</TableHead>
128
+ <TableHead className="text-right">Actions</TableHead>
129
+ </TableRow>
130
+ </TableHeader>
131
+ <TableBody>
132
+ {tokens.map((t) => (
133
+ <TableRow key={t.id}>
134
+ <TableCell>
135
+ <div className="flex items-center gap-2">
136
+ <Device ua={t.userAgent} />
137
+ {t.current && (
138
+ <Badge variant="success" className="ml-1">
139
+ This device
140
+ </Badge>
141
+ )}
142
+ </div>
143
+ </TableCell>
144
+ <TableCell className="font-mono text-xs">
145
+ {t.ipAddress ?? "—"}
146
+ </TableCell>
147
+ <TableCell title={formatDateTime(t.createdAt)} className="text-sm">
148
+ {formatRelative(t.createdAt)}
149
+ </TableCell>
150
+ <TableCell title={formatDateTime(t.expiresAt)} className="text-sm">
151
+ {formatRelative(t.expiresAt)}
152
+ </TableCell>
153
+ <TableCell className="text-right">
154
+ {t.current ? (
155
+ <span className="text-xs text-muted-foreground">—</span>
156
+ ) : (
157
+ <Button
158
+ variant="ghost"
159
+ size="sm"
160
+ onClick={() => revokeOne(t.id)}
161
+ loading={revokingId === t.id}
162
+ >
163
+ Revoke
164
+ </Button>
165
+ )}
166
+ </TableCell>
167
+ </TableRow>
168
+ ))}
169
+ </TableBody>
170
+ </Table>
171
+ )}
172
+ {loading && <Spinner size="sm" className="mt-2" />}
173
+ </CardContent>
174
+ </Card>
175
+ );
176
+ };