Skip to content

Commit

Permalink
update refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
habibasseiss committed Nov 30, 2024
1 parent f678d73 commit d948990
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from app.database import get_session
from app.models import User
from app.schemas import Token
from app.schemas import RefreshToken, Token
from app.security import (
create_access_token,
create_refresh_token,
Expand Down Expand Up @@ -49,8 +49,8 @@ def login_for_access_token(form_data: OAuth2Form, session: DbSession):


@router.post('/refresh', response_model=Token)
def refresh_access_token(refresh_token: str):
token_data = verify_token(refresh_token, 'refresh')
def refresh_access_token(token: RefreshToken):
token_data = verify_token(token.refresh_token, 'refresh')

access_token = create_access_token(data={'sub': token_data.email})
new_refresh_token = create_refresh_token(data={'sub': token_data.email})
Expand Down
20 changes: 13 additions & 7 deletions app/schemas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from uuid import UUID

from pydantic import BaseModel, ConfigDict, EmailStr
Expand All @@ -21,6 +22,7 @@ class FilePublic(BaseModel):
size: int
mime_type: str
original_filename: str
created_at: datetime
model_config = ConfigDict(from_attributes=True)


Expand All @@ -34,6 +36,7 @@ class ProjectPublic(BaseModel):
name: str
description: str
organization_id: UUID
created_at: datetime
files: list[FilePublic] = []
model_config = ConfigDict(from_attributes=True)

Expand All @@ -42,19 +45,18 @@ class ProjectList(BaseModel):
projects: list[ProjectPublic]


class OrganizationSchema(BaseModel):
class OrganizationBasic(BaseModel):
id: UUID
name: str
model_config = ConfigDict(from_attributes=True)


class OrganizationPublic(BaseModel):
id: UUID
name: str
class OrganizationPublic(OrganizationBasic):
projects: list[ProjectPublic]
model_config = ConfigDict(from_attributes=True)


class OrganizationList(BaseModel):
organizations: list[OrganizationPublic]
organizations: list[OrganizationBasic]


class UserSchema(BaseModel):
Expand All @@ -65,7 +67,7 @@ class UserSchema(BaseModel):
class UserPublic(BaseModel):
id: UUID
email: EmailStr
organizations: list[OrganizationPublic]
organizations: list[OrganizationBasic]
model_config = ConfigDict(from_attributes=True)


Expand All @@ -81,3 +83,7 @@ class Token(BaseModel):

class TokenData(BaseModel):
email: EmailStr | None = None


class RefreshToken(BaseModel):
refresh_token: str

0 comments on commit d948990

Please sign in to comment.