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

useAuth0 causes internal server error #606

Closed
taneba opened this issue Aug 24, 2021 · 3 comments
Closed

useAuth0 causes internal server error #606

taneba opened this issue Aug 24, 2021 · 3 comments
Assignees
Labels
kind/bug Something isn't working

Comments

@taneba
Copy link
Contributor

taneba commented Aug 24, 2021

Hi, i'm really enjoying using envelop.
Thank you for creating great libraries.

Describe the bug

I set up envelop with useAuth0 and if I make a request without authorization header, it causes internal server error and the http status code will be 500.

To Reproduce

Make envelop setup below and serve it in the same way of graphql-helix example.

const getEnveloped = envelop({
  plugins: [
    useSchema(executableSchema),
    useExtendContext(createContext),
    useLogger(),
    useAuth0({
      onError: (e: any) => {
        throw new EnvelopError('request not authenticated', {
          code: 'NOT_AUTHENTICATED',
        })
      },
      domain: process.env.AUTH0_DOMAIN!,
      audience: process.env.AUTH0_AUDIENCE!,
      headerName: 'authorization',
      preventUnauthenticatedAccess: true,
      extendContextField: 'auth0',
      tokenType: 'Bearer',
    }),
    useMaskedErrors(),
    useErrorHandler((error: any) => {
      console.log('ERROR: ' + JSON.stringify(error))
    }),
    useTiming(),
    useDepthLimit({
      maxDepth: 10,
    }),
  ],
})

Expected behavior

I think it should be caught internally and server should send back with http status 200.

Environment:

  • @envelop/core@1.0.3:
  • @envelop/auth0@1.0.0
  • NodeJS: 14.16.0
@taneba
Copy link
Contributor Author

taneba commented Aug 24, 2021

This is because graphql-helix handles it as 500 error when OnContextBuildingHook throws an error.
https://github.com/contrawork/graphql-helix/blob/master/packages/core/lib/process-request.ts#L310
I'm not sure if it is correct or not, but I think it's not common to handle 500 in graphql client. And that being said, onError option of useAuth0 occasionally wouldn't work as expected.

@taneba
Copy link
Contributor Author

taneba commented Sep 23, 2021

@dotansimha
Hey, thank you for handling this issue :)
As this is related to graphql-helix, this issue can be closed after the next version of graphql-helix is released (not yet, right?).

@taneba
Copy link
Contributor Author

taneba commented Sep 24, 2021

close this as it is solved in graphql-helix 1.8.0

@taneba taneba closed this as completed Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants