Spaces:
Runtime error
Runtime error
YoonJ-C
commited on
Commit
Β·
043cba6
1
Parent(s):
b930736
Improve Google Sign-In with better error handling and user feedback
Browse files- Add account selection prompt for better UX
- Add loading state messages during sign-in process
- Implement comprehensive error handling for common Firebase auth errors
- Provide user-friendly error messages for different failure scenarios
- static/script.js +41 -2
static/script.js
CHANGED
|
@@ -15,10 +15,25 @@ async function signInWithGoogle() {
|
|
| 15 |
|
| 16 |
const provider = new firebase.auth.GoogleAuthProvider();
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
const result = await window.firebaseAuth.signInWithPopup(provider);
|
| 20 |
const user = result.user;
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
// Get ID token to send to backend
|
| 23 |
const idToken = await user.getIdToken();
|
| 24 |
|
|
@@ -41,8 +56,32 @@ async function signInWithGoogle() {
|
|
| 41 |
}
|
| 42 |
} catch (error) {
|
| 43 |
console.error('Google Sign-In Error:', error);
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
}
|
| 48 |
|
|
|
|
| 15 |
|
| 16 |
const provider = new firebase.auth.GoogleAuthProvider();
|
| 17 |
|
| 18 |
+
// Configure provider for better popup behavior
|
| 19 |
+
provider.setCustomParameters({
|
| 20 |
+
prompt: 'select_account' // Always show account selection
|
| 21 |
+
});
|
| 22 |
+
|
| 23 |
try {
|
| 24 |
+
// Show loading state
|
| 25 |
+
const resultDiv = document.getElementById('result');
|
| 26 |
+
if (resultDiv) {
|
| 27 |
+
resultDiv.innerHTML = '<p style="color: #666;">Opening sign-in window...</p>';
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
const result = await window.firebaseAuth.signInWithPopup(provider);
|
| 31 |
const user = result.user;
|
| 32 |
|
| 33 |
+
if (resultDiv) {
|
| 34 |
+
resultDiv.innerHTML = '<p style="color: #666;">Signing in...</p>';
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
// Get ID token to send to backend
|
| 38 |
const idToken = await user.getIdToken();
|
| 39 |
|
|
|
|
| 56 |
}
|
| 57 |
} catch (error) {
|
| 58 |
console.error('Google Sign-In Error:', error);
|
| 59 |
+
console.error('Error code:', error.code);
|
| 60 |
+
console.error('Error details:', error);
|
| 61 |
+
|
| 62 |
+
const resultDiv = document.getElementById('result');
|
| 63 |
+
let errorMsg = '';
|
| 64 |
+
|
| 65 |
+
// Handle specific error cases
|
| 66 |
+
if (error.code === 'auth/popup-closed-by-user') {
|
| 67 |
+
errorMsg = 'β Sign-in window was closed. Please try again and complete the sign-in process.';
|
| 68 |
+
} else if (error.code === 'auth/popup-blocked') {
|
| 69 |
+
errorMsg = 'β Pop-up was blocked by your browser. Please allow pop-ups for this site and try again.';
|
| 70 |
+
} else if (error.code === 'auth/cancelled-popup-request') {
|
| 71 |
+
errorMsg = 'β Another sign-in is in progress. Please wait a moment and try again.';
|
| 72 |
+
} else if (error.code === 'auth/unauthorized-domain') {
|
| 73 |
+
errorMsg = 'β This domain is not authorized for Google Sign-In. Please contact the administrator.';
|
| 74 |
+
} else if (error.code === 'auth/operation-not-allowed') {
|
| 75 |
+
errorMsg = 'β Google Sign-In is not enabled. Please contact the administrator.';
|
| 76 |
+
} else if (error.code === 'auth/network-request-failed') {
|
| 77 |
+
errorMsg = 'β Network error. Please check your internet connection and try again.';
|
| 78 |
+
} else {
|
| 79 |
+
errorMsg = `β ${error.message || 'Google Sign-In failed. Please try again.'}`;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
if (resultDiv) {
|
| 83 |
+
resultDiv.innerHTML = `<p class="error-msg">${errorMsg}</p>`;
|
| 84 |
+
}
|
| 85 |
}
|
| 86 |
}
|
| 87 |
|