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

Cannot set headers after they are sent to the client #36

Closed
dmitrijs-pavlovs-dev opened this issue Jul 9, 2020 · 2 comments
Closed

Comments

@dmitrijs-pavlovs-dev
Copy link

Hello i have this code in my resolver

  @ResolveField(() => Account)
  async login(
    @Args("input") { service, params }: LoginInput,
    @Context() context: any
  ): Promise<Account> {
    const auth = await context.authenticate("graphql-local", {
      email: params.email,
      password: params.password,
    });
    context.login(auth.user);
    return {
      id: auth.user.id,
      user: auth.user,
    };
  }

I receive and error when i try to login the user. The error disappears when i remove context.login(auth.user) function.

(node:432) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

at ServerResponse.setHeader (_http_outgoing.js:518:11)

at ServerResponse.header (/ftw/node_modules/express/lib/response.js:771:10)

at ServerResponse.send (/ftw/node_modules/express/lib/response.js:170:12)

at ServerResponse.json (/ftw/node_modules/express/lib/response.js:267:15)

at ExpressAdapter.reply (/ftw/node_modules/@nestjs/platform-express/adapters/express-adapter.js:24:57)

at ExceptionsHandler.handleUnknownError (/ftw/node_modules/@nestjs/core/exceptions/base-exception-filter.js:33:24)

at ExceptionsHandler.catch (/ftw/node_modules/@nestjs/core/exceptions/base-exception-filter.js:17:25)

at ExceptionsHandler.next (/ftw/node_modules/@nestjs/core/exceptions/exceptions-handler.js:16:20)

at /ftw/node_modules/@nestjs/core/router/router-proxy.js:24:35

at Layer.handle_error (/ftw/node_modules/express/lib/router/layer.js:71:5)

at trim_prefix (/ftw/node_modules/express/lib/router/index.js:315:13)

at /ftw/node_modules/express/lib/router/index.js:284:7

at Function.process_params (/ftw/node_modules/express/lib/router/index.js:335:12)

at next (/ftw/node_modules/express/lib/router/index.js:275:10)

at Layer.handle_error (/ftw/node_modules/express/lib/router/layer.js:67:12)

at trim_prefix (/ftw/node_modules/express/lib/router/index.js:315:13)

(node:432) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

(node:432) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

What might cause the error ?

@jkettmann
Copy link
Collaborator

Thanks for the issue. I can't really tell from the code above. Do you use express-session? If not you can simply remove that line. Otherwise, could you provide the source code or reproduce the issue in a codesandbox?

@gforge
Copy link
Collaborator

gforge commented Aug 27, 2021

This is most likely an issue with something sending a header ahead of time: https://stackoverflow.com/questions/7042340/error-cant-set-headers-after-they-are-sent-to-the-client

@gforge gforge closed this as completed Aug 27, 2021
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

No branches or pull requests

3 participants