add login endpoint
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi import APIRouter, Depends, Response
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
|
||||
from src.api.dependacies.db_dep import sessionDep
|
||||
from src.api.dependacies.user_dep import ActiveUser
|
||||
from src.core.settings import settings
|
||||
from src.schemas.auth import Token
|
||||
from src.schemas.users import UserRequestADD
|
||||
from src.services.auth import AuthService
|
||||
|
||||
@@ -17,12 +19,26 @@ async def registration(session: sessionDep, credential: UserRequestADD):
|
||||
return auth
|
||||
|
||||
|
||||
@router.post(path="/login")
|
||||
@router.post(path="/login", response_model=Token)
|
||||
async def login(
|
||||
session: sessionDep,
|
||||
credential: Annotated[OAuth2PasswordRequestForm, Depends()],
|
||||
response: Response
|
||||
):
|
||||
access_token = await AuthService(session).login(
|
||||
result = await AuthService(session).login(
|
||||
credential.username, credential.password
|
||||
)
|
||||
return access_token
|
||||
response.set_cookie(
|
||||
key="refresh_token",
|
||||
value=result["refresh_token"],
|
||||
httponly=True,
|
||||
samesite='lax',
|
||||
path=settings.api.v1.auth,
|
||||
max_age=60 * 60 * 24 * 7
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
@router.post(path="/refresh")
|
||||
async def refresh(user: ActiveUser, response: Response):
|
||||
print(response)
|
||||
|
||||
Reference in New Issue
Block a user