From 849490f5b2b767515d341b3c2e9b2af9a99313bd Mon Sep 17 00:00:00 2001 From: syui Date: Tue, 17 Jun 2025 13:45:40 +0900 Subject: [PATCH] fix oauth --- oauth/src/services/atproto-oauth.ts | 54 ++++------------------------- 1 file changed, 6 insertions(+), 48 deletions(-) diff --git a/oauth/src/services/atproto-oauth.ts b/oauth/src/services/atproto-oauth.ts index 847fd12..9667761 100644 --- a/oauth/src/services/atproto-oauth.ts +++ b/oauth/src/services/atproto-oauth.ts @@ -95,46 +95,18 @@ class AtprotoOAuthService { } private async processSession(session: any): Promise<{ did: string; handle: string }> { - console.log('[OAuth Debug] Processing session object:', session); - - // Log session structure - console.log('[OAuth Debug] Session keys:', Object.keys(session)); - console.log('[OAuth Debug] Session.sub:', session.sub); - console.log('[OAuth Debug] Session.did:', session.did); - console.log('[OAuth Debug] Session.handle:', session.handle); - - // Check if agent has properties we can access - if (session.agent) { - console.log('[OAuth Debug] Session has agent property'); - } - const did = session.sub || session.did; let handle = session.handle || 'unknown'; - console.log('[OAuth Debug] Extracted DID:', did); - console.log('[OAuth Debug] Extracted handle:', handle); - // Create Agent directly with session (per official docs) try { this.agent = new Agent(session); - console.log('[OAuth Debug] Agent created successfully with session'); - - // Check if agent has session info after creation - if (this.agent.session) { - console.log('[OAuth Debug] Agent has session:', this.agent.session); - } } catch (err) { - console.log('[OAuth Debug] Failed to create agent with session:', err); // Fallback to dpopFetch method - try { - this.agent = new Agent({ - service: session.server?.serviceEndpoint || 'https://bsky.social', - fetch: session.dpopFetch - }); - console.log('[OAuth Debug] Agent created with dpopFetch fallback'); - } catch (fallbackErr) { - console.error('[OAuth Debug] Failed to create agent with fallback:', fallbackErr); - } + this.agent = new Agent({ + service: session.server?.serviceEndpoint || 'https://bsky.social', + fetch: session.dpopFetch + }); } // Store basic session info @@ -374,37 +346,23 @@ class AtprotoOAuthService { } } - async checkSession(forceReset: boolean = false): Promise<{ did: string; handle: string } | null> { + async checkSession(): Promise<{ did: string; handle: string } | null> { try { - console.log('[OAuth Debug] Checking session... (forceReset:', forceReset, ')'); - - if (forceReset) { - console.log('[OAuth Debug] Force reset requested - clearing all sessions'); - await this.logout(); - } - if (!this.oauthClient) { - console.log('[OAuth Debug] No OAuth client, initializing...'); await this.initialize(); } if (!this.oauthClient) { - console.log('[OAuth Debug] Failed to initialize OAuth client'); return null; } const result = await this.oauthClient.init(); - console.log('[OAuth Debug] OAuth init result:', !!result?.session); if (result?.session) { - console.log('[OAuth Debug] Session found, processing...'); // Use the common session processing method - const sessionData = await this.processSession(result.session); - console.log('[OAuth Debug] Processed session data:', sessionData); - return sessionData; + return this.processSession(result.session); } - console.log('[OAuth Debug] No session found'); return null; } catch (error) {