@@ -3,16 +3,17 @@ import { resolveActor } from "./identity";
33import { isActorIdentifier } from "@atcute/lexicons/syntax" ;
44import { ResolvedActor } from "@atcute/identity-resolver" ;
55import { OAuthHandler , } from "./oauth/oauth" ;
6- import { OAuthUserAgent , Session } from "@atcute/oauth-browser-client" ;
6+ import { OAuthUserAgent } from "@atcute/oauth-browser-client" ;
77
88export 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 */
5357export 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 ) ;
0 commit comments