FIX: google auth on windows/web
# Conflicts: # js/accounts/auth.js
This commit is contained in:
parent
7233fb5fbf
commit
9a6d4da463
1 changed files with 36 additions and 3 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
import { auth, provider } from './config.js';
|
import { auth, provider } from './config.js';
|
||||||
import {
|
import {
|
||||||
signInWithPopup,
|
signInWithPopup,
|
||||||
|
signInWithRedirect,
|
||||||
|
getRedirectResult,
|
||||||
signOut as firebaseSignOut,
|
signOut as firebaseSignOut,
|
||||||
onAuthStateChanged,
|
onAuthStateChanged,
|
||||||
signInWithEmailAndPassword,
|
signInWithEmailAndPassword,
|
||||||
|
|
@ -26,6 +28,12 @@ export class AuthManager {
|
||||||
|
|
||||||
this.authListeners.forEach((listener) => listener(user));
|
this.authListeners.forEach((listener) => listener(user));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle redirect result (for Linux/Mobile where popup might be blocked)
|
||||||
|
getRedirectResult(auth).catch((error) => {
|
||||||
|
console.error('Redirect Login failed:', error);
|
||||||
|
alert(`Login failed: ${error.message}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onAuthStateChanged(callback) {
|
onAuthStateChanged(callback) {
|
||||||
|
|
@ -44,11 +52,36 @@ export class AuthManager {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await signInWithPopup(auth, provider);
|
const result = await signInWithPopup(auth, provider);
|
||||||
// The onAuthStateChanged listener will handle the rest
|
|
||||||
|
if (result.user) {
|
||||||
|
console.log('Login successful:', result.user.email);
|
||||||
|
this.user = result.user;
|
||||||
|
this.updateUI(result.user);
|
||||||
|
this.authListeners.forEach((listener) => listener(result.user));
|
||||||
return result.user;
|
return result.user;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Login failed:', error);
|
console.error('Login failed:', error);
|
||||||
|
|
||||||
|
// On Linux, if popup is blocked or fails, we might be forced to redirect,
|
||||||
|
// but we've seen it "bug the app", so we alert the user first.
|
||||||
|
if (error.code === 'auth/popup-blocked' || error.code === 'auth/cancelled-popup-request') {
|
||||||
|
if (
|
||||||
|
confirm(
|
||||||
|
'The login popup was blocked or failed to communicate. Would you like to try a redirect instead? Note: This may reload the application.'
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
await signInWithRedirect(auth, provider);
|
||||||
|
return;
|
||||||
|
} catch (redirectError) {
|
||||||
|
console.error('Redirect fallback failed:', redirectError);
|
||||||
|
alert(`Login failed: ${redirectError.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
alert(`Login failed: ${error.message}`);
|
alert(`Login failed: ${error.message}`);
|
||||||
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue