From 549f728b7acc7309bd92e912c65b69035a388749 Mon Sep 17 00:00:00 2001 From: syui Date: Tue, 17 Jun 2025 13:58:00 +0900 Subject: [PATCH] fix oauth --- oauth/src/App.tsx | 68 ++++++++--------------------- oauth/src/services/atproto-oauth.ts | 60 ++----------------------- 2 files changed, 23 insertions(+), 105 deletions(-) diff --git a/oauth/src/App.tsx b/oauth/src/App.tsx index 2d42939..af031f5 100644 --- a/oauth/src/App.tsx +++ b/oauth/src/App.tsx @@ -1216,12 +1216,6 @@ function App() { // Use the author from the record if available, otherwise fall back to AI profile const authorInfo = value.author || aiProfile; - // Debug log for author information - if (value.author) { - console.log('[Debug] Using record author:', value.author); - } else { - console.log('[Debug] Using AI profile fallback:', aiProfile); - } const postInfo = isNewFormat ? value.post : null; const contentType = value.type || 'unknown'; const createdAt = value.createdAt || value.generated_at || ''; @@ -1320,51 +1314,27 @@ function App() {
{/* Authentication Section */} {!user ? ( -
-
- setHandleInput(e.target.value)} - onKeyDown={(e) => { - if (e.key === 'Enter') { - e.preventDefault(); - executeOAuth(); - } - }} - /> - -
+
+ setHandleInput(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter') { + e.preventDefault(); + executeOAuth(); + } + }} + />
) : ( diff --git a/oauth/src/services/atproto-oauth.ts b/oauth/src/services/atproto-oauth.ts index 9667761..44cadd4 100644 --- a/oauth/src/services/atproto-oauth.ts +++ b/oauth/src/services/atproto-oauth.ts @@ -38,13 +38,11 @@ class AtprotoOAuthService { // Support multiple PDS hosts for OAuth - console.log('[OAuth Debug] Initializing OAuth client with default settings'); this.oauthClient = await BrowserOAuthClient.load({ clientId: clientId, handleResolver: 'https://bsky.social', // Default resolver plcDirectoryUrl: 'https://plc.directory', // Default PLC directory }); - console.log('[OAuth Debug] OAuth client initialized with defaults'); @@ -206,7 +204,6 @@ class AtprotoOAuthService { if (response.ok) { const data = await response.json(); if (data.did) { - console.log('[OAuth Debug] Resolved handle via', endpoint, '- using that PDS'); return endpoint; } } @@ -215,7 +212,7 @@ class AtprotoOAuthService { } } } catch (e) { - console.log('[OAuth Debug] Handle resolution failed, using default'); + // Handle resolution failed, using default } // Default to bsky.social @@ -225,10 +222,7 @@ class AtprotoOAuthService { async initiateOAuthFlow(handle?: string): Promise { try { - console.log('[OAuth Debug] Starting OAuth flow...'); - if (!this.oauthClient) { - console.log('[OAuth Debug] No OAuth client, initializing...'); await this.initialize(); } @@ -244,32 +238,10 @@ class AtprotoOAuthService { } } - console.log('[OAuth Debug] Input handle:', handle); - - - // Detect PDS based on handle const pdsUrl = await this.detectPDSFromHandle(handle); - console.log('[OAuth Debug] Detected PDS for handle', handle, ':', pdsUrl); - // Re-initialize OAuth client with correct PDS if needed - if (pdsUrl !== 'https://bsky.social') { - console.log('[OAuth Debug] Re-initializing OAuth client for non-Bluesky PDS'); - - // Determine PLC directory for syu.is only - const plcDirectoryUrl = handle.endsWith('.syu.is') || handle.endsWith('.syui.ai') ? 'https://plc.syu.is' : 'https://plc.directory'; - console.log('[OAuth Debug] Using PLC directory:', plcDirectoryUrl); - - this.oauthClient = await BrowserOAuthClient.load({ - clientId: this.getClientId(), - handleResolver: pdsUrl, - plcDirectoryUrl: plcDirectoryUrl, - }); - - console.log('[OAuth Debug] OAuth client re-initialized for', pdsUrl); - } else { - console.log('[OAuth Debug] Using default OAuth client for Bluesky'); - } + // For all handles, use the default OAuth client (no re-initialization) // OAuth client initialized @@ -421,27 +393,20 @@ class AtprotoOAuthService { async logout(): Promise { try { - console.log('[OAuth Debug] Starting logout process...'); - // Clear Agent this.agent = null; // Clear BrowserOAuthClient session if (this.oauthClient) { - console.log('[OAuth Debug] Clearing OAuth client session...'); try { // BrowserOAuthClient may have a revoke or signOut method if (typeof (this.oauthClient as any).signOut === 'function') { await (this.oauthClient as any).signOut(); - console.log('[OAuth Debug] OAuth client signOut completed'); } else if (typeof (this.oauthClient as any).revoke === 'function') { await (this.oauthClient as any).revoke(); - console.log('[OAuth Debug] OAuth client revoke completed'); - } else { - console.log('[OAuth Debug] No signOut/revoke method available'); } } catch (oauthError) { - console.log('[OAuth Debug] OAuth logout error:', oauthError); + // Ignore logout errors } // Reset the OAuth client to force re-initialization @@ -451,13 +416,12 @@ class AtprotoOAuthService { // Clear any stored session data localStorage.removeItem('atproto_session'); + sessionStorage.clear(); // Clear all OAuth-related storage - console.log('[OAuth Debug] Clearing all OAuth storage...'); for (let i = 0; i < localStorage.length; i++) { const key = localStorage.key(i); if (key && (key.includes('oauth') || key.includes('atproto') || key.includes('session'))) { - console.log('[OAuth Debug] Removing localStorage key:', key); localStorage.removeItem(key); } } @@ -465,22 +429,6 @@ class AtprotoOAuthService { // Clear internal session info (this as any)._sessionInfo = null; - console.log('[OAuth Debug] Logout completed'); - sessionStorage.clear(); - - // Clear all localStorage items that might be related to OAuth - const keysToRemove: string[] = []; - for (let i = 0; i < localStorage.length; i++) { - const key = localStorage.key(i); - if (key && (key.includes('oauth') || key.includes('atproto') || key.includes('session'))) { - keysToRemove.push(key); - } - } - keysToRemove.forEach(key => { - - localStorage.removeItem(key); - }); - // Force page reload to ensure clean state