Skip to content

Commit 117f2d4

Browse files
committed
cleanup
1 parent 77bb941 commit 117f2d4

3 files changed

Lines changed: 13 additions & 31 deletions

File tree

src/lib/client.ts

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ import { resolveActor } from "./identity";
33
import { isActorIdentifier } from "@atcute/lexicons/syntax";
44
import { ResolvedActor } from "@atcute/identity-resolver";
55
import { OAuthHandler, } from "./oauth/oauth";
6-
import { OAuthUserAgent, Session } from "@atcute/oauth-browser-client";
6+
import { OAuthUserAgent } from "@atcute/oauth-browser-client";
77

88
export class ATClient extends Client {
99
private hh: Handler;
10+
private oauth: OAuthHandler;
1011
actor?: ResolvedActor;
1112

1213
constructor() {
13-
const oauth = new OAuthHandler();
14-
const hh = new Handler(oauth);
14+
const hh = new Handler();
1515
super({ handler: hh });
16+
this.oauth = new OAuthHandler();
1617
this.hh = hh;
1718
}
1819

@@ -21,20 +22,23 @@ export class ATClient extends Client {
2122
}
2223

2324
async login(identifier: string): Promise<void> {
24-
await this.hh.login(identifier);
25+
const session = await this.oauth.authorize(identifier);
26+
this.hh.agent = new OAuthUserAgent(session);
2527
const did = this.hh.agent?.session.info.sub;
2628
if (did) {
2729
this.actor = await this.hh.getActor(did);
2830
}
2931
}
3032

3133
async restoreSession(did: string): Promise<void> {
32-
await this.hh.restoreSession(did);
34+
const session = await this.oauth.restore(did);
35+
this.hh.agent = new OAuthUserAgent(session);
3336
this.actor = await this.hh.getActor(did);
3437
}
3538

3639
async logout(identifier: string): Promise<void> {
37-
await this.hh.logout(identifier);
40+
await this.oauth.revoke(identifier);
41+
this.hh.agent = undefined;
3842
this.actor = undefined;
3943
}
4044

@@ -43,7 +47,7 @@ export class ATClient extends Client {
4347
}
4448

4549
handleOAuthCallback(params: URLSearchParams): void {
46-
this.hh.handleOAuthCallback(params);
50+
this.oauth.handleCallback(params);
4751
}
4852
}
4953

@@ -52,33 +56,12 @@ export class ATClient extends Client {
5256
*/
5357
export class Handler implements FetchHandlerObject {
5458
cache: Cache;
55-
oauth: OAuthHandler;
5659
agent?: OAuthUserAgent;
5760

58-
constructor(oauth: OAuthHandler) {
59-
this.oauth = oauth;
61+
constructor() {
6062
this.cache = new Cache(5 * 60 * 1000); // 5 minutes TTL
6163
}
6264

63-
async login(identifier: string): Promise<void> {
64-
const session = await this.oauth.authorize(identifier);
65-
this.agent = new OAuthUserAgent(session);
66-
}
67-
68-
async restoreSession(did: string): Promise<void> {
69-
const session = await this.oauth.restore(did);
70-
this.agent = new OAuthUserAgent(session);
71-
}
72-
73-
async logout(identifier: string): Promise<void> {
74-
await this.oauth.revoke(identifier);
75-
this.agent = undefined;
76-
}
77-
78-
handleOAuthCallback(params: URLSearchParams): void {
79-
this.oauth.handleCallback(params);
80-
}
81-
8265
async getActor(identifier: string): Promise<ResolvedActor> {
8366
const key = `actor:${identifier}`;
8467
const cached = this.cache.get<ResolvedActor>(key);

src/lib/oauth/oauth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class OAuthHandler {
4545
target: { type: 'account', identifier: identifier as ActorIdentifier },
4646
scope: metadata.scope,
4747
});
48-
await sleep(200);
48+
await new Promise((resolve) => setTimeout(resolve, 200));
4949

5050
// Create promise for callback
5151
const waitForCallback = new Promise<URLSearchParams>((resolve, reject) => {

src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export default class AtmospherePlugin extends Plugin {
8181
this.addSettingTab(new SettingTab(this.app, this));
8282
}
8383

84-
8584
async checkAuth() {
8685
if (this.client.loggedIn) {
8786
return true;

0 commit comments

Comments
 (0)