feat: 修复接口认证时查询用户信息没有缓存用户的职位信息的问题
This commit is contained in:
@@ -10,7 +10,8 @@ from starlette.responses import JSONResponse
|
||||
from app.config.env import env
|
||||
from app.controller.add_user_route import unauthorized_exception, get_current_user
|
||||
from app.model.ApiSecretModel import ApiSecretService
|
||||
from app.model.UserModel import PublicUser
|
||||
from app.model.PosModel import PosModel
|
||||
from app.model.UserModel import UserServiceModel
|
||||
from app.utils.CrpyUtils import TokenInfo, CryptUtils
|
||||
from app.utils.api_secret_utils import api_secret_utils, ApiSecretStatus
|
||||
from app.utils.db_utils import async_session
|
||||
@@ -68,8 +69,8 @@ def add_app_middlewares(app: FastAPI):
|
||||
async def get_default_cache_value():
|
||||
async with async_session() as session:
|
||||
try:
|
||||
public_user = await get_current_user(session, token)
|
||||
return public_user.model_dump(mode="json")
|
||||
user_dict = await get_current_user(session, token)
|
||||
return user_dict
|
||||
except InvalidTokenError:
|
||||
return None
|
||||
|
||||
@@ -80,7 +81,11 @@ def add_app_middlewares(app: FastAPI):
|
||||
if not user_dict:
|
||||
raise unauthorized_exception
|
||||
|
||||
request.state.user = PublicUser(**user_dict)
|
||||
print("user_dict", user_dict)
|
||||
request.state.user = UserServiceModel(**user_dict)
|
||||
user_pos_dict = user_dict.get('pos')
|
||||
if user_pos_dict:
|
||||
request.state.user.position = PosModel(**user_pos_dict)
|
||||
request.state.token = token
|
||||
|
||||
# 如果请求的是api接口
|
||||
|
||||
Reference in New Issue
Block a user