fix: 修复普通用户无法正常读取用户信息的问题

This commit is contained in:
SikongJueluo 2025-07-12 18:54:10 +08:00
parent 28af2df093
commit 15c6eefe30
No known key found for this signature in database
2 changed files with 43 additions and 6 deletions

View File

@ -210,15 +210,22 @@ export class AuthManager {
await client.testAdminAuth();
return true;
} catch (error) {
// 如果是401错误说明token有效但不是管理员不需要清除token
// 如果是其他错误可能token无效清除token
// 只有在token完全无效的情况下才清除token
// 401错误表示token有效但权限不足不应清除token
if (
error &&
typeof error === "object" &&
"status" in error &&
error.status !== 401
"status" in error
) {
// 如果是403 (Forbidden) 或401 (Unauthorized)说明token有效但权限不足
if (error.status === 401 || error.status === 403) {
return false;
}
// 其他状态码可能表示token无效清除token
AuthManager.clearToken();
} else {
// 网络错误等不清除token
console.error('管理员权限验证失败:', error);
}
return false;
}

View File

@ -18,6 +18,10 @@
<div v-if="activePage === 1">
<UserInfo />
</div>
<div v-else-if="activePage === 2">
<!-- 添加对应的组件或内容 -->
<div>Item 2 内容</div>
</div>
<div v-else-if="activePage === 100">
<BoardTable />
</div>
@ -37,11 +41,37 @@ const isAdmin = ref(false);
function setActivePage(event: Event) {
const target = event.currentTarget as HTMLLinkElement;
activePage.value = toNumber(target.id);
const newPage = toNumber(target.id);
// 访
if (newPage === 100 && !isAdmin.value) {
return;
}
activePage.value = newPage;
}
onMounted(async () => {
isAdmin.value = await AuthManager.verifyAdminAuth();
try {
//
const isAuthenticated = await AuthManager.isAuthenticated();
if (!isAuthenticated) {
//
// 使
return;
}
//
isAdmin.value = await AuthManager.verifyAdminAuth();
//
if (activePage.value === 100 && !isAdmin.value) {
activePage.value = 1;
}
} catch (error) {
console.error('用户认证检查失败:', error);
//
}
});
</script>