优化评论区/个人中心验证登录态相关逻辑,性能提升
This commit is contained in:
parent
1695864e99
commit
0390dd19fe
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
dist/index.html
vendored
2
dist/index.html
vendored
@ -1 +1 @@
|
||||
<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>NEU小站</title><script defer="defer" src="/js/chunk-vendors.f3a85c9b.js"></script><script defer="defer" src="/js/app.4a2a4607.js"></script><link href="/css/app.91c3e0f8.css" rel="stylesheet"></head><body><noscript><strong>抱歉,NEU小站无法在没有 JavaScript 的情况下正常工作。请启用 JavaScript 以继续。</strong></noscript><div id="app"></div></body></html>
|
||||
<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>NEU小站</title><script defer="defer" src="/js/chunk-vendors.f3a85c9b.js"></script><script defer="defer" src="/js/app.46a2c1d1.js"></script><link href="/css/app.91c3e0f8.css" rel="stylesheet"></head><body><noscript><strong>抱歉,NEU小站无法在没有 JavaScript 的情况下正常工作。请启用 JavaScript 以继续。</strong></noscript><div id="app"></div></body></html>
|
File diff suppressed because one or more lines are too long
2
dist/js/614.443c84a6.js
vendored
Normal file
2
dist/js/614.443c84a6.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
dist/js/879.581ebf2e.js
vendored
2
dist/js/879.581ebf2e.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -81,7 +81,8 @@ export default {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('https://newfront.xn--xhq44jb2fzpc.com/user/info', {
|
||||
// 使用 /islogin 接口快速验证 token
|
||||
const response = await fetch('https://newfront.xn--xhq44jb2fzpc.com/user/islogin', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': token
|
||||
@ -89,11 +90,20 @@ export default {
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('获取用户信息失败');
|
||||
// 如果状态码不是 2xx (例如 401 Unauthorized)
|
||||
throw new Error('Token 验证失败');
|
||||
}
|
||||
|
||||
// 验证成功
|
||||
const data = await response.json();
|
||||
if (data && data.isLoggedIn) {
|
||||
this.isAuthenticated = true;
|
||||
} else {
|
||||
// 理论上如果 response.ok 为 true,这里不应该执行
|
||||
// 但以防万一,处理逻辑上验证失败的情况
|
||||
throw new Error('Token 验证成功但返回状态不正确');
|
||||
}
|
||||
|
||||
const userData = await response.json();
|
||||
this.isAuthenticated = true;
|
||||
this.isLoading = false;
|
||||
|
||||
// 如果登录成功且当前在/login路径,重定向到/user-center
|
||||
|
Loading…
x
Reference in New Issue
Block a user