-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathauth.ts
More file actions
45 lines (35 loc) · 912 Bytes
/
auth.ts
File metadata and controls
45 lines (35 loc) · 912 Bytes
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
36
37
38
39
40
41
42
43
44
45
import {
type AtpSessionData,
CredentialManager,
type CredentialManagerOptions,
} from '@atcute/client';
export class Auth {
manager: CredentialManager;
sessions: Map<string, AtpSessionData> = new Map();
constructor(options?: CredentialManagerOptions) {
this.manager = new CredentialManager(
options ?? { service: 'https://bsky.social' },
);
}
async login(identifier: string, password: string) {
const session = await this.manager.login({
identifier,
password,
});
this.sessions.set(session.did, session);
return session;
}
async switch(did: string) {
const session = this.sessions.get(did);
if (!session) {
throw new Error('Session not found');
}
return await this.manager.resume(session);
}
logout(did: string) {
this.sessions.delete(did);
}
get currentSession() {
return this.manager.session;
}
}