fix oauth
This commit is contained in:
@@ -1216,12 +1216,6 @@ function App() {
|
|||||||
// Use the author from the record if available, otherwise fall back to AI profile
|
// Use the author from the record if available, otherwise fall back to AI profile
|
||||||
const authorInfo = value.author || aiProfile;
|
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 postInfo = isNewFormat ? value.post : null;
|
||||||
const contentType = value.type || 'unknown';
|
const contentType = value.type || 'unknown';
|
||||||
const createdAt = value.createdAt || value.generated_at || '';
|
const createdAt = value.createdAt || value.generated_at || '';
|
||||||
@@ -1320,51 +1314,27 @@ function App() {
|
|||||||
<section className="comment-section">
|
<section className="comment-section">
|
||||||
{/* Authentication Section */}
|
{/* Authentication Section */}
|
||||||
{!user ? (
|
{!user ? (
|
||||||
<div className="auth-section">
|
<div className="auth-section search-bar-layout">
|
||||||
<div className="search-bar-layout">
|
<input
|
||||||
<input
|
type="text"
|
||||||
type="text"
|
id="handle-input"
|
||||||
id="handle-input"
|
name="handle"
|
||||||
name="handle"
|
placeholder="user.bsky.social"
|
||||||
placeholder="user.bsky.social"
|
className="handle-input"
|
||||||
className="handle-input"
|
value={handleInput}
|
||||||
value={handleInput}
|
onChange={(e) => setHandleInput(e.target.value)}
|
||||||
onChange={(e) => setHandleInput(e.target.value)}
|
onKeyDown={(e) => {
|
||||||
onKeyDown={(e) => {
|
if (e.key === 'Enter') {
|
||||||
if (e.key === 'Enter') {
|
e.preventDefault();
|
||||||
e.preventDefault();
|
executeOAuth();
|
||||||
executeOAuth();
|
}
|
||||||
}
|
}}
|
||||||
}}
|
/>
|
||||||
/>
|
|
||||||
<button
|
|
||||||
onClick={executeOAuth}
|
|
||||||
className="atproto-button"
|
|
||||||
>
|
|
||||||
<i class="fab fa-bluesky"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<button
|
<button
|
||||||
onClick={async () => {
|
onClick={executeOAuth}
|
||||||
console.log('Force clearing all OAuth sessions...');
|
className="atproto-button"
|
||||||
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
|
<i class="fab fa-bluesky"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
@@ -38,13 +38,11 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
|
|
||||||
// Support multiple PDS hosts for OAuth
|
// Support multiple PDS hosts for OAuth
|
||||||
console.log('[OAuth Debug] Initializing OAuth client with default settings');
|
|
||||||
this.oauthClient = await BrowserOAuthClient.load({
|
this.oauthClient = await BrowserOAuthClient.load({
|
||||||
clientId: clientId,
|
clientId: clientId,
|
||||||
handleResolver: 'https://bsky.social', // Default resolver
|
handleResolver: 'https://bsky.social', // Default resolver
|
||||||
plcDirectoryUrl: 'https://plc.directory', // Default PLC directory
|
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) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data.did) {
|
if (data.did) {
|
||||||
console.log('[OAuth Debug] Resolved handle via', endpoint, '- using that PDS');
|
|
||||||
return endpoint;
|
return endpoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,7 +212,7 @@ class AtprotoOAuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('[OAuth Debug] Handle resolution failed, using default');
|
// Handle resolution failed, using default
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to bsky.social
|
// Default to bsky.social
|
||||||
@@ -225,10 +222,7 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
async initiateOAuthFlow(handle?: string): Promise<void> {
|
async initiateOAuthFlow(handle?: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
console.log('[OAuth Debug] Starting OAuth flow...');
|
|
||||||
|
|
||||||
if (!this.oauthClient) {
|
if (!this.oauthClient) {
|
||||||
console.log('[OAuth Debug] No OAuth client, initializing...');
|
|
||||||
await this.initialize();
|
await this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,32 +238,10 @@ class AtprotoOAuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[OAuth Debug] Input handle:', handle);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Detect PDS based on handle
|
// Detect PDS based on handle
|
||||||
const pdsUrl = await this.detectPDSFromHandle(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
|
// For all handles, use the default OAuth client (no re-initialization)
|
||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
// OAuth client initialized
|
// OAuth client initialized
|
||||||
|
|
||||||
@@ -421,27 +393,20 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
async logout(): Promise<void> {
|
async logout(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
console.log('[OAuth Debug] Starting logout process...');
|
|
||||||
|
|
||||||
// Clear Agent
|
// Clear Agent
|
||||||
this.agent = null;
|
this.agent = null;
|
||||||
|
|
||||||
// Clear BrowserOAuthClient session
|
// Clear BrowserOAuthClient session
|
||||||
if (this.oauthClient) {
|
if (this.oauthClient) {
|
||||||
console.log('[OAuth Debug] Clearing OAuth client session...');
|
|
||||||
try {
|
try {
|
||||||
// BrowserOAuthClient may have a revoke or signOut method
|
// BrowserOAuthClient may have a revoke or signOut method
|
||||||
if (typeof (this.oauthClient as any).signOut === 'function') {
|
if (typeof (this.oauthClient as any).signOut === 'function') {
|
||||||
await (this.oauthClient as any).signOut();
|
await (this.oauthClient as any).signOut();
|
||||||
console.log('[OAuth Debug] OAuth client signOut completed');
|
|
||||||
} else if (typeof (this.oauthClient as any).revoke === 'function') {
|
} else if (typeof (this.oauthClient as any).revoke === 'function') {
|
||||||
await (this.oauthClient as any).revoke();
|
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) {
|
} catch (oauthError) {
|
||||||
console.log('[OAuth Debug] OAuth logout error:', oauthError);
|
// Ignore logout errors
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the OAuth client to force re-initialization
|
// Reset the OAuth client to force re-initialization
|
||||||
@@ -451,13 +416,12 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
// Clear any stored session data
|
// Clear any stored session data
|
||||||
localStorage.removeItem('atproto_session');
|
localStorage.removeItem('atproto_session');
|
||||||
|
sessionStorage.clear();
|
||||||
|
|
||||||
// Clear all OAuth-related storage
|
// Clear all OAuth-related storage
|
||||||
console.log('[OAuth Debug] Clearing all OAuth storage...');
|
|
||||||
for (let i = 0; i < localStorage.length; i++) {
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
const key = localStorage.key(i);
|
const key = localStorage.key(i);
|
||||||
if (key && (key.includes('oauth') || key.includes('atproto') || key.includes('session'))) {
|
if (key && (key.includes('oauth') || key.includes('atproto') || key.includes('session'))) {
|
||||||
console.log('[OAuth Debug] Removing localStorage key:', key);
|
|
||||||
localStorage.removeItem(key);
|
localStorage.removeItem(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -465,22 +429,6 @@ class AtprotoOAuthService {
|
|||||||
// Clear internal session info
|
// Clear internal session info
|
||||||
(this as any)._sessionInfo = null;
|
(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
|
// Force page reload to ensure clean state
|
||||||
|
Reference in New Issue
Block a user