Skip to content

Commit 4d6970c

Browse files
authored
Add is superuser protocol to ctx (#1216)
1 parent d4f78d6 commit 4d6970c

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

backend/common/context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class TypedContextProtocol(Protocol):
2222
language: str
2323

2424
user_id: int | None
25+
is_superuser: bool
2526

2627

2728
class TypedContext(TypedContextProtocol, _Context):

backend/common/security/jwt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ async def jwt_authentication(token: str) -> GetUserInfoWithRelationDetail:
255255
if token != redis_token:
256256
raise errors.TokenError(msg='Token 已失效')
257257

258-
return await get_jwt_user(ctx.user_id)
258+
user = await get_jwt_user(ctx.user_id)
259+
ctx.is_superuser = user.is_superuser
260+
return user
259261

260262

261263
def jwt_authentication_verify(

0 commit comments

Comments
 (0)