diff options
Diffstat (limited to '')
| -rw-r--r-- | backend/authentication/user.py | 17 | 
1 files changed, 17 insertions, 0 deletions
| diff --git a/backend/authentication/user.py b/backend/authentication/user.py index f40c68c..a1d78e5 100644 --- a/backend/authentication/user.py +++ b/backend/authentication/user.py @@ -1,7 +1,11 @@  import typing as t +import jwt  from starlette.authentication import BaseUser +from backend.constants import SECRET_KEY +from backend.discord import fetch_user_details +  class User(BaseUser):      """Starlette BaseUser implementation for JWT authentication.""" @@ -23,3 +27,16 @@ class User(BaseUser):      @property      def discord_mention(self) -> str:          return f"<@{self.payload['id']}>" + +    @property +    def decoded_token(self) -> dict[str, any]: +        return jwt.decode(self.token, SECRET_KEY, algorithms=["HS256"]) + +    async def refresh_data(self) -> None: +        """Fetches user data from discord, and updates the instance.""" +        self.payload = await fetch_user_details(self.decoded_token.get("token")) + +        updated_info = self.decoded_token +        updated_info["user_details"] = self.payload + +        self.token = jwt.encode(updated_info, SECRET_KEY, algorithm="HS256") | 
