fix oauth

This commit is contained in:
2025-06-17 13:58:00 +09:00
parent 849490f5b2
commit 549f728b7a
2 changed files with 23 additions and 105 deletions

View File

@@ -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,8 +1314,7 @@ function App() {
<section className="comment-section">
{/* Authentication Section */}
{!user ? (
<div className="auth-section">
<div className="search-bar-layout">
<div className="auth-section search-bar-layout">
<input
type="text"
id="handle-input"
@@ -1344,29 +1337,6 @@ function App() {
<i class="fab fa-bluesky"></i>
</button>
</div>
<button
onClick={async () => {
console.log('Force clearing all OAuth sessions...');
await atprotoOAuthService.logout();
localStorage.clear();
sessionStorage.clear();
// Force reset session check
await atprotoOAuthService.checkSession(true);
window.location.reload();
}}
style={{
padding: '5px 10px',
fontSize: '12px',
backgroundColor: '#ff6b6b',
color: 'white',
border: 'none',
borderRadius: '3px',
marginTop: '5px'
}}
>
Clear All Sessions
</button>
</div>
) : (
<div className="user-section">
<div className="user-info">

View File

@@ -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<void> {
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<void> {
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