fix auth lifetime

main
Сергей Ванюшкин 2024-04-07 21:31:51 +00:00
parent d55e8d1df3
commit 0f5a98b273
2 changed files with 11 additions and 22 deletions

View File

@ -2,20 +2,18 @@ from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from api.domain.error import DomainValidationError
from api.domain.user.error import (UserAlreadyExistsError,
UserInvalidCredentialsError,
UserIsNotAuthorizedError)
from api.domain.user.error import (
UserAlreadyExistsError,
UserInvalidCredentialsError,
UserIsNotAuthorizedError,
)
async def validation_error_exc_handler(
request: Request, exc: DomainValidationError
) -> JSONResponse:
async def validation_error_exc_handler(request: Request, exc: DomainValidationError) -> JSONResponse:
return JSONResponse(status_code=400, content={"detail": exc.message})
async def user_authentication_error_exc_handler(
request: Request, exc: UserIsNotAuthorizedError
) -> JSONResponse:
async def user_authentication_error_exc_handler(request: Request, exc: UserIsNotAuthorizedError) -> JSONResponse:
return JSONResponse(
status_code=401,
content={"detail": exc.message},
@ -23,9 +21,7 @@ async def user_authentication_error_exc_handler(
)
async def user_already_exist_error_exc_handler(
request: Request, exc: UserAlreadyExistsError
) -> JSONResponse:
async def user_already_exist_error_exc_handler(request: Request, exc: UserAlreadyExistsError) -> JSONResponse:
return JSONResponse(status_code=409, content={"detail": exc.message})
@ -40,12 +36,6 @@ def init_exc_handlers(app: FastAPI) -> None:
DomainValidationError,
validation_error_exc_handler,
)
app.add_exception_handler(
UserIsNotAuthorizedError, user_authentication_error_exc_handler
)
app.add_exception_handler(
UserAlreadyExistsError, user_already_exist_error_exc_handler
)
app.add_exception_handler(
UserInvalidCredentialsError, user_invalid_credentials_error_exc_handler
)
app.add_exception_handler(UserIsNotAuthorizedError, user_authentication_error_exc_handler)
app.add_exception_handler(UserAlreadyExistsError, user_already_exist_error_exc_handler)
app.add_exception_handler(UserInvalidCredentialsError, user_invalid_credentials_error_exc_handler)

View File

@ -45,7 +45,6 @@ async def login(
async def logout(
response: Response,
):
response.delete_cookie(key="access_token", httponly=True)
return {"result": "logout"}