Mhdeusi commited on
Commit
ff0bda6
·
verified ·
1 Parent(s): d8d6827

Update js/middleware/auth_middleware.js

Browse files
Files changed (1) hide show
  1. js/middleware/auth_middleware.js +13 -20
js/middleware/auth_middleware.js CHANGED
@@ -26,28 +26,21 @@ class AuthMiddleware {
26
  }
27
 
28
  static initializeApp() {
29
- // مقداردهی اولیه کاربران پیش‌فرض
30
- authManager.initializeDefaultUsers();
31
-
32
- // بررسی توکن موجود
33
- const token = authManager.getToken();
34
- if (token) {
35
- const tokenData = authManager.verifyToken(token);
36
- if (!tokenData) {
37
- authManager.logout();
38
- console.log('Token expired, user logged out');
 
39
  }
40
- }
41
-
42
- // نمایش وضعیت ورود در کنسول
43
- const currentUser = authManager.getCurrentUser();
44
- if (currentUser) {
45
- console.log(`User authenticated: ${currentUser.username} (${currentUser.role})`);
46
- } else {
47
- console.log('No user authenticated');
48
- }
49
  }
50
- }
51
 
52
  // میان‌افزارهای سریع
53
  const requireAuth = (callback) => AuthMiddleware.checkAuth()(callback);
 
26
  }
27
 
28
  static initializeApp() {
29
+ console.log('🔐 Auth Middleware Initialized');
30
+
31
+ // فقط بررسی ساده - حذف فراخوانی‌های مشکل‌دار
32
+ if (typeof authManager !== 'undefined' && authManager.getToken) {
33
+ const token = authManager.getToken();
34
+ if (token) {
35
+ const user = authManager.getCurrentUser();
36
+ if (!user) {
37
+ authManager.logout();
38
+ console.log('Token exists but no user - logged out');
39
+ }
40
  }
41
+ }
 
 
 
 
 
 
 
 
42
  }
43
+ }
44
 
45
  // میان‌افزارهای سریع
46
  const requireAuth = (callback) => AuthMiddleware.checkAuth()(callback);