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

Error is thrown on calling the route #82

Open
maheshambiga opened this issue Oct 3, 2017 · 1 comment
Open

Error is thrown on calling the route #82

maheshambiga opened this issue Oct 3, 2017 · 1 comment

Comments

@maheshambiga
Copy link

maheshambiga commented Oct 3, 2017

Getting below exception when passport route is hit,

Error
    at /Users/mambig/Downloads/angular2-node-fb-login-master/backend/node_modules/passport-facebook-token/lib/index.js:155:32
    at passBackControl (/Users/mambig/Downloads/angular2-node-fb-login-master/backend/node_modules/oauth/lib/oauth2.js:132:9)
    at IncomingMessage.<anonymous> (/Users/mambig/Downloads/angular2-node-fb-login-master/backend/node_modules/oauth/lib/oauth2.js:157:7)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:975:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

Express route config,

router.route('/auth/facebook').post(passport.authenticate('facebook-token', {session: false}), function(req, res, next) {
   
    if (!req.user) {
      return res.send(401, 'User Not Authenticated');
    }

    // prepare token for API
    req.auth = {
      id: req.user.id
    };

    next(); 
}, generateToken, sendToken);
@tomwagner
Copy link

You can use Express default error handler option (form Express doc: http://expressjs.com/en/guide/error-handling.html#the-default-error-handler ). And handle Oauth error something like this.

import { InternalOAuthError } from 'passport-oauth';
...
routes ...
...
app.use((err, req, res, next) => {
  if (err instanceof InternalOAuthError) {
    res.status(401).send({
      error: true,
      data: err.message
    });
  }
  next(err);
});

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

2 participants