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

Build exceptions and handler #6459

Merged
merged 6 commits into from
Aug 7, 2024
Merged

Build exceptions and handler #6459

merged 6 commits into from
Aug 7, 2024

Conversation

thomtrp
Copy link
Contributor

@thomtrp thomtrp commented Jul 30, 2024

Adding exceptions and handler for auth services.

Tested with:

  • Workspace creation
  • Workspace signup
  • Workspace invitation
  • Reset password
  • Adding email account
  • Impersonation

Copy link

github-actions bot commented Aug 1, 2024

TODOs/FIXMEs:

  • // TODO: replace this with call to third party apps table: packages/twenty-server/src/engine/core-modules/auth/services/token.service.ts

Generated by 🚫 dangerJS against d1f0cbe

@thomtrp thomtrp force-pushed the tt-add-auth-exceptions branch 4 times, most recently from 07976df to a7f1dc3 Compare August 1, 2024 17:00
@thomtrp thomtrp marked this pull request as ready for review August 6, 2024 13:21
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 introduces custom AuthExceptions and handlers to improve error management across the authentication services in the Twenty application.

  • Adds new AuthException class and AuthExceptionCode enum in auth.exception.ts for standardized error handling
  • Implements AuthGraphqlApiExceptionFilter and AuthRestApiExceptionFilter to handle AuthExceptions in GraphQL and REST contexts
  • Replaces generic NestJS exceptions with custom AuthExceptions in various auth services and controllers
  • Updates guards to use AuthExceptions with specific codes (e.g., FORBIDDEN_EXCEPTION) for better error clarity
  • Modifies AuthService and SignInUpService to use custom exceptions and improve input validation

19 file(s) reviewed, 13 comment(s)
Edit PR Review Bot Settings

@@ -151,8 +137,6 @@ export class AuthResolver {
verifyInput.loginToken,
);

assert(email, 'Invalid token', ForbiddenException);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the check to the function bellow

if (!args.appToken) {
throw new BadRequestException('Refresh token is mendatory');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here

assert(user.canImpersonate, 'User cannot impersonate', ForbiddenException);

return this.authService.impersonate(impersonateInput.userId);
return await this.authService.impersonate(impersonateInput.userId, user);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here

args.newPassword,
);
const { id } =
await this.tokenService.validatePasswordResetToken(passwordResetToken);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

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

LGTM @thomtrp 👏

@Weiko Weiko merged commit 2abb6ad into main Aug 7, 2024
4 of 5 checks passed
@Weiko Weiko deleted the tt-add-auth-exceptions branch August 7, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants