This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

ts errors

+22 -39
+22 -39
app/src/app/auth/callback/page.tsx
··· 133 133 134 134 setStatus('Getting user profile...'); 135 135 136 - // We'll extract the PDS endpoint from the decoded token 136 + // Extract PDS endpoint from the token 137 + let pdsEndpoint = null; 138 + 139 + // First, try to decode the access token 140 + try { 141 + const parts = tokenResponse.access_token.split('.'); 142 + if (parts.length === 3) { 143 + const payload = JSON.parse(atob(parts[1])); 144 + if (payload.aud && typeof payload.aud === 'string' && payload.aud.startsWith('did:web:')) { 145 + pdsEndpoint = 'https://' + payload.aud.replace('did:web:', ''); 146 + } 147 + } 148 + } catch (e) { 149 + console.warn('Failed to extract PDS endpoint from token'); 150 + } 137 151 138 152 // Get user profile 139 153 let profileResponse; ··· 143 157 keyPair, 144 158 dpopNonce, 145 159 undefined, // Use default handle 146 - pdsEndpoint // Pass the PDS endpoint 160 + pdsEndpoint // Pass the PDS endpoint if we have it 147 161 ); 148 162 } catch (profileError: any) { 149 163 console.error('Profile fetch error:', profileError); ··· 161 175 const userDid = tokenResponse.sub; 162 176 console.log('User DID from token:', userDid); 163 177 164 - // Extract PDS endpoint from the token 165 - let extractedPdsEndpoint = null; 166 - 167 - // Try to decode the access token to extract the audience 168 - try { 169 - if (tokenResponse.access_token) { 170 - const parts = tokenResponse.access_token.split('.'); 171 - if (parts.length === 3) { 172 - // Decode the payload (second part) 173 - const payload = JSON.parse(atob(parts[1])); 174 - 175 - // Extract audience from the decoded token 176 - if (payload.aud && typeof payload.aud === 'string') { 177 - // Update the pdsEndpoint from the decoded token if available 178 - if (payload.aud.startsWith('did:web:')) { 179 - // Convert did:web:example.com to https://example.com 180 - extractedPdsEndpoint = 'https://' + payload.aud.replace('did:web:', ''); 181 - console.log('Extracted PDS endpoint from decoded token:', extractedPdsEndpoint); 182 - 183 - // Update our variable for use in the rest of the function 184 - pdsEndpoint = extractedPdsEndpoint; 185 - } 186 - } 187 - } 188 - } 189 - } catch (error) { 190 - console.warn('Failed to decode token:', error); 191 - } 192 - 193 - // If we couldn't extract the PDS endpoint, show an error 194 - if (!pdsEndpoint) { 195 - console.error('Failed to extract PDS endpoint from token. This will cause API calls to fail.'); 178 + // If we were able to extract the PDS endpoint, log it 179 + if (pdsEndpoint) { 180 + console.log('Extracted PDS endpoint from token:', pdsEndpoint); 181 + } else { 182 + console.warn('Could not extract PDS endpoint from token'); 196 183 } 197 184 198 185 // Now that we have the PDS endpoint, try to get the user's handle directly ··· 209 196 keyPair, 210 197 dpopNonce, 211 198 userDid, // Use the user's DID instead of default 212 - pdsEndpoint 199 + pdsEndpoint // Pass the PDS endpoint if we have it 213 200 ); 214 201 215 202 if (handleResponse && handleResponse.handle) { ··· 224 211 } 225 212 } 226 213 227 - // Log the PDS endpoint that will be used 228 - console.log('Using PDS endpoint for API requests:', pdsEndpoint); 229 - 230 214 // Store auth data 231 - console.log('Saving PDS endpoint to auth context:', pdsEndpoint); 232 215 setAuth({ 233 216 accessToken: tokenResponse.access_token, 234 217 refreshToken: tokenResponse.refresh_token,