diff --git a/frontend/src/components/auth/SocialAuth.jsx b/frontend/src/components/auth/SocialAuth.jsx index a319c07..475de11 100644 --- a/frontend/src/components/auth/SocialAuth.jsx +++ b/frontend/src/components/auth/SocialAuth.jsx @@ -1,5 +1,6 @@ import { useState } from 'react'; import { useAuth } from '../../context/AuthContext'; +import { firebaseConfigured } from '../../config/firebase.js'; const GOOGLE_ICON = ( @@ -41,30 +42,36 @@ export default function SocialAuth() {
- {error && ( -

{error}

- )} + {!firebaseConfigured ? ( +

Social sign-in is not configured.

+ ) : ( + <> + {error && ( +

{error}

+ )} -
- - -
+
+ + +
+ + )} ); } diff --git a/frontend/src/config/firebase.js b/frontend/src/config/firebase.js index e54f6b1..a5c57d8 100644 --- a/frontend/src/config/firebase.js +++ b/frontend/src/config/firebase.js @@ -3,11 +3,19 @@ import { getAuth, GoogleAuthProvider, GithubAuthProvider } from 'firebase/auth'; const getMeta = (name) => document.querySelector(`meta[name="${name}"]`)?.content || ''; -const app = initializeApp({ +const firebaseConfig = { apiKey: import.meta.env.VITE_FIREBASE_API_KEY || getMeta('fb-api-key'), authDomain: import.meta.env.VITE_FIREBASE_AUTH_DOMAIN || getMeta('fb-auth-domain'), projectId: import.meta.env.VITE_FIREBASE_PROJECT_ID || getMeta('fb-project-id'), -}); +}; + +export const firebaseConfigured = !!(firebaseConfig.apiKey && firebaseConfig.authDomain && firebaseConfig.projectId); + +if (import.meta.env.DEV && !firebaseConfigured) { + console.warn('[Firebase] Missing env vars: VITE_FIREBASE_API_KEY, VITE_FIREBASE_AUTH_DOMAIN, VITE_FIREBASE_PROJECT_ID. Social sign-in will not work.'); +} + +const app = initializeApp(firebaseConfig); export const auth = getAuth(app); export const providers = { diff --git a/frontend/src/context/AuthContext.jsx b/frontend/src/context/AuthContext.jsx index 01aeb7d..b1179f6 100644 --- a/frontend/src/context/AuthContext.jsx +++ b/frontend/src/context/AuthContext.jsx @@ -70,13 +70,23 @@ export function AuthProvider({ children }) { dispatch({ type: 'AUTH_SUCCESS', payload: data.user }); } catch (err) { await firebaseSignOut(auth).catch(() => {}); - let message = err.message; + if (err.code === 'auth/cancelled-popup-request') { + dispatch({ type: 'LOADING' }); + return; + } + let message = 'Sign-in failed. Please try again.'; if (err.code === 'auth/account-exists-with-different-credential') { const other = providerName === 'google' ? 'GitHub' : 'Google'; message = `An account with this email already exists. Try signing in with ${other} instead.`; + } else if (err.code === 'auth/popup-blocked') { + message = 'Sign-in popup was blocked by your browser. Please allow popups for this site and try again.'; + } else if (err.code === 'auth/popup-closed-by-user') { + message = 'Sign-in window was closed. If this keeps happening, check that your browser allows popups for this site.'; + } else if (err.code === 'auth/unauthorized-domain') { + message = 'This domain is not authorized for sign-in. Add the deployment URL to Firebase Console → Authentication → Authorized domains.'; } dispatch({ type: 'AUTH_ERROR', payload: message }); - throw err; + throw new Error(message); } }, []);