fix oauth

This commit is contained in:
2025-06-17 13:45:40 +09:00
parent c1d3678d96
commit 849490f5b2

View File

@@ -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);
}
}
// 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) {