fix auth lifetime
parent
d55e8d1df3
commit
0f5a98b273
|
@ -2,20 +2,18 @@ from fastapi import FastAPI, Request
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
|
|
||||||
from api.domain.error import DomainValidationError
|
from api.domain.error import DomainValidationError
|
||||||
from api.domain.user.error import (UserAlreadyExistsError,
|
from api.domain.user.error import (
|
||||||
UserInvalidCredentialsError,
|
UserAlreadyExistsError,
|
||||||
UserIsNotAuthorizedError)
|
UserInvalidCredentialsError,
|
||||||
|
UserIsNotAuthorizedError,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def validation_error_exc_handler(
|
async def validation_error_exc_handler(request: Request, exc: DomainValidationError) -> JSONResponse:
|
||||||
request: Request, exc: DomainValidationError
|
|
||||||
) -> JSONResponse:
|
|
||||||
return JSONResponse(status_code=400, content={"detail": exc.message})
|
return JSONResponse(status_code=400, content={"detail": exc.message})
|
||||||
|
|
||||||
|
|
||||||
async def user_authentication_error_exc_handler(
|
async def user_authentication_error_exc_handler(request: Request, exc: UserIsNotAuthorizedError) -> JSONResponse:
|
||||||
request: Request, exc: UserIsNotAuthorizedError
|
|
||||||
) -> JSONResponse:
|
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=401,
|
status_code=401,
|
||||||
content={"detail": exc.message},
|
content={"detail": exc.message},
|
||||||
|
@ -23,9 +21,7 @@ async def user_authentication_error_exc_handler(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def user_already_exist_error_exc_handler(
|
async def user_already_exist_error_exc_handler(request: Request, exc: UserAlreadyExistsError) -> JSONResponse:
|
||||||
request: Request, exc: UserAlreadyExistsError
|
|
||||||
) -> JSONResponse:
|
|
||||||
return JSONResponse(status_code=409, content={"detail": exc.message})
|
return JSONResponse(status_code=409, content={"detail": exc.message})
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,12 +36,6 @@ def init_exc_handlers(app: FastAPI) -> None:
|
||||||
DomainValidationError,
|
DomainValidationError,
|
||||||
validation_error_exc_handler,
|
validation_error_exc_handler,
|
||||||
)
|
)
|
||||||
app.add_exception_handler(
|
app.add_exception_handler(UserIsNotAuthorizedError, user_authentication_error_exc_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(
|
|
||||||
UserAlreadyExistsError, user_already_exist_error_exc_handler
|
|
||||||
)
|
|
||||||
app.add_exception_handler(
|
|
||||||
UserInvalidCredentialsError, user_invalid_credentials_error_exc_handler
|
|
||||||
)
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ async def login(
|
||||||
async def logout(
|
async def logout(
|
||||||
response: Response,
|
response: Response,
|
||||||
):
|
):
|
||||||
|
|
||||||
response.delete_cookie(key="access_token", httponly=True)
|
response.delete_cookie(key="access_token", httponly=True)
|
||||||
|
|
||||||
return {"result": "logout"}
|
return {"result": "logout"}
|
||||||
|
|
Loading…
Reference in New Issue