From 4d6970c6cc7f89a3ee1f1599c4518730acd2ad7f Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Fri, 3 Jul 2026 13:40:58 +0800 Subject: [PATCH] Add is superuser protocol to ctx (#1216) --- backend/common/context.py | 1 + backend/common/security/jwt.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/common/context.py b/backend/common/context.py index 2b06d0a4..dc8552e3 100644 --- a/backend/common/context.py +++ b/backend/common/context.py @@ -22,6 +22,7 @@ class TypedContextProtocol(Protocol): language: str user_id: int | None + is_superuser: bool class TypedContext(TypedContextProtocol, _Context): diff --git a/backend/common/security/jwt.py b/backend/common/security/jwt.py index eac40547..a3977ecc 100644 --- a/backend/common/security/jwt.py +++ b/backend/common/security/jwt.py @@ -255,7 +255,9 @@ async def jwt_authentication(token: str) -> GetUserInfoWithRelationDetail: if token != redis_token: raise errors.TokenError(msg='Token 已失效') - return await get_jwt_user(ctx.user_id) + user = await get_jwt_user(ctx.user_id) + ctx.is_superuser = user.is_superuser + return user def jwt_authentication_verify(