forked from kawarimidoll/bluestream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.ts
35 lines (27 loc) · 760 Bytes
/
login.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { BLUESKY_SERVICE, IS_DEV } from "./constants.ts";
import { load } from "std/dotenv/mod.ts";
if (IS_DEV) {
await load({
defaultsPath: null,
examplePath: null,
export: true,
allowEmptyValues: true,
});
}
import AtoprotoAPI from "@atproto/api";
const { BskyAgent } = AtoprotoAPI;
const bskyAgent = () => {
return new BskyAgent({ service: BLUESKY_SERVICE });
};
export type AgentType = ReturnType<typeof bskyAgent>;
// singleton agent
const agent = bskyAgent();
export async function login() {
if (agent.session) {
return agent;
}
const identifier = Deno.env.get("BLUESKY_IDENTIFIER") || "";
const password = Deno.env.get("BLUESKY_PASSWORD") || "";
await agent.login({ identifier, password });
return agent;
}