Graphical PDS migrator for AT Protocol
1import { getSessionAgent } from "../../../lib/sessions.ts";
2import { setCredentialSession } from "../../../lib/cred/sessions.ts";
3import { Agent } from "@atproto/api";
4import { define } from "../../../utils.ts";
5
6/**
7 * Handle account creation
8 * First step of the migration process
9 * Body must contain:
10 * - service: The service URL of the new account
11 * - handle: The handle of the new account
12 * - password: The password of the new account
13 * - email: The email of the new account
14 * - invite: The invite code of the new account (optional depending on the PDS)
15 * @param ctx - The context object containing the request and response
16 * @returns A response object with the creation result
17 */
18export const handler = define.handlers({
19 async GET(ctx) {
20 const res = new Response();
21 try {
22 const agent = await getSessionAgent(ctx.req, res);
23
24 if (!agent) return new Response("Unauthorized", { status: 401 });
25
26 // console.log("getting did");
27 // const session = await agent.com.atproto.server.getSession();
28 // const accountDid = session.data.did;
29 // console.log("got did");
30
31 await agent.com.atproto.identity.requestPlcOperationSignature();
32
33 return new Response(
34 JSON.stringify({
35 success: true,
36 message:
37 "We've requested a token to update your identity, it should be sent to your account's email address.",
38 }),
39 {
40 status: 200,
41 headers: {
42 "Content-Type": "application/json",
43 ...Object.fromEntries(res.headers), // Include session cookie headers
44 },
45 },
46 );
47 } catch (error) {
48 console.error("PLC signature request error:", error);
49 return new Response(
50 JSON.stringify({
51 success: false,
52 message: error instanceof Error
53 ? error.message
54 : "Failed to get PLC operation signature (sending confirmation email)",
55 }),
56 {
57 status: 400,
58 headers: { "Content-Type": "application/json" },
59 },
60 );
61 }
62 },
63});