优化登录身份缓存机制

This commit is contained in:
eoao
2025-07-04 20:02:00 +08:00
parent 7a0711071d
commit e2aeaf3783
4 changed files with 6 additions and 5 deletions

View File

@@ -131,7 +131,7 @@ function clickLogout() {
logoutLoading.value = true logoutLoading.value = true
logout().then(() => { logout().then(() => {
localStorage.removeItem("token") localStorage.removeItem("token")
router.push('/login') router.replace('/login')
}).finally(() => { }).finally(() => {
logoutLoading.value = false logoutLoading.value = false
}) })

View File

@@ -92,7 +92,6 @@ app.use('*', async (c, next) => {
const result = await jwtUtils.verifyToken(c, jwt); const result = await jwtUtils.verifyToken(c, jwt);
if (!result) { if (!result) {
console.error(401,1)
throw new BizError('身份认证失效,请重新登录', 401); throw new BizError('身份认证失效,请重新登录', 401);
} }
@@ -100,16 +99,13 @@ app.use('*', async (c, next) => {
const authInfo = await c.env.kv.get(KvConst.AUTH_INFO + userId, { type: 'json' }); const authInfo = await c.env.kv.get(KvConst.AUTH_INFO + userId, { type: 'json' });
if (!authInfo) { if (!authInfo) {
console.error(401,2)
throw new BizError('身份认证失效,请重新登录', 401); throw new BizError('身份认证失效,请重新登录', 401);
} }
if (!authInfo.tokens.includes(token)) { if (!authInfo.tokens.includes(token)) {
console.error(401,3)
throw new BizError('身份认证失效,请重新登录', 401); throw new BizError('身份认证失效,请重新登录', 401);
} }
const permIndex = requirePerms.findIndex(item => { const permIndex = requirePerms.findIndex(item => {
return path.startsWith(item); return path.startsWith(item);
}); });

View File

@@ -96,6 +96,10 @@ const loginService = {
if (authInfo) { if (authInfo) {
if (authInfo.tokens.length > 10) {
authInfo.tokens.shift();
}
authInfo.tokens.push(uuid); authInfo.tokens.push(uuid);
} else { } else {

View File

@@ -79,6 +79,7 @@ const jwtUtils = {
return payload; return payload;
} catch (err) { } catch (err) {
console.log(err)
return null; return null;
} }
} }