antes de alterar login

This commit is contained in:
2026-05-26 16:40:01 +01:00
parent ef265ceeef
commit 3aa6e5468d
12 changed files with 316 additions and 92 deletions

View File

@@ -23,11 +23,51 @@ export default function LoginPage() {
setLoading(true);
try {
await signInWithEmailAndPassword(auth, email, password);
const userCredential = await signInWithEmailAndPassword(auth, email, password);
// Verify the user has a restaurant record before redirecting
if (!userCredential.user?.email) {
setError("Erro: Utilizador sem email válido.");
return;
}
// Success — redirect to dashboard
router.push("/");
} catch (err: any) {
console.error(err);
setError("Credenciais inválidas. Verifique o seu email e palavra-passe.");
console.error("[Login Error]", err.code, err.message);
// Map Firebase Auth error codes to user-friendly messages in Portuguese
switch (err.code) {
case "auth/user-not-found":
setError("Esta conta não existe. Verifique o email ou registe-se.");
break;
case "auth/wrong-password":
setError("Palavra-passe incorrecta. Tente novamente.");
break;
case "auth/invalid-email":
setError("Email inválido. Verifique o formato do email.");
break;
case "auth/invalid-credential":
setError("Credenciais inválidas. Verifique o email e a palavra-passe.");
break;
case "auth/too-many-requests":
setError("Demasiadas tentativas falhadas. Aguarde alguns minutos e tente novamente.");
break;
case "auth/invalid-verification-id":
setError("Sessão expirada. Por favor, recarregue a página e tente novamente.");
break;
case "auth/network-request-failed":
setError("Erro de conexão. Verifique a sua ligação à internet.");
break;
case "auth/weak-password":
setError("A palavra-passe é demasiado curta. Deve ter pelo menos 6 caracteres.");
break;
case "auth/popup-closed-by-user":
// User closed the popup — no error needed
break;
default:
setError("Erro ao entrar. Verifique as suas credenciais e tente novamente.");
}
} finally {
setLoading(false);
}