🐛 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:
parent
62a4e94c71
commit
c6882a0598
1 changed files with 9 additions and 9 deletions
|
|
@ -25,6 +25,11 @@ async def login_to_get_access_token(
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
user = authenticate_user(form_data.username, form_data.password, db)
|
user = authenticate_user(form_data.username, form_data.password, db)
|
||||||
|
except Exception as exc:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
|
detail=str(exc),
|
||||||
|
) from exc
|
||||||
|
|
||||||
if user:
|
if user:
|
||||||
return create_user_tokens(user_id=user.id, db=db, update_last_login=True)
|
return create_user_tokens(user_id=user.id, db=db, update_last_login=True)
|
||||||
|
|
@ -34,11 +39,6 @@ async def login_to_get_access_token(
|
||||||
detail="Incorrect username or password",
|
detail="Incorrect username or password",
|
||||||
headers={"WWW-Authenticate": "Bearer"},
|
headers={"WWW-Authenticate": "Bearer"},
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
||||||
detail=str(exc),
|
|
||||||
) from exc
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/auto_login")
|
@router.get("/auto_login")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue