This might be an issue with my understanding of how passport js is handling sessions, but the docs doesn't seem to help...
I have a sign up button in my frontend that redirects to {{backend_api}}/auth/google?action=signup , that endpoint handles google authentication this way:
router.get(
'/google',
(req, _res, next) => {
console.log('req.session 1st mdlw: ', req.session);
if (typeof req.query.redirect === 'string') {
/**
* Passport will redirect to this route upon successfully logging in due to us setting `successReturnToOrRedirect` below.
*/
req.session.returnTo = req.query.redirect;
}
if (typeof req.query.action === 'string') {
// Store the action in the session,
// we do this in order to identify if the user is trying to login or signup
req.session.action = req.query.action;
}
return next();
},
passport.authenticate('google', {
scope: ['profile', 'email'],
prompt: 'consent',
session: true,
})
);
router.get('/google/callback', (req, res, next) => {
console.log('req.session 2nd mdlw: ', req.session);
passport.authenticate('google', {
successReturnToOrRedirect: `${frontend_url}?action=${req.session.action}`,
failureRedirect: '/login',
session: true,
})(req, res, next);
});
after the google authorization succeeds, passportjs is redirecting me to {{frontend_url}}/action=undefined , and I need that value to redirect my user to different routes of my app depending on the action, i.e sign-in or sign-up.
I would appreciate some lights here, and I apologize in advance if this is not the correct way to do it.
to receive the value 'signin' or 'signup' depending on the user's action when using google oauth, in order to redirect him to a setup page if he's signing up, or to the dashboard if he's logging in.