fix oauth
This commit is contained in:
@@ -95,46 +95,18 @@ class AtprotoOAuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async processSession(session: any): Promise<{ did: string; handle: string }> {
|
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;
|
const did = session.sub || session.did;
|
||||||
let handle = session.handle || 'unknown';
|
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)
|
// Create Agent directly with session (per official docs)
|
||||||
try {
|
try {
|
||||||
this.agent = new Agent(session);
|
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) {
|
} catch (err) {
|
||||||
console.log('[OAuth Debug] Failed to create agent with session:', err);
|
|
||||||
// Fallback to dpopFetch method
|
// Fallback to dpopFetch method
|
||||||
try {
|
this.agent = new Agent({
|
||||||
this.agent = new Agent({
|
service: session.server?.serviceEndpoint || 'https://bsky.social',
|
||||||
service: session.server?.serviceEndpoint || 'https://bsky.social',
|
fetch: session.dpopFetch
|
||||||
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
|
// 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 {
|
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) {
|
if (!this.oauthClient) {
|
||||||
console.log('[OAuth Debug] No OAuth client, initializing...');
|
|
||||||
await this.initialize();
|
await this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.oauthClient) {
|
if (!this.oauthClient) {
|
||||||
console.log('[OAuth Debug] Failed to initialize OAuth client');
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await this.oauthClient.init();
|
const result = await this.oauthClient.init();
|
||||||
console.log('[OAuth Debug] OAuth init result:', !!result?.session);
|
|
||||||
|
|
||||||
if (result?.session) {
|
if (result?.session) {
|
||||||
console.log('[OAuth Debug] Session found, processing...');
|
|
||||||
// Use the common session processing method
|
// Use the common session processing method
|
||||||
const sessionData = await this.processSession(result.session);
|
return this.processSession(result.session);
|
||||||
console.log('[OAuth Debug] Processed session data:', sessionData);
|
|
||||||
return sessionData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[OAuth Debug] No session found');
|
|
||||||
return null;
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user