Fix: Add fallback token retrieval endpoint and improved token extraction debugging
This commit is contained in:
@@ -101,13 +101,51 @@
|
||||
const email = authData?.meta?.rawUser?.email || authData?.record?.email || pb.authStore.model?.email || 'Not available';
|
||||
const graphToken = extractGraphToken(authData);
|
||||
console.log('Extracted Graph token:', graphToken ? graphToken.substring(0, 30) + '...' : 'NOT FOUND');
|
||||
console.log('Full meta object:', JSON.stringify(authData?.meta, null, 2));
|
||||
|
||||
if (graphToken) {
|
||||
localStorage.setItem(GRAPH_TOKEN_KEY, graphToken);
|
||||
localStorage.removeItem(GRAPH_REAUTH_FLAG);
|
||||
console.log('✓ Graph token stored');
|
||||
} else {
|
||||
console.error('❌ Graph token NOT found in auth response!');
|
||||
console.error('Available meta keys:', Object.keys(authData?.meta || {}));
|
||||
// If token not in response, try fetching it from the backend
|
||||
console.log('Attempting to fetch token from backend...');
|
||||
fetchTokenFromBackend().then(token => {
|
||||
if (token) {
|
||||
localStorage.setItem(GRAPH_TOKEN_KEY, token);
|
||||
console.log('✓ Graph token fetched from backend');
|
||||
} else {
|
||||
console.warn('⚠ Graph token could not be obtained from backend');
|
||||
}
|
||||
showAuthedUI(displayName, email);
|
||||
}).catch(err => {
|
||||
console.error('Failed to fetch token from backend:', err);
|
||||
showAuthedUI(displayName, email);
|
||||
});
|
||||
return;
|
||||
}
|
||||
showAuthedUI(displayName, email);
|
||||
}
|
||||
|
||||
async function fetchTokenFromBackend() {
|
||||
try {
|
||||
const response = await fetch('/api/graph-token', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${pb.authStore.token}`
|
||||
}
|
||||
});
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
return data.token || '';
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Token fetch error:', err.message);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const reauth = params.get('reauth') === '1';
|
||||
|
||||
Reference in New Issue
Block a user