diff --git a/backend/src/index.ts b/backend/src/index.ts index b6f9061..b83f8e2 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -47,6 +47,9 @@ app.use(express.urlencoded({ extended: true })); // Request logging app.use((req, res, next) => { + if (req.path === '/health') { + return next(); + } logger.info(`${req.method} ${req.path}`, { ip: req.ip, userAgent: req.get('User-Agent') diff --git a/frontend/src/stores/admin.ts b/frontend/src/stores/admin.ts index 8487227..af89500 100644 --- a/frontend/src/stores/admin.ts +++ b/frontend/src/stores/admin.ts @@ -22,13 +22,20 @@ export const useAdminStore = defineStore('admin', () => { const isLoggedIn = computed(() => !!token.value && !!admin.value) // 初始化认证状态 - const initAuth = () => { + const initAuth = async () => { const storedToken = adminAuth.getToken() const storedAdmin = adminAuth.getAdminInfo() if (storedToken && storedAdmin) { token.value = storedToken admin.value = storedAdmin + try { + await getStats() + } catch (error) { + // token失效,清除本地存储 + logout() + console.error('Admin token is invalid, logging out') + } } } diff --git a/frontend/src/stores/auth.ts b/frontend/src/stores/auth.ts index 45cf696..67bdb91 100644 --- a/frontend/src/stores/auth.ts +++ b/frontend/src/stores/auth.ts @@ -15,15 +15,20 @@ export const useAuthStore = defineStore('auth', () => { const isLoggedIn = computed(() => !!token.value && !!user.value) // 初始化认证状态 - const initAuth = () => { + const initAuth = async () => { const storedToken = userAuth.getToken() const storedUser = userAuth.getUserInfo() - + if (storedToken && storedUser) { token.value = storedToken user.value = storedUser - } else { - + try { + await getProfile() + } catch (error) { + // token失效,清除本地存储 + logout() + console.error('Token is invalid, logging out') + } } } diff --git a/frontend/src/views/Test.vue b/frontend/src/views/Test.vue deleted file mode 100644 index 8c16496..0000000 --- a/frontend/src/views/Test.vue +++ /dev/null @@ -1,212 +0,0 @@ - - - \ No newline at end of file