Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
0565e626
authored
Jul 03, 2026
by
feitianbubu
Committed by
GitHub
Jul 03, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: only treat 401 as session expiry in auth guard (#5872)
parent
8874d192
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
3 deletions
+8
-3
web/default/src/routes/_authenticated/route.tsx
+8
-3
No files found.
web/default/src/routes/_authenticated/route.tsx
View file @
0565e626
...
@@ -39,13 +39,18 @@ export const Route = createFileRoute('/_authenticated')({
...
@@ -39,13 +39,18 @@ export const Route = createFileRoute('/_authenticated')({
// 本地有用户信息,但需要验证 session 是否有效(每个会话只验证一次)
// 本地有用户信息,但需要验证 session 是否有效(每个会话只验证一次)
if
(
!
sessionVerified
)
{
if
(
!
sessionVerified
)
{
const
res
=
await
getSelf
().
catch
(()
=>
null
)
// 仅 401 视为 session 失效;网络错误/超时/5xx 返回 null 放行,下次导航重验
const
res
=
await
getSelf
().
catch
((
err
:
unknown
)
=>
(
err
as
{
response
?:
{
status
?:
number
}
})?.
response
?.
status
===
401
?
{
success
:
false
}
:
null
)
if
(
res
?.
success
&&
res
.
data
)
{
if
(
res
?.
success
&&
res
.
data
)
{
// 验证成功,更新用户信息(可能有变化)
// 验证成功,更新用户信息(可能有变化)
auth
.
setUser
(
res
.
data
)
auth
.
setUser
(
res
.
data
)
sessionVerified
=
true
sessionVerified
=
true
}
else
{
}
else
if
(
res
)
{
// 验证失败
或 API 调用失败
,清除本地缓存并跳转登录页
// 验证失败,清除本地缓存并跳转登录页
auth
.
reset
()
auth
.
reset
()
throw
redirect
({
throw
redirect
({
to
:
'/sign-in'
,
to
:
'/sign-in'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment