mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 15:03:52 +00:00
provide /sessions endpoint to return json of the current sessions
This commit is contained in:
24
apps/login/src/app/sessions/route.ts
Normal file
24
apps/login/src/app/sessions/route.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { listSessions, server } from "@/lib/zitadel";
|
||||||
|
import { SessionCookie, getAllSessions } from "@/utils/cookies";
|
||||||
|
import { Session } from "@zitadel/server";
|
||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
|
async function loadSessions(ids: string[]): Promise<Session[]> {
|
||||||
|
const response = await listSessions(
|
||||||
|
server,
|
||||||
|
ids.filter((id: string | undefined) => !!id),
|
||||||
|
);
|
||||||
|
|
||||||
|
return response?.sessions ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GET(request: NextRequest) {
|
||||||
|
const sessionCookies: SessionCookie[] = await getAllSessions();
|
||||||
|
const ids = sessionCookies.map((s) => s.id);
|
||||||
|
let sessions: Session[] = [];
|
||||||
|
if (ids && ids.length) {
|
||||||
|
sessions = await loadSessions(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({ sessions }, { status: 500 });
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user