feat: implement brute force protection and error handling for authentication

This commit is contained in:
Lorenzo Venerandi
2026-03-07 17:09:22 +01:00
parent 4fd5832fdc
commit e1ec7ede45
2 changed files with 71 additions and 2 deletions

View File

@@ -136,8 +136,22 @@ document.addEventListener('alpine:init', () => {
this.closeAuthModal();
this.switchToAdmin();
} else {
this.authModal.error = 'Invalid password';
const data = await resp.json().catch(() => ({}));
this.authModal.error = data.error || 'Invalid password';
this.authModal.password = '';
this.authModal.loading = false;
if (data.locked && data.retry_after) {
let remaining = data.retry_after;
const interval = setInterval(() => {
remaining--;
if (remaining <= 0) {
clearInterval(interval);
this.authModal.error = '';
} else {
this.authModal.error = `Too many attempts. Try again in ${remaining}s`;
}
}, 1000);
}
}
} catch {
this.authModal.error = 'Authentication failed';