···73737474 console.log('[TOKEN REFRESH] Refreshing token for PDS:', pdsEndpoint);
75757676- // CRITICAL FIX: For third-party PDS endpoints, use bsky.social for auth
7777- // Third-party PDS hosts don't implement OAuth endpoints themselves
7676+ // CRITICAL FIX: Token refresh endpoint selection based on PDS type
7877 let authServer = pdsEndpoint;
79788080- // Check if this is a third-party PDS (not bsky.social)
8181- if (!pdsEndpoint.includes('bsky.social')) {
8282- console.log('[TOKEN REFRESH] Using bsky.social for OAuth on third-party PDS');
7979+ // For bsky.network PDSes, use bsky.social
8080+ if (pdsEndpoint.includes('bsky.network')) {
8181+ console.log('[TOKEN REFRESH] Using bsky.social for bsky.network PDS');
8382 authServer = 'https://bsky.social';
8383+ } else if (pdsEndpoint.includes('bsky.social')) {
8484+ // Already using bsky.social
8585+ console.log('[TOKEN REFRESH] Using bsky.social directly');
8686+ } else {
8787+ // For third-party PDSes, use their own endpoint for token refresh
8888+ console.log('[TOKEN REFRESH] Using third-party PDS\'s own endpoint for token refresh:', pdsEndpoint);
8989+ // Keep authServer as the original PDS endpoint
8490 }
85918692 // Endpoint for token refresh
···394400395401 try {
396402 // Try to refresh the token with enhanced error handling
397397- // Use bsky.social for token refresh with third-party PDS
403403+ // Follow the same server selection logic as in refreshAccessToken
398404 let refreshAuthServer = pdsEndpoint;
399399- if (!pdsEndpoint.includes('bsky.social')) {
400400- console.log('[AUTH CHECK] Using bsky.social for token refresh with third-party PDS');
405405+406406+ // For bsky.network PDSes, use bsky.social
407407+ if (pdsEndpoint.includes('bsky.network')) {
408408+ console.log('[AUTH CHECK] Will use bsky.social for bsky.network PDS');
401409 refreshAuthServer = 'https://bsky.social';
410410+ } else if (pdsEndpoint.includes('bsky.social')) {
411411+ // Already using bsky.social
412412+ console.log('[AUTH CHECK] Will use bsky.social directly');
413413+ } else {
414414+ // For third-party PDSes, use their own endpoint
415415+ console.log('[AUTH CHECK] Will use third-party PDS\'s own endpoint:', pdsEndpoint);
416416+ // Keep refreshAuthServer as the original PDS endpoint
402417 }
403418404419 const { accessToken: newAccessToken, refreshToken: newRefreshToken, dpopNonce: newNonce } =
···783798 console.log('Authentication error (401), attempting token refresh...');
784799785800 try {
801801+ // CRITICAL FIX: Follow the same server selection logic as in refreshAccessToken
802802+ let refreshAuthServer = pdsEndpoint || 'https://bsky.social';
803803+804804+ // For bsky.network PDSes, use bsky.social
805805+ if (refreshAuthServer.includes('bsky.network')) {
806806+ console.log('[CREATE STATUS] Using bsky.social for token refresh with bsky.network PDS');
807807+ refreshAuthServer = 'https://bsky.social';
808808+ } else if (refreshAuthServer.includes('bsky.social')) {
809809+ // Already using bsky.social
810810+ console.log('[CREATE STATUS] Using bsky.social directly for token refresh');
811811+ } else {
812812+ // For third-party PDSes, use their own endpoint
813813+ console.log('[CREATE STATUS] Using third-party PDS\'s own endpoint for token refresh:', refreshAuthServer);
814814+ }
815815+786816 // Try to refresh the token
787817 const { accessToken: newAccessToken, refreshToken: newRefreshToken, dpopNonce: newNonce } =
788788- await refreshAccessToken(refreshToken, keyPair, pdsEndpoint || 'https://bsky.social');
818818+ await refreshAccessToken(refreshToken, keyPair, refreshAuthServer);
789819790820 // Update tokens in localStorage
791821 if (typeof localStorage !== 'undefined') {