fix problems
This commit is contained in:
+10
-4
@@ -30,12 +30,17 @@ class JwtService:
|
||||
def __init__(self) -> None:
|
||||
|
||||
self.error=Errors()
|
||||
|
||||
def _validate_sub(self,data:dict)->None:
|
||||
if not (data.get("sub")) or data.get("sub") == "":
|
||||
raise self.error.credentials_error(detail="Jwt token is incorrect")
|
||||
|
||||
def create_access_token(self, data:dict)->str:
|
||||
|
||||
user_info=data.copy()
|
||||
if not (user_info.get("sub")) or user_info.get("sub") == "":
|
||||
raise self.error.credentials_error(detail="Jwt token is incorrect")
|
||||
|
||||
self._validate_sub(user_info)
|
||||
|
||||
user_info.update({"exp": datetime.now(UTC)+timedelta(minutes=env_settings.ACCESS_TOKEN_EXPIRE_MINUTES),
|
||||
"token_type":"access"})
|
||||
return jwt.encode(user_info, env_settings.SECRET_KEY, env_settings.ALGORITHM)
|
||||
@@ -45,8 +50,9 @@ class JwtService:
|
||||
|
||||
user_info=data.copy()
|
||||
jti=str(uuid4())
|
||||
if not (user_info.get("sub")) or user_info.get("sub") == "":
|
||||
raise self.error.credentials_error(detail="Jwt token is incorrect")
|
||||
|
||||
self._validate_sub(user_info)
|
||||
|
||||
user_info.update({"exp":datetime.now(UTC)+timedelta(days=env_settings.REFRESH_TOKEN_EXPIRE_DAYS),
|
||||
"token_type":"refresh",
|
||||
"jti":jti
|
||||
|
||||
Reference in New Issue
Block a user