Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michaelfreund/edc147f1abefb39753496856306aa076 to your computer and use it in GitHub Desktop.
Save michaelfreund/edc147f1abefb39753496856306aa076 to your computer and use it in GitHub Desktop.
LoopBack Component Passport Local Auth Strategy Custom Callback
const Passport = require('passport');
const PassportProviders = require('../providers.json');
const LocalPassportConfig = PassportProviders['local'];
LocalPassportConfig.customCallback = function (req, res, next) {
Passport.authenticate('local', {}, function (err, user, info) {
if (err) {
return res.status(500).json(err); // log internals - do not expose them
}
if (!user) {
return res.status(401).json({ error: 'unauthorized' });
}
res.json({ accessToken: info.accessToken.id, userId: user.id });
})(req, res, next);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment