blob: f40c68ce891476228deadf766e9efa8433fa5afc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  | 
import typing as t
from starlette.authentication import BaseUser
class User(BaseUser):
    """Starlette BaseUser implementation for JWT authentication."""
    def __init__(self, token: str, payload: dict[str, t.Any]) -> None:
        self.token = token
        self.payload = payload
    @property
    def is_authenticated(self) -> bool:
        """Returns True because user is always authenticated at this stage."""
        return True
    @property
    def display_name(self) -> str:
        """Return username and discriminator as display name."""
        return f"{self.payload['username']}#{self.payload['discriminator']}"
    @property
    def discord_mention(self) -> str:
        return f"<@{self.payload['id']}>"
 
  |