fix: preserva email no login quando senha incorreta

- Passa email como parametro na URL de erro
- Preenche campo automaticamente ao recarregar
- Foca no campo senha quando email ja preenchido

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
root
2026-02-08 13:38:13 -05:00
parent 627fa8e7a4
commit 0669214d47
2 changed files with 10 additions and 3 deletions

View File

@@ -168,7 +168,13 @@
el.textContent = 'E-mail ou senha incorretos.';
el.style.display = 'block';
}
document.getElementById('email').focus();
const emailParam = params.get('email');
if (emailParam) {
document.getElementById('email').value = emailParam;
document.getElementById('senha').focus();
} else {
document.getElementById('email').focus();
}
</script>
</body>
</html>

View File

@@ -55,9 +55,10 @@ app.get('/login', (req, res) => {
// Unified Login POST - detects role and redirects accordingly
app.post('/login', async (req, res) => {
const { email, senha } = req.body;
const emailParam = encodeURIComponent(email || '');
try {
const user = await authenticate(email, senha);
if (!user) return res.redirect('/login?error=1');
if (!user) return res.redirect(`/login?error=1&email=${emailParam}`);
// Unified session
req.session.user = {
@@ -76,7 +77,7 @@ app.post('/login', async (req, res) => {
}
} catch (err) {
console.error('Login error:', err);
res.redirect('/login?error=1');
res.redirect(`/login?error=1&email=${emailParam}`);
}
});