mirror of
https://github.com/schroinerxy/cloud-mail.git
synced 2026-06-21 19:35:50 +08:00
优化登录身份缓存机制
This commit is contained in:
@@ -131,7 +131,7 @@ function clickLogout() {
|
||||
logoutLoading.value = true
|
||||
logout().then(() => {
|
||||
localStorage.removeItem("token")
|
||||
router.push('/login')
|
||||
router.replace('/login')
|
||||
}).finally(() => {
|
||||
logoutLoading.value = false
|
||||
})
|
||||
|
||||
@@ -92,7 +92,6 @@ app.use('*', async (c, next) => {
|
||||
const result = await jwtUtils.verifyToken(c, jwt);
|
||||
|
||||
if (!result) {
|
||||
console.error(401,1)
|
||||
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' });
|
||||
|
||||
if (!authInfo) {
|
||||
console.error(401,2)
|
||||
throw new BizError('身份认证失效,请重新登录', 401);
|
||||
}
|
||||
|
||||
if (!authInfo.tokens.includes(token)) {
|
||||
console.error(401,3)
|
||||
throw new BizError('身份认证失效,请重新登录', 401);
|
||||
}
|
||||
|
||||
|
||||
const permIndex = requirePerms.findIndex(item => {
|
||||
return path.startsWith(item);
|
||||
});
|
||||
|
||||
@@ -96,6 +96,10 @@ const loginService = {
|
||||
|
||||
if (authInfo) {
|
||||
|
||||
if (authInfo.tokens.length > 10) {
|
||||
authInfo.tokens.shift();
|
||||
}
|
||||
|
||||
authInfo.tokens.push(uuid);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -79,6 +79,7 @@ const jwtUtils = {
|
||||
return payload;
|
||||
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user