Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/validate access token user not found #8484

Conversation

nicolasrouanne
Copy link
Contributor

Description

Closes #7244

See details about implementation: #7244 (comment) and #7244 (comment)

Changes

…ror type

- since jest only checks for the message, and no other attributes/methods of the class thrown, see jestjs/jest#13232 (comment)
- we actually had a false positive test on the error code
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR modifies the JWT authentication error handling to properly handle and communicate user not found scenarios, addressing the blank page issue on demo.twenty.com after database resets.

  • Changed error code from INVALID_INPUT to USER_NOT_FOUND in jwt.auth.strategy.ts for better frontend error handling
  • Added explicit error code verification in jwt.auth.strategy.spec.ts to catch false positives in error testing
  • Modified test case to properly verify both error message and code using try/catch block
  • Ensures frontend receives correct error code to trigger login page redirect instead of showing blank screen

2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 153 to +160
await expect(strategy.validate(payload as JwtPayload)).rejects.toThrow(
new AuthException('User not found', AuthExceptionCode.INVALID_INPUT),
new AuthException('User not found', expect.any(String)),
);
try {
await strategy.validate(payload as JwtPayload);
} catch (e) {
expect(e.code).toBe(AuthExceptionCode.USER_NOT_FOUND);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Redundant error testing - the second test using try/catch is unnecessary since Jest's rejects.toThrow() can check both message and code using a matcher object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well... that seems to be wrong, following this comment jestjs/jest#13232 (comment)

However there might be a more elegant way using another matcher inside the .toThrow, but I don't quite have the syntax.

Copy link
Member

Choose a reason for hiding this comment

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

It's good enough like this imo! Thanks a lot!

Copy link
Member

@FelixMalfait FelixMalfait left a comment

Choose a reason for hiding this comment

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

Super clean - well documented, thanks a lot!

@FelixMalfait FelixMalfait merged commit cde96cf into twentyhq:main Nov 13, 2024
17 checks passed
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.

Whitescreen when user not found
2 participants