diff --git a/app/routers/token.py b/app/routers/token.py index 7ef5419..4c362fb 100644 --- a/app/routers/token.py +++ b/app/routers/token.py @@ -2,6 +2,7 @@ from datetime import datetime, timedelta from typing import Annotated from fastapi import Depends, FastAPI, HTTPException, status, APIRouter +from fastapi.responses import JSONResponse from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm from ..dependencies import users_token from ..models import token @@ -9,7 +10,7 @@ from ..models import token router = APIRouter() ACCESS_TOKEN_EXPIRE_MINUTES = 30 -@router.post("/token", response_model=token.Token, tags=["token"]) +@router.post("/token", tags=["token"]) async def login_for_access_token( form_data: Annotated[OAuth2PasswordRequestForm, Depends()] ): @@ -24,4 +25,7 @@ async def login_for_access_token( access_token = users_token.create_access_token( data={"sub": user.username}, expires_delta=access_token_expires ) - return {"access_token": access_token, "token_type": "bearer"} \ No newline at end of file + content = {"message": "Access token generated"} + response = JSONResponse(content=content) + response.set_cookie(key="jwt", value=access_token) + return response \ No newline at end of file