🐛 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,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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue