Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies = [
"alembic>=1.13.1",
"asyncpg>=0.29.0",
"SQLAlchemy-Utils>=0.41.1",
"python-jose>=3.3.0",
"PyJWT>=2.8.0",
"SQLAlchemy>=2.0.25",
"python-multipart>=0.0.9",
"greenlet>=2.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/v1/logout.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional

import jwt
from fastapi import APIRouter, Cookie, Depends, Response
from jose import JWTError
from sqlalchemy.ext.asyncio import AsyncSession

from ...core.db.database import async_get_db
Expand All @@ -27,5 +27,5 @@ async def logout(

return {"message": "Logged out successfully"}

except JWTError:
except jwt.PyJWTError:
raise UnauthorizedException("Invalid token.")
16 changes: 8 additions & 8 deletions src/app/core/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Any, Literal

import bcrypt
import jwt
from fastapi.security import OAuth2PasswordBearer
from jose import JWTError, jwt
from pydantic import SecretStr
from sqlalchemy.ext.asyncio import AsyncSession

Expand Down Expand Up @@ -54,21 +54,21 @@ async def authenticate_user(username_or_email: str, password: str, db: AsyncSess
async def create_access_token(data: dict[str, Any], expires_delta: timedelta | None = None) -> str:
to_encode = data.copy()
if expires_delta:
expire = datetime.now(UTC).replace(tzinfo=None) + expires_delta
expire = datetime.now(UTC) + expires_delta
else:
expire = datetime.now(UTC).replace(tzinfo=None) + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
to_encode.update({"exp": expire, "token_type": TokenType.ACCESS})
expire = datetime.now(UTC) + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
to_encode.update({"exp": int(expire.timestamp()), "token_type": TokenType.ACCESS})
encoded_jwt: str = jwt.encode(to_encode, SECRET_KEY.get_secret_value(), algorithm=ALGORITHM)
return encoded_jwt


async def create_refresh_token(data: dict[str, Any], expires_delta: timedelta | None = None) -> str:
to_encode = data.copy()
if expires_delta:
expire = datetime.now(UTC).replace(tzinfo=None) + expires_delta
expire = datetime.now(UTC) + expires_delta
else:
expire = datetime.now(UTC).replace(tzinfo=None) + timedelta(days=REFRESH_TOKEN_EXPIRE_DAYS)
to_encode.update({"exp": expire, "token_type": TokenType.REFRESH})
expire = datetime.now(UTC) + timedelta(days=REFRESH_TOKEN_EXPIRE_DAYS)
to_encode.update({"exp": int(expire.timestamp()), "token_type": TokenType.REFRESH})
encoded_jwt: str = jwt.encode(to_encode, SECRET_KEY.get_secret_value(), algorithm=ALGORITHM)
return encoded_jwt

Expand Down Expand Up @@ -104,7 +104,7 @@ async def verify_token(token: str, expected_token_type: TokenType, db: AsyncSess

return TokenData(username_or_email=username_or_email)

except JWTError:
except jwt.PyJWTError:
return None


Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.