import os import jwt from jwt.exceptions import InvalidTokenError as jwtITError, DecodeError as jwtDError, InvalidSignatureError as jwtISError import supabase jwtKey: string = os.environ.get("JWTKey") class User: def __init__(self, username, token): self.name = username self.token = token # Tokens should be JWT def validate(self): try: curToken = jwt.decode(self.token, jwtKey, algorithms="HS256") except jwtDError: return (false, "Validation failed") try: if curToken["username"] != self.name: raise jwtDError else: return (true, "OK")