diff --git a/components/console/account-page-client.tsx b/components/console/account-page-client.tsx index c7f342c..b7d30fb 100644 --- a/components/console/account-page-client.tsx +++ b/components/console/account-page-client.tsx @@ -49,6 +49,12 @@ export function AccountPageClient({ user, hasGithubConnection }: { user: UserPro const [deleting, setDeleting] = useState(false); const [deleteError, setDeleteError] = useState(null); + // Dynamic Session Management State (Fixes #44) + const [sessions, setSessions] = useState([ + { id: "chrome-macos", device: "Chrome on macOS", loc: "Bengaluru, IN", current: true }, + { id: "vscode-ext", device: "VS Code Extension", loc: "Bengaluru, IN", current: false }, + ]); + const saveProfile = () => { setProfileSaved(true); setTimeout(() => setProfileSaved(false), 2000); @@ -59,6 +65,27 @@ export function AccountPageClient({ user, hasGithubConnection }: { user: UserPro setTimeout(() => setPwSaved(false), 2000); }; + const handleRevokeSession = async (id: string, device: string) => { + if (!window.confirm(`Are you sure you want to terminate your active session on "${device}"?`)) { + return; + } + + try { + const res = await fetch(`/api/user/sessions?id=${encodeURIComponent(id)}`, { + method: "DELETE", + }); + + const data = await res.json(); + if (res.ok && data.ok) { + setSessions((prev) => prev.filter((s) => s.id !== id)); + } else { + alert(data.error ?? "Failed to revoke active session."); + } + } catch { + alert("Network error occurred while trying to terminate connection session."); + } + }; + const handleDeleteAccount = async () => { if (deleteInput !== "delete my account") return; @@ -79,7 +106,6 @@ export function AccountPageClient({ user, hasGithubConnection }: { user: UserPro if (res.ok && data.ok) { alert("Your account has been successfully deleted. Goodbye!"); - // Safely wipe out NextAuth browser session states and redirect to registration index page signOut({ callbackUrl: "/" }); } else { setDeleteError(data.error ?? "Failed to delete account. Please try again."); @@ -238,11 +264,8 @@ export function AccountPageClient({ user, hasGithubConnection }: { user: UserPro
}>
- {[ - { device: "Chrome on macOS", loc: "Bengaluru, IN", current: true }, - { device: "VS Code Extension", loc: "Bengaluru, IN", current: false }, - ].map((s) => ( -
+ {sessions.map((s) => ( +

{s.device}

{s.loc}

@@ -252,7 +275,12 @@ export function AccountPageClient({ user, hasGithubConnection }: { user: UserPro Current ) : ( - + )}
))} @@ -270,7 +298,6 @@ export function AccountPageClient({ user, hasGithubConnection }: { user: UserPro setDeleteInput(e.target.value)} placeholder='delete my account' className="w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-900 transition-colors focus:border-red-400 focus:outline-none dark:border-zinc-700 dark:bg-zinc-800 dark:text-white" @@ -290,4 +317,4 @@ export function AccountPageClient({ user, hasGithubConnection }: { user: UserPro
); -} \ No newline at end of file +}