aboutsummaryrefslogtreecommitdiffstats
path: root/backend/authentication/user.py
blob: afa243fefc4c85d5cc8db494e4f48c2c2404c6ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import typing as t
from abc import ABC

from starlette.authentication import BaseUser


class User(BaseUser, ABC):
    """Starlette BaseUser implementation for JWT authentication."""

    def __init__(self, token: str, payload: t.Dict) -> 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']}"