🐛 fix(login.py): move user authentication logic outside of try-except block to ensure proper error handling

 feat(login.py): add endpoint for auto login to improve user experience
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-25 20:56:39 -03:00
commit c6882a0598

View file

@ -25,21 +25,21 @@ async def login_to_get_access_token(
):
try:
user = authenticate_user(form_data.username, form_data.password, db)
if user:
return create_user_tokens(user_id=user.id, db=db, update_last_login=True)
else:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Incorrect username or password",
headers={"WWW-Authenticate": "Bearer"},
)
except Exception as exc:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=str(exc),
) from exc
if user:
return create_user_tokens(user_id=user.id, db=db, update_last_login=True)
else:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Incorrect username or password",
headers={"WWW-Authenticate": "Bearer"},
)
@router.get("/auto_login")
async def auto_login(