Files
zitadel/apps/login/app/(login)/accounts/page.tsx

46 lines
1.5 KiB
TypeScript
Raw Normal View History

2023-06-06 17:11:49 +02:00
import { Session } from "@zitadel/server";
2023-05-17 15:25:25 +02:00
import { listSessions, server } from "#/lib/zitadel";
import { getAllSessionIds } from "#/utils/cookies";
2023-06-06 17:11:49 +02:00
import { UserPlusIcon } from "@heroicons/react/24/outline";
2023-05-17 15:25:25 +02:00
import Link from "next/link";
import SessionsList from "#/ui/SessionsList";
2023-05-17 15:25:25 +02:00
2023-05-24 16:27:35 +02:00
async function loadSessions(): Promise<Session[]> {
2023-05-23 09:22:15 +02:00
const ids = await getAllSessionIds();
2023-05-17 15:25:25 +02:00
if (ids && ids.length) {
2023-05-24 16:27:35 +02:00
const response = await listSessions(
2023-05-17 15:25:25 +02:00
server,
ids.filter((id: string | undefined) => !!id)
2023-05-23 09:22:15 +02:00
);
2023-05-24 16:27:35 +02:00
return response?.sessions ?? [];
2023-05-17 15:25:25 +02:00
} else {
2023-05-25 08:40:53 +02:00
console.info("No session cookie found.");
2023-05-17 15:25:25 +02:00
return [];
}
}
export default async function Page() {
2023-06-06 17:11:49 +02:00
let sessions = await loadSessions();
2023-06-19 16:28:29 +02:00
console.log(sessions);
2023-05-17 15:25:25 +02:00
return (
<div className="flex flex-col items-center space-y-4">
<h1>Accounts</h1>
<p className="ztdl-p mb-6 block">Use your ZITADEL Account</p>
2023-05-23 09:31:56 +02:00
<div className="flex flex-col w-full space-y-2">
<SessionsList sessions={sessions} />
2023-05-23 09:22:15 +02:00
<Link href="/username">
2023-05-23 09:31:56 +02:00
<div className="flex flex-row items-center py-3 px-4 hover:bg-black/10 dark:hover:bg-white/10 rounded-md transition-all">
2023-05-23 09:22:15 +02:00
<div className="w-8 h-8 mr-4 flex flex-row justify-center items-center rounded-full bg-black/5 dark:bg-white/5">
<UserPlusIcon className="h-5 w-5" />
</div>
<span className="text-sm">Add another account</span>
</div>
</Link>
2023-05-17 15:25:25 +02:00
</div>
</div>
);
}