fix oauth
This commit is contained in:
@@ -1215,6 +1215,13 @@ function App() {
|
||||
const contentText = isNewFormat ? value.text : (value.content || value.body || '');
|
||||
// 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 || '';
|
||||
@@ -1313,27 +1320,51 @@ function App() {
|
||||
<section className="comment-section">
|
||||
{/* Authentication Section */}
|
||||
{!user ? (
|
||||
<div className="auth-section search-bar-layout">
|
||||
<input
|
||||
type="text"
|
||||
id="handle-input"
|
||||
name="handle"
|
||||
placeholder="user.bsky.social"
|
||||
className="handle-input"
|
||||
value={handleInput}
|
||||
onChange={(e) => setHandleInput(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
executeOAuth();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<div className="auth-section">
|
||||
<div className="search-bar-layout">
|
||||
<input
|
||||
type="text"
|
||||
id="handle-input"
|
||||
name="handle"
|
||||
placeholder="user.bsky.social"
|
||||
className="handle-input"
|
||||
value={handleInput}
|
||||
onChange={(e) => setHandleInput(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
executeOAuth();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
onClick={executeOAuth}
|
||||
className="atproto-button"
|
||||
>
|
||||
<i class="fab fa-bluesky"></i>
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
onClick={executeOAuth}
|
||||
className="atproto-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'
|
||||
}}
|
||||
>
|
||||
<i class="fab fa-bluesky"></i>
|
||||
Clear All Sessions
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
|
@@ -95,26 +95,25 @@ class AtprotoOAuthService {
|
||||
}
|
||||
|
||||
private async processSession(session: any): Promise<{ did: string; handle: string }> {
|
||||
console.log('[OAuth Debug] Processing session object:', session);
|
||||
|
||||
|
||||
// Log full session structure
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 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);
|
||||
@@ -254,10 +253,10 @@ 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();
|
||||
}
|
||||
|
||||
@@ -273,33 +272,32 @@ 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);
|
||||
|
||||
// Always re-initialize OAuth client with detected PDS
|
||||
console.log('[OAuth Debug] Re-initializing OAuth client');
|
||||
// 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');
|
||||
|
||||
// Clear existing client to force fresh initialization
|
||||
this.oauthClient = null;
|
||||
this.initializePromise = null;
|
||||
// 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);
|
||||
|
||||
// Determine PLC directory based on input handle, not environment PDS
|
||||
let plcDirectoryUrl = 'https://plc.directory'; // Default to Bluesky PLC
|
||||
if (handle.endsWith('.syu.is') || handle.endsWith('.syui.ai')) {
|
||||
plcDirectoryUrl = 'https://plc.syu.is';
|
||||
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');
|
||||
}
|
||||
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 successfully');
|
||||
|
||||
// OAuth client initialized
|
||||
|
||||
@@ -376,9 +374,14 @@ class AtprotoOAuthService {
|
||||
}
|
||||
}
|
||||
|
||||
async checkSession(): Promise<{ did: string; handle: string } | null> {
|
||||
async checkSession(forceReset: boolean = false): Promise<{ did: string; handle: string } | null> {
|
||||
try {
|
||||
console.log('[OAuth Debug] Checking session...');
|
||||
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...');
|
||||
@@ -460,28 +463,27 @@ 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);
|
||||
}
|
||||
|
||||
// Reset the OAuth client to force re-initialization
|
||||
@@ -491,6 +493,21 @@ class AtprotoOAuthService {
|
||||
|
||||
// Clear any stored session data
|
||||
localStorage.removeItem('atproto_session');
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
Reference in New Issue
Block a user