Revert "Refactor login method to use unified identifier for user input; update request body to support both email and username"

This reverts commit 3c901a35a6.
This commit is contained in:
Алекс 2026-01-16 20:59:01 +01:00
parent ac84ee86c1
commit f81d742bde
1 changed files with 4 additions and 9 deletions

View File

@ -4,19 +4,14 @@ export class Auth {
this.isAuthenticated = false; this.isAuthenticated = false;
} }
async login(identifier, password) { async login(email, password) {
if (!identifier || !password) return false; if (!email || !password) return false;
try { try {
const response = await fetch(`${import.meta.env.VITE_API_BASE_URL}/api/Auth/login`, { const response = await fetch(`${import.meta.env.VITE_API_BASE_URL}/api/Auth/login`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
// Enviamos ambos nombres de campo para cubrir email o userName según espere el backend. body: JSON.stringify({ email, password })
body: JSON.stringify({
email: identifier,
userName: identifier,
password
})
}); });
if (!response.ok) return false; if (!response.ok) return false;
@ -24,7 +19,7 @@ export class Auth {
const { token, user } = await response.json(); const { token, user } = await response.json();
if (!token) return false; if (!token) return false;
this.currentUser = user || { email: identifier }; this.currentUser = user || { email };
this.isAuthenticated = true; this.isAuthenticated = true;
localStorage.setItem('user', JSON.stringify(this.currentUser)); localStorage.setItem('user', JSON.stringify(this.currentUser));
localStorage.setItem('token', token); localStorage.setItem('token', token);