forked from
haetae.tngl.sh/fanfic-atproto
personal fork for experimenting
1import type { APIContext } from "astro";
2import { AtpBaseClient } from "@atproto/api";
3import { DidResolver } from "@atproto/identity";
4
5export async function getAgent(locals: APIContext["locals"]) {
6 const loggedInUser = locals.loggedInUser;
7 try {
8 const agent = new AtpBaseClient(loggedInUser?.fetchHandler!);
9 return agent;
10 } catch (error) {
11 // we don't need to return anything to make sure the site still functions for not logged in users?
12 console.error(error);
13 return;
14 }
15}
16
17const RESOLVER = new DidResolver({});
18export async function didToHandle(did: string) {
19 try {
20 const atProtoData = await RESOLVER.resolveAtprotoData(did);
21 return atProtoData.handle;
22 } catch (error) {
23 // console.error(error);
24 return "Invalid handle";
25 }
26}