Hi all,
I am trying to set up a node.js server with express for the backend authentication of my React App. On the front end I have an <a>
routing users to http://localhost:3001/login. My /login route runs fine and the user can login.
router.get('/login', passport.authenticate('auth0', {
scope: 'openid email profile'
}), (req, res) => {
res.redirect('/');
});
After login the user is routed to http://localhost:3000/callback?code=OXVrD51HyqKA&state=g6Fo2SBJM2RGNjc1FWdU8#
or some similar url with different query parameters. I don’t have a specified front-end route with “/callback” and I am assuming I don’t need one. It seems like my back-end “/callback” route should be running and rerouting me again but it is not.
router.get('/callback', function (req, res, next) {
console.log('called')
passport.authenticate('auth0', function (err, user, info) {
if (err) {
return next(err);
}
if (!user) {
return res.redirect('/login');
}
req.logIn(user, function (err) {
if (err) {
return next(err);
}
const returnTo = req.session.returnTo;
delete req.session.returnTo;
res.redirect(returnTo || '/user');
});
})(req, res, next);
});