Created
September 15, 2017 06:45
-
-
Save michaelfreund/edc147f1abefb39753496856306aa076 to your computer and use it in GitHub Desktop.
LoopBack Component Passport Local Auth Strategy Custom Callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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