diff --git a/store/app/routers/email_signup.py b/store/app/routers/email_signup.py index 4604bf6f..ca4c99d7 100644 --- a/store/app/routers/email_signup.py +++ b/store/app/routers/email_signup.py @@ -45,17 +45,19 @@ async def create_signup_token(data: EmailSignUpRequest) -> EmailSignUpResponse: # GET: Retrieve Signup Token @email_signup_router.get("/get/{id}", response_model=GetTokenResponse) async def get_signup_token(id: str) -> GetTokenResponse: - async with EmailSignUpCrud() as crud: # Properly enter the context manager + async with EmailSignUpCrud() as crud: signup_token = await crud.get_email_signup_token(id) if not signup_token: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Token not found.") - return signup_token + + # Map the EmailSignUpToken to GetTokenResponse + return GetTokenResponse(id=signup_token.id, email=signup_token.email) # DELETE: Delete Signup Token @email_signup_router.delete("/delete/{id}", response_model=DeleteTokenResponse) async def delete_signup_token(id: str, crud: EmailSignUpCrud = Depends()) -> DeleteTokenResponse: - deleted = await crud.delete_email_signup_token(id) - if not deleted: - raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Token not found.") + await crud.delete_email_signup_token(id) + + # The return value should be a DeleteTokenResponse, not None return {"message": "Token deleted successfully."} diff --git a/store/app/routers/users.py b/store/app/routers/users.py index 13e786c4..c35a38e7 100644 --- a/store/app/routers/users.py +++ b/store/app/routers/users.py @@ -218,17 +218,15 @@ class LoginResponse(BaseModel): @users_router.post("/login", response_model=LoginResponse) -async def login_user( - data: LoginRequest, user_crud: UserCrud = Depends() -) -> LoginResponse: # Added return type annotation +async def login_user(data: LoginRequest, user_crud: UserCrud = Depends()) -> LoginResponse: async with user_crud: # Fetch user by email user = await user_crud.get_user_from_email(data.email) if not user: raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid email or password") - # Verify password - if not verify_password(data.password, user.hashed_password): + # Ensure `hashed_password` is not None before verifying + if user.hashed_password is None or not verify_password(data.password, user.hashed_password): raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid email or password") token = new_uuid()