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