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

Add Type Safety for GraphQL Error Extensions Code #9626

Closed
samyakpiya opened this issue Jan 15, 2025 · 1 comment
Closed

Add Type Safety for GraphQL Error Extensions Code #9626

samyakpiya opened this issue Jan 15, 2025 · 1 comment

Comments

@samyakpiya
Copy link
Contributor

References

This issues is a follow up from PR #9288. For more context, check this conversation.

Issue

Currently, there is no type-safe mechanism for handling GraphQL error extensions codes on the frontend. This creates a risk of runtime errors and makes the code harder to maintain.

Context

In the handleChallenge function, an error code (EMAIL_NOT_VERIFIED) from the backend is used to redirect users to the email verification page. However, the implementation lacks type safety. Adding type safety will help ensure consistency and prevent errors when checking these codes.

Relevant code snippet from the current implementation:

if (
  error instanceof ApolloError &&
  error.graphQLErrors[0]?.extensions?.code === 'EMAIL_NOT_VERIFIED'
) {
  setSearchParams({ email });
  setSignInUpStep(SignInUpStep.EmailVerification);
  throw error;
}

Proposed Solution

To address this, create a shared file to store error codes in the twenty-shared package. This will:

  • Ensure error codes are centrally defined and reusable.
  • Provide type safety for both frontend and backend when working with these codes.
@samyakpiya
Copy link
Contributor Author

Closing as this has been moved to the core team and is a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

No branches or pull requests

1 participant