Skip to content

fix verify password response#125

Merged
mohamed-sameh-albaz merged 1 commit into
devfrom
feature/trends
Dec 4, 2025
Merged

fix verify password response#125
mohamed-sameh-albaz merged 1 commit into
devfrom
feature/trends

Conversation

@mohamed-sameh-albaz
Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings December 4, 2025 13:40
@mohamed-sameh-albaz mohamed-sameh-albaz merged commit 6764c46 into dev Dec 4, 2025
3 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request modifies the password verification logic to throw an exception when the password is incorrect, rather than returning a boolean value. However, this creates an inconsistency between the service layer (which now throws exceptions) and the controller layer (which still expects and handles boolean return values).

Key Changes:

  • Modified verifyCurrentPassword method to throw BadRequestException for incorrect passwords instead of returning false
  • Updated controller response message from conditional to hardcoded "Correct Password"

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/auth/services/password/password.service.ts Changed verifyCurrentPassword to throw exception on password mismatch instead of returning false
src/auth/auth.controller.ts Updated response message to hardcoded string, but retained isValid field that will always be true

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if (isMatched) {
return true;
}
throw new BadRequestException('incorrect password');
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message should be capitalized to match the pattern used in other error messages in the codebase. For example, line 174 uses "Old password is incorrect" with proper capitalization.

Suggested change
throw new BadRequestException('incorrect password');
throw new BadRequestException('Incorrect password');

Copilot uses AI. Check for mistakes.
if (isMatched) {
return true;
}
throw new BadRequestException('incorrect password');
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API design has a fundamental issue. The service method now throws a BadRequestException when the password is incorrect (line 195), which means it will never return false. However, the controller code still expects a boolean return value and includes isValid in the response data (line 773). This creates an inconsistent API where:

  1. If the password is correct, it returns { status: 'success', data: { isValid: true }, message: 'Correct Password' }
  2. If the password is incorrect, it throws an exception instead of returning { data: { isValid: false } }

This breaks the original API contract where the endpoint would return both success and failure states without throwing exceptions. Either:

  • Remove the exception and return false when the password is incorrect (reverting to the original behavior), OR
  • Remove the isValid field from the response data since it will always be true if the endpoint doesn't throw an exception
Suggested change
throw new BadRequestException('incorrect password');
return false;

Copilot uses AI. Check for mistakes.
isValid,
},
message: isValid ? 'Password is correct' : 'Password is incorrect',
message: 'Correct Password',
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded message 'Correct Password' is inconsistent with the new error handling in the service. Since verifyCurrentPassword now throws a BadRequestException for incorrect passwords (line 195 in password.service.ts), the conditional message is no longer needed. However, the isValid field in the response data (line 773) will always be true when this line is reached, making it redundant. Consider updating the API documentation to reflect that this endpoint now throws a 400 error for incorrect passwords instead of returning isValid: false.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants