Skip to content

Commit

Permalink
feat: update /auth/session to return categories
Browse files Browse the repository at this point in the history
  • Loading branch information
seelengxd committed Sep 22, 2024
1 parent 0b4dcb1 commit 6bdeeaa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions backend/src/auth/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime, timedelta, timezone
from fastapi import Cookie, Depends, HTTPException, Request, status
from sqlalchemy import select
from sqlalchemy.orm import Session
from sqlalchemy.orm import Session, selectinload
from src.common.database import engine
from .models import User
import jwt
Expand Down Expand Up @@ -90,7 +90,9 @@ async def get_current_user(
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
id = payload.get("sub")
with Session(engine) as session:
staff = session.get(User, id)
staff = session.scalar(
select(User).where(User.id == id).options(selectinload(User.categories))
)
if not staff:
raise InvalidTokenError()

Expand Down
3 changes: 3 additions & 0 deletions backend/src/auth/schemas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pydantic import BaseModel, ConfigDict, EmailStr, Field
from src.categories.schemas import CategoryDTO


class UserPublic(BaseModel):
Expand All @@ -7,6 +8,8 @@ class UserPublic(BaseModel):
id: int
email: EmailStr

categories: list[CategoryDTO]


class Token(BaseModel):
access_token: str
Expand Down

0 comments on commit 6bdeeaa

Please sign in to comment.