Add debugging for OAuth token storage and API requests

- Add token verification before redirect
- Add detailed logging for API requests
- Increase redirect delay to ensure localStorage sync
parent 188e0a7c
......@@ -771,10 +771,25 @@ function setupOAuthMessageListener() {
const displayName = currentUser.real_name || currentUser.username;
showNotification(`Welcome, ${displayName}!`, 'success');
// Redirect to appropriate dashboard
// Verify token was stored before redirecting
console.log('OAuth: Token stored, verifying...', {
tokenStored: localStorage.getItem('authToken') ? 'yes' : 'no',
tokenLength: localStorage.getItem('authToken')?.length || 0
});
// Redirect to appropriate dashboard after ensuring storage is complete
// Use a longer delay to ensure localStorage is synced
setTimeout(() => {
redirectToDashboard(currentUser.role);
}, 1000);
// Double-check token before redirect
const storedToken = localStorage.getItem('authToken');
if (storedToken) {
console.log('OAuth: Redirecting with valid token');
redirectToDashboard(currentUser.role);
} else {
console.error('OAuth: Token not found in localStorage after storage!');
showNotification('Authentication error. Please try again.', 'error');
}
}, 1500);
} else if (event.data.error) {
console.error('OAuth error:', event.data.error);
showNotification(event.data.error, 'error');
......@@ -1748,6 +1763,14 @@ async function updateAvatar(avatarData = null, avatarUrl = null) {
async function apiRequest(endpoint, method = 'GET', data = null) {
const token = localStorage.getItem('authToken');
console.log('API Request:', {
endpoint: endpoint,
method: method,
hasToken: !!token,
tokenLength: token ? token.length : 0,
tokenPreview: token ? token.substring(0, 30) + '...' : 'none'
});
const options = {
method: method,
headers: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment