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

Application crash if register fails #8

Open
oslo10e opened this issue Oct 15, 2017 · 3 comments
Open

Application crash if register fails #8

oslo10e opened this issue Oct 15, 2017 · 3 comments

Comments

@oslo10e
Copy link

oslo10e commented Oct 15, 2017

STR:
POST: http://localhost:4040/auth/register
payload:

{
"email": "a@b.c",
"password": "def"
}

then do the same a second time

Observe log in terminal:

_http_outgoing.js:359
    throw new Error('Can\'t set headers after they are sent.');
    ^

Error: Can't set headers after they are sent.
    at ServerResponse.setHeader (_http_outgoing.js:359:11)
    at ServerResponse.header (/Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/node_modules/express/lib/response.js:719:10)
    at ServerResponse.send (/Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/node_modules/express/lib/response.js:164:12)
    at ServerResponse.json (/Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/node_modules/express/lib/response.js:250:15)
    at /Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/src/server/controllers/auth.controller.js:31:11
    at /Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/node_modules/passport/lib/middleware/authenticate.js:236:29
    at /Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/node_modules/passport/lib/http/request.js:51:48
    at pass (/Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/node_modules/passport/lib/authenticator.js:287:14)
    at Authenticator.serializeUser (/Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/node_modules/passport/lib/authenticator.js:289:5)
    at IncomingMessage.req.login.req.logIn (/Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/node_modules/passport/lib/http/request.js:50:29)
    at Strategy.strategy.success (/Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/node_modules/passport/lib/middleware/authenticate.js:235:13)
    at verified (/Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/node_modules/passport-local/lib/strategy.js:83:10)
    at InternalFieldObject.ondone (/Users/opeaucelle/Sites/test/es6-express-mongoose-passport-rest-api/node_modules/passport-local-mongoose/index.js:152:16)
[nodemon] app crashed - waiting for file changes before starting...
@oslo10e
Copy link
Author

oslo10e commented Oct 15, 2017

it could be fixed by adding return in auth.controller.js

    if (err) {
      const error = new APIError('Authentication error', httpStatus.UNAUTHORIZED)
      next(error)
      return
    }

@tutts
Copy link
Owner

tutts commented Oct 15, 2017

Hi @oslo10e, thanks for reporting! Will take a look in the morning and see whats up, will post PR shortly :)

@ssurabhi10
Copy link

You are sending two response to client. Send only one response to client. If error happens, send error response and if there is success then send success response.

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