Graphical PDS migrator for AT Protocol
1import { destroyAllSessions, getSession } from "../../lib/sessions.ts";
2import { oauthClient } from "../../lib/oauth/client.ts";
3import { define } from "../../utils.ts";
4
5export const handler = define.handlers({
6 async POST(ctx) {
7 const req = ctx.req;
8
9 try {
10 const response = new Response(null, { status: 200 });
11 const session = await getSession(req, response);
12
13 if (session.did) {
14 // Try to revoke both types of sessions - the one that doesn't exist will just no-op
15 await Promise.all([
16 oauthClient.revoke(session.did).catch(console.error),
17 ]);
18 // Then destroy the iron session
19 session.destroy();
20 }
21
22 // Destroy all sessions including migration session
23 const result = await destroyAllSessions(req, response);
24
25 return result;
26 } catch (error: unknown) {
27 const err = error instanceof Error ? error : new Error(String(error));
28 console.error("Logout failed:", err.message);
29 return new Response("Logout failed", { status: 500 });
30 }
31 },
32});