-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
92a984a
to
ac9ae73
Compare
07976df
to
a7f1dc3
Compare
a7f1dc3
to
ea83099
Compare
There was a problem hiding this 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 andAuthExceptionCode
enum inauth.exception.ts
for standardized error handling - Implements
AuthGraphqlApiExceptionFilter
andAuthRestApiExceptionFilter
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
andSignInUpService
to use custom exceptions and improve input validation
19 file(s) reviewed, 13 comment(s)
Edit PR Review Bot Settings
...ages/twenty-server/src/engine/core-modules/auth/filters/auth-graphql-api-exception.filter.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/filters/auth-rest-api-exception.filter.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/guards/google-provider-enabled.guard.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/guards/microsoft-provider-enabled.guard.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/services/auth.service.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/services/token.service.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/services/token.service.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/services/token.service.ts
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/services/token.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/services/token.service.ts
Show resolved
Hide resolved
@@ -151,8 +137,6 @@ export class AuthResolver { | |||
verifyInput.loginToken, | |||
); | |||
|
|||
assert(email, 'Invalid token', ForbiddenException); |
There was a problem hiding this comment.
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'); | ||
} | ||
|
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
a7369af
to
764e8e2
Compare
packages/twenty-server/src/engine/core-modules/auth/services/auth.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/services/auth.service.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @thomtrp 👏
Adding exceptions and handler for auth services.
Tested with: