forked from
rocksky.app/rocksky
A decentralized music tracking and discovery platform built on AT Protocol 馃幍
1import { Agent } from "@atproto/api";
2import type { NodeOAuthClient } from "@atproto/oauth-client-node";
3
4export async function createAgent(
5 oauthClient: NodeOAuthClient,
6 did: string,
7): Promise<Agent | null> {
8 let agent = null;
9 let retry = 0;
10 do {
11 try {
12 const oauthSession = await oauthClient.restore(did);
13 agent = oauthSession ? new Agent(oauthSession) : null;
14 if (agent === null) {
15 await new Promise((r) => setTimeout(r, 1000));
16 retry += 1;
17 }
18 } catch (e) {
19 console.log("Error creating agent");
20 console.log(did);
21 console.log(e);
22 await new Promise((r) => setTimeout(r, 1000));
23 retry += 1;
24 }
25 } while (agent === null && retry < 5);
26
27 return agent;
28}