You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# 修复前
try:
user = await jwt_authentication(token)
except TokenError as exc:
raise AuthenticationError(code=exc.code, msg=exc.detail, headers=exc.headers)
# 修复后
try:
user = await jwt_authentication(token)
except Exception:
return None
目的
解决公开接口(如 GET /agreements)被误拦截的问题——前端传了过期 token 时,中间件不再拦截,让请求正常到达路由处理函数。
引发的新问题
修复后,需认证的接口传了过期 token 时,出现 500 内部错误:
File "backend/app/admin/api/v1/sys/user.py", line 27, in get_current_user
data = request.user.model_dump()
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'UnauthenticatedUser' object has no attribute 'model_dump'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
close #1213