diff --git a/static/js/auth.js b/static/js/auth.js
index ddef0805..d973b80f 100644
--- a/static/js/auth.js
+++ b/static/js/auth.js
@@ -55,42 +55,33 @@ class AuthManager {
const loginBtn = document.querySelector('.login-btn');
try {
- // Show loading state
loginBtn.innerHTML = ' Authenticating...';
loginBtn.disabled = true;
- // Simple authentication - in production, this would call an API
- // For now, using mock authentication
- await new Promise(resolve => setTimeout(resolve, 1000));
+ const response = await fetch('/api/auth/login', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ username, password })
+ });
- if (username === 'admin' && password === 'admin123') {
- // Successful login
- this.token = this.generateToken();
- this.user = {
- username: 'admin',
- name: 'Administrator',
- role: 'Super Admin',
- avatar: null
- };
+ const result = await response.json();
+
+ if (result.success) {
+ this.token = result.data.token;
+ this.user = result.data.user;
- // Save to localStorage
localStorage.setItem('dashboard_token', this.token);
localStorage.setItem('dashboard_user', JSON.stringify(this.user));
this.isAuthenticated = true;
this.showDashboard();
-
- // Show success message
this.showToast('Successfully logged in!', 'success');
} else {
- throw new Error('Invalid credentials');
+ throw new Error(result.error || 'Invalid credentials');
}
} catch (error) {
- // Show error
errorElement.style.display = 'flex';
errorElement.querySelector('span').textContent = error.message;
-
- // Reset button
loginBtn.innerHTML = ' Sign In';
loginBtn.disabled = false;
}