-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProfile.tsx
More file actions
885 lines (817 loc) · 27.8 KB
/
Profile.tsx
File metadata and controls
885 lines (817 loc) · 27.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
import { useState, useEffect, useCallback } from "react";
import { toast } from "sonner";
import { authClient, useSession } from "@/lib/auth-client";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Badge } from "@/components/ui/badge";
import { Separator } from "@/components/ui/separator";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import {
MonitorIcon,
SmartphoneIcon,
LinkIcon,
UnlinkIcon,
ShieldIcon,
Loader2Icon,
KeyIcon,
CopyIcon,
CheckIcon,
} from "lucide-react";
import { BASE_PATH } from "@/lib/config";
interface SessionInfo {
id: string;
token: string;
ipAddress: string | null;
userAgent: string | null;
createdAt: string;
expiresAt: string;
}
interface AccountInfo {
id: string;
providerId: string;
accountId: string;
createdAt: string;
}
// Known social providers the system supports.
// Extend this list as new providers are configured in Better Auth.
const KNOWN_PROVIDERS = ["github", "google", "microsoft", "apple"] as const;
function parseUserAgent(ua: string | null): {
browser: string;
device: string;
} {
if (!ua) return { browser: "Unknown", device: "Unknown" };
let browser = "Unknown";
if (ua.includes("Edg/") || ua.includes("Edge/")) browser = "Edge";
else if (ua.includes("Chrome/")) browser = "Chrome";
else if (ua.includes("Firefox/")) browser = "Firefox";
else if (ua.includes("Safari/") && !ua.includes("Chrome/"))
browser = "Safari";
let device = "Desktop";
if (/Mobile|Android|iPhone|iPad/i.test(ua)) device = "Mobile";
return { browser, device };
}
function providerDisplayName(provider: string): string {
const names: Record<string, string> = {
github: "GitHub",
google: "Google",
microsoft: "Microsoft",
apple: "Apple",
credential: "Email & Password",
};
return names[provider] || provider.charAt(0).toUpperCase() + provider.slice(1);
}
function ProfileTab() {
const { data: session, isPending } = useSession();
const [name, setName] = useState("");
const [saving, setSaving] = useState(false);
useEffect(() => {
if (session?.user?.name) {
setName(session.user.name);
}
}, [session]);
async function handleSave() {
setSaving(true);
try {
const result = await authClient.updateUser({ name });
if (result.error) {
toast.error(result.error.message || "Failed to update profile.");
return;
}
toast.success("Profile updated.");
} catch {
toast.error("An unexpected error occurred.");
} finally {
setSaving(false);
}
}
if (isPending) {
return (
<div className="flex justify-center py-8">
<Loader2Icon className="size-6 animate-spin text-muted-foreground" />
</div>
);
}
if (!session) return null;
const initials =
session.user.name
?.split(" ")
.map((n) => n[0])
.join("")
.toUpperCase() || "?";
return (
<Card>
<CardHeader>
<CardTitle>Profile Information</CardTitle>
<CardDescription>Update your display name and avatar</CardDescription>
</CardHeader>
<CardContent>
<div className="flex flex-col gap-6">
<div className="flex items-center gap-4">
<Avatar className="h-16 w-16" size="lg">
<AvatarImage src={session.user.image || undefined} />
<AvatarFallback className="text-lg">{initials}</AvatarFallback>
</Avatar>
<div>
<p className="font-medium">{session.user.name}</p>
<p className="text-sm text-muted-foreground">
{session.user.email}
</p>
</div>
</div>
<Separator />
<div className="flex flex-col gap-4 max-w-md">
<div className="flex flex-col gap-2">
<Label htmlFor="profile-name">Display Name</Label>
<Input
id="profile-name"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="Your name"
/>
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="profile-email">Email</Label>
<Input
id="profile-email"
value={session.user.email}
disabled
readOnly
/>
<p className="text-xs text-muted-foreground">
Email cannot be changed
</p>
</div>
<Button
onClick={handleSave}
disabled={saving || name === session.user.name}
className="w-fit"
>
{saving ? "Saving..." : "Save Changes"}
</Button>
</div>
</div>
</CardContent>
</Card>
);
}
function SecurityTab() {
const [currentPassword, setCurrentPassword] = useState("");
const [newPassword, setNewPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
async function handleChangePassword(e: React.FormEvent) {
e.preventDefault();
setError("");
if (newPassword !== confirmPassword) {
setError("Passwords do not match.");
return;
}
setLoading(true);
try {
const result = await authClient.changePassword({
currentPassword,
newPassword,
revokeOtherSessions: false,
});
if (result.error) {
setError(result.error.message || "Failed to change password.");
return;
}
toast.success("Password changed successfully.");
setCurrentPassword("");
setNewPassword("");
setConfirmPassword("");
} catch {
setError("An unexpected error occurred.");
} finally {
setLoading(false);
}
}
return (
<Card>
<CardHeader>
<CardTitle>Change Password</CardTitle>
<CardDescription>Update your account password</CardDescription>
</CardHeader>
<CardContent>
<form onSubmit={handleChangePassword} className="flex flex-col gap-4 max-w-md">
<div className="flex flex-col gap-2">
<Label htmlFor="current-password">Current Password</Label>
<Input
id="current-password"
type="password"
value={currentPassword}
onChange={(e) => setCurrentPassword(e.target.value)}
required
autoComplete="current-password"
/>
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="new-password">New Password</Label>
<Input
id="new-password"
type="password"
value={newPassword}
onChange={(e) => setNewPassword(e.target.value)}
required
minLength={8}
autoComplete="new-password"
/>
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="confirm-password">Confirm New Password</Label>
<Input
id="confirm-password"
type="password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
required
minLength={8}
autoComplete="new-password"
/>
</div>
{error && (
<p className="text-sm text-destructive">{error}</p>
)}
<Button type="submit" className="w-fit" disabled={loading}>
{loading ? "Changing..." : "Change Password"}
</Button>
</form>
</CardContent>
</Card>
);
}
// --- Linked Accounts Tab (T045 + T047 lockout protection) ---
function LinkedAccountsTab() {
const [accounts, setAccounts] = useState<AccountInfo[]>([]);
const [loading, setLoading] = useState(true);
const [unlinking, setUnlinking] = useState<string | null>(null);
const [linking, setLinking] = useState<string | null>(null);
const fetchAccounts = useCallback(async () => {
setLoading(true);
try {
const result = await authClient.listAccounts();
if (result.data) {
setAccounts(result.data as unknown as AccountInfo[]);
}
} catch {
toast.error("Failed to load linked accounts.");
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
fetchAccounts();
}, [fetchAccounts]);
// T047: Check if user has at least one other auth method before allowing unlink.
// The user must retain at least one linked account (social or credential).
const canUnlink = accounts.length > 1;
async function handleUnlink(providerId: string) {
setUnlinking(providerId);
try {
const result = await authClient.unlinkAccount({ providerId });
if (result.error) {
toast.error(
result.error.message || "Failed to unlink account."
);
return;
}
toast.success(`${providerDisplayName(providerId)} account unlinked.`);
fetchAccounts();
} catch {
toast.error("Failed to unlink account.");
} finally {
setUnlinking(null);
}
}
async function handleLink(provider: string) {
setLinking(provider);
try {
await authClient.signIn.social({
provider: provider as "github" | "google" | "microsoft" | "apple",
callbackURL: window.location.href,
});
} catch {
toast.error(`Failed to link ${providerDisplayName(provider)} account.`);
setLinking(null);
}
}
if (loading) {
return (
<div className="flex justify-center py-8">
<Loader2Icon className="size-6 animate-spin text-muted-foreground" />
</div>
);
}
const linkedProviders = accounts.map((a) => a.providerId);
const unlinkedProviders = KNOWN_PROVIDERS.filter(
(p) => !linkedProviders.includes(p)
);
return (
<Card>
<CardHeader>
<CardTitle>Linked Accounts</CardTitle>
<CardDescription>
Manage your connected authentication providers
</CardDescription>
</CardHeader>
<CardContent>
<div className="flex flex-col gap-4">
{/* Linked accounts */}
{accounts.length === 0 ? (
<p className="text-sm text-muted-foreground">
No linked accounts found.
</p>
) : (
accounts.map((account) => (
<div
key={account.id}
className="flex items-center justify-between rounded-md border p-4"
>
<div className="flex items-center gap-3">
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-muted">
<LinkIcon className="size-4" />
</div>
<div>
<p className="text-sm font-medium">
{providerDisplayName(account.providerId)}
</p>
<p className="text-xs text-muted-foreground">
Linked{" "}
{account.createdAt
? new Date(account.createdAt).toLocaleDateString()
: ""}
</p>
</div>
</div>
{account.providerId !== "credential" && (
<div className="relative group">
<Button
variant="ghost"
size="sm"
disabled={!canUnlink || unlinking === account.providerId}
onClick={() => handleUnlink(account.providerId)}
>
<UnlinkIcon className="size-4 mr-1" />
{unlinking === account.providerId
? "Unlinking..."
: "Unlink"}
</Button>
{!canUnlink && (
<div className="absolute bottom-full right-0 mb-2 hidden group-hover:block w-56 rounded-md bg-popover border p-2 shadow-md text-xs text-muted-foreground z-50">
Cannot unlink your only authentication method. Link
another provider or set a password first.
</div>
)}
</div>
)}
</div>
))
)}
{/* Unlinked providers */}
{unlinkedProviders.length > 0 && (
<>
<Separator />
<div>
<p className="text-sm font-medium mb-3">
Available Providers
</p>
<div className="flex flex-wrap gap-2">
{unlinkedProviders.map((provider) => (
<Button
key={provider}
variant="outline"
size="sm"
disabled={linking === provider}
onClick={() => handleLink(provider)}
>
<LinkIcon className="size-4 mr-1" />
{linking === provider
? "Linking..."
: `Link ${providerDisplayName(provider)}`}
</Button>
))}
</div>
</div>
</>
)}
</div>
</CardContent>
</Card>
);
}
// --- Sessions Tab (T046) ---
function SessionsTab() {
const { data: currentSession } = useSession();
const [sessions, setSessions] = useState<SessionInfo[]>([]);
const [loading, setLoading] = useState(true);
const [revoking, setRevoking] = useState<string | null>(null);
const fetchSessions = useCallback(async () => {
setLoading(true);
try {
const result = await authClient.listSessions();
if (result.data) {
setSessions(result.data as unknown as SessionInfo[]);
}
} catch {
toast.error("Failed to load sessions.");
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
fetchSessions();
}, [fetchSessions]);
async function handleRevoke(sessionToken: string) {
setRevoking(sessionToken);
try {
const result = await authClient.revokeSession({ token: sessionToken });
if (result.error) {
toast.error(result.error.message || "Failed to revoke session.");
return;
}
toast.success("Session revoked.");
fetchSessions();
} catch {
toast.error("Failed to revoke session.");
} finally {
setRevoking(null);
}
}
if (loading) {
return (
<div className="flex justify-center py-8">
<Loader2Icon className="size-6 animate-spin text-muted-foreground" />
</div>
);
}
const currentToken = currentSession?.session?.token;
return (
<Card>
<CardHeader>
<CardTitle>Active Sessions</CardTitle>
<CardDescription>
Manage your active sessions across devices ({sessions.length} total)
</CardDescription>
</CardHeader>
<CardContent>
<div className="flex flex-col gap-3">
{sessions.length === 0 ? (
<p className="text-sm text-muted-foreground">
No active sessions found.
</p>
) : (
sessions.map((session) => {
const { browser, device } = parseUserAgent(session.userAgent);
const isCurrent = session.token === currentToken;
const DeviceIcon =
device === "Mobile" ? SmartphoneIcon : MonitorIcon;
return (
<div
key={session.id}
className="flex items-center justify-between rounded-md border p-4"
>
<div className="flex items-center gap-3">
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-muted">
<DeviceIcon className="size-4" />
</div>
<div>
<div className="flex items-center gap-2">
<p className="text-sm font-medium">
{browser} on {device}
</p>
{isCurrent && (
<Badge variant="default" className="text-xs">
<ShieldIcon className="size-3 mr-0.5" />
Current
</Badge>
)}
</div>
<div className="flex items-center gap-2 text-xs text-muted-foreground">
{session.ipAddress && (
<span className="font-mono">
{session.ipAddress}
</span>
)}
<span>
Created{" "}
{new Date(session.createdAt).toLocaleDateString()}
</span>
</div>
</div>
</div>
{!isCurrent && (
<Button
variant="ghost"
size="sm"
disabled={revoking === session.token}
onClick={() => handleRevoke(session.token)}
>
{revoking === session.token ? "Revoking..." : "Revoke"}
</Button>
)}
</div>
);
})
)}
</div>
</CardContent>
</Card>
);
}
interface ApiKeyInfo {
id: string;
name: string;
key_prefix: string;
lastUsedAt: string | null;
expiresAt: string | null;
revokedAt: string | null;
createdAt: string;
}
function getKeyStatus(key: ApiKeyInfo): { label: string; variant: "default" | "secondary" | "destructive" | "outline" } {
if (key.revokedAt) return { label: "Revoked", variant: "destructive" };
if (key.expiresAt && new Date(key.expiresAt) < new Date()) return { label: "Expired", variant: "secondary" };
return { label: "Active", variant: "default" };
}
function ApiKeysTab() {
const [keys, setKeys] = useState<ApiKeyInfo[]>([]);
const [loading, setLoading] = useState(true);
const [creating, setCreating] = useState(false);
const [revoking, setRevoking] = useState<string | null>(null);
const [showCreateDialog, setShowCreateDialog] = useState(false);
const [newKeyName, setNewKeyName] = useState("");
const [newKeyExpiry, setNewKeyExpiry] = useState("");
const [createdKey, setCreatedKey] = useState<string | null>(null);
const [copied, setCopied] = useState(false);
const fetchKeys = useCallback(async () => {
setLoading(true);
try {
const res = await fetch(`${BASE_PATH}/api/api-keys`, { credentials: "include" });
if (!res.ok) throw new Error("Failed to fetch keys");
setKeys(await res.json());
} catch {
toast.error("Failed to load API keys.");
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
fetchKeys();
}, [fetchKeys]);
async function handleCreate(e: React.FormEvent) {
e.preventDefault();
setCreating(true);
try {
const body: Record<string, string> = { name: newKeyName };
if (newKeyExpiry) body.expiresAt = new Date(newKeyExpiry).toISOString();
const res = await fetch(`${BASE_PATH}/api/api-keys`, {
method: "POST",
headers: { "Content-Type": "application/json" },
credentials: "include",
body: JSON.stringify(body),
});
if (!res.ok) {
const data = await res.json().catch(() => ({}));
throw new Error(data.error || "Failed to create key");
}
const data = await res.json();
setCreatedKey(data.key);
setShowCreateDialog(false);
setNewKeyName("");
setNewKeyExpiry("");
fetchKeys();
toast.success("API key created.");
} catch (err: any) {
toast.error(err.message || "Failed to create API key.");
} finally {
setCreating(false);
}
}
async function handleRevoke(id: string) {
setRevoking(id);
try {
const res = await fetch(`${BASE_PATH}/api/api-keys/${id}`, {
method: "DELETE",
credentials: "include",
});
if (!res.ok) throw new Error("Failed to revoke key");
toast.success("API key revoked.");
fetchKeys();
} catch {
toast.error("Failed to revoke API key.");
} finally {
setRevoking(null);
}
}
async function handleCopy() {
if (!createdKey) return;
await navigator.clipboard.writeText(createdKey);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
}
if (loading) {
return (
<div className="flex justify-center py-8">
<Loader2Icon className="size-6 animate-spin text-muted-foreground" />
</div>
);
}
return (
<>
<Card>
<CardHeader className="flex flex-row items-center justify-between">
<div>
<CardTitle>API Keys</CardTitle>
<CardDescription>
Manage API keys for MCP server authentication
</CardDescription>
</div>
<Button onClick={() => setShowCreateDialog(true)}>
<KeyIcon className="size-4 mr-1" />
Create API Key
</Button>
</CardHeader>
<CardContent>
<div className="flex flex-col gap-3">
{keys.length === 0 ? (
<p className="text-sm text-muted-foreground">
No API keys yet. Create one to get started with the MCP server.
</p>
) : (
keys.map((key) => {
const status = getKeyStatus(key);
const isActive = status.label === "Active";
return (
<div
key={key.id}
className="flex items-center justify-between rounded-md border p-4"
>
<div className="flex items-center gap-3">
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-muted">
<KeyIcon className="size-4" />
</div>
<div>
<div className="flex items-center gap-2">
<p className="text-sm font-medium">{key.name}</p>
<Badge variant={status.variant} className="text-xs">
{status.label}
</Badge>
</div>
<div className="flex items-center gap-2 text-xs text-muted-foreground">
<span className="font-mono">{key.key_prefix}...</span>
<span>
Created {new Date(key.createdAt).toLocaleDateString()}
</span>
<span>
Expires{" "}
{key.expiresAt
? new Date(key.expiresAt).toLocaleDateString()
: "Never"}
</span>
<span>
Last used{" "}
{key.lastUsedAt
? new Date(key.lastUsedAt).toLocaleDateString()
: "Never"}
</span>
</div>
</div>
</div>
{isActive && (
<Button
variant="ghost"
size="sm"
disabled={revoking === key.id}
onClick={() => handleRevoke(key.id)}
>
{revoking === key.id ? "Revoking..." : "Revoke"}
</Button>
)}
</div>
);
})
)}
</div>
</CardContent>
</Card>
{/* Create key dialog */}
<Dialog open={showCreateDialog} onOpenChange={setShowCreateDialog}>
<DialogContent>
<DialogHeader>
<DialogTitle>Create API Key</DialogTitle>
<DialogDescription>
Create a new API key for MCP server authentication.
</DialogDescription>
</DialogHeader>
<form onSubmit={handleCreate} className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
<Label htmlFor="key-name">Name</Label>
<Input
id="key-name"
value={newKeyName}
onChange={(e) => setNewKeyName(e.target.value)}
placeholder="e.g. My MCP Client"
required
/>
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="key-expiry">Expiration (optional)</Label>
<Input
id="key-expiry"
type="date"
value={newKeyExpiry}
onChange={(e) => setNewKeyExpiry(e.target.value)}
min={new Date().toISOString().split("T")[0]}
/>
</div>
<DialogFooter>
<Button type="submit" disabled={creating || !newKeyName.trim()}>
{creating ? "Creating..." : "Create"}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
{/* One-time key display dialog */}
<Dialog open={!!createdKey} onOpenChange={(open) => { if (!open) setCreatedKey(null); }}>
<DialogContent>
<DialogHeader>
<DialogTitle>API Key Created</DialogTitle>
<DialogDescription>
Copy this key now — it won't be shown again.
</DialogDescription>
</DialogHeader>
<div className="flex items-center gap-2">
<Input
value={createdKey || ""}
readOnly
className="font-mono text-sm"
/>
<Button variant="outline" size="icon" onClick={handleCopy}>
{copied ? <CheckIcon className="size-4" /> : <CopyIcon className="size-4" />}
</Button>
</div>
<DialogFooter showCloseButton />
</DialogContent>
</Dialog>
</>
);
}
export function Profile() {
const { data: session } = useSession();
const isAdmin = (session?.user as any)?.role === "admin";
return (
<div className="space-y-6">
<div>
<h2 className="text-2xl font-bold">Account Settings</h2>
<p className="text-muted-foreground">
Manage your profile, security, linked accounts, and sessions
</p>
</div>
<Tabs defaultValue="profile">
<TabsList>
<TabsTrigger value="profile">Profile</TabsTrigger>
<TabsTrigger value="security">Security</TabsTrigger>
<TabsTrigger value="accounts">Linked Accounts</TabsTrigger>
<TabsTrigger value="sessions">Sessions</TabsTrigger>
{isAdmin && <TabsTrigger value="api-keys">API Keys</TabsTrigger>}
</TabsList>
<TabsContent value="profile" className="mt-4">
<ProfileTab />
</TabsContent>
<TabsContent value="security" className="mt-4">
<SecurityTab />
</TabsContent>
<TabsContent value="accounts" className="mt-4">
<LinkedAccountsTab />
</TabsContent>
<TabsContent value="sessions" className="mt-4">
<SessionsTab />
</TabsContent>
{isAdmin && (
<TabsContent value="api-keys" className="mt-4">
<ApiKeysTab />
</TabsContent>
)}
</Tabs>
</div>
);
}