From 83140043a1eadbf47764554e6d4b7bba5236a1bc Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Wed, 26 Mar 2025 16:23:37 +0000 Subject: [PATCH] Add POST endpoint for /login --- endpoints/login.post.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/endpoints/login.post.py b/endpoints/login.post.py index 4d4e155..ca95e33 100644 --- a/endpoints/login.post.py +++ b/endpoints/login.post.py @@ -16,22 +16,21 @@ async def login( db: Session = Depends(get_db) ): user = db.query(User).filter(User.email == login_data.email).first() - if not user: + if not user or not verify_password(login_data.password, user.hashed_password): raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, - detail="Incorrect email or password" - ) - - if not verify_password(login_data.password, user.hashed_password): - raise HTTPException( - status_code=status.HTTP_401_UNAUTHORIZED, - detail="Incorrect email or password" + detail="Incorrect email or password", + headers={"WWW-Authenticate": "Bearer"}, ) access_token = create_access_token(data={"sub": user.email}) return { "access_token": access_token, "token_type": "bearer", - "user": UserSchema.from_orm(user) + "user": { + "id": user.id, + "email": user.email, + "role": user.role + } } ``` \ No newline at end of file