I am using Nuxt.js with Passport and connect-redis to manage sessions When user logs in, I want to take them back to the page they came from after Login I added this middleware but it doesnt seem to work

app.use((req, res, next) => { // After successful login, redirect back to the intended page if (!req.user && req.path !== '/login' && req.path !== '/signup' && !req.path.match(/^\/auth/) && !req.path.match(/\./)) { req.session.returnTo = req.originalUrl; } else if (req.user && (req.path === '/account' || req.path.match(/^\/api/))) { req.session.returnTo = req.originalUrl; } next(); }); app.get('/auth/google', passport.authenticate('google', { scope: ['profile', 'email', 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/spreadsheets.readonly'], accessType: 'offline', prompt: 'consent' })); app.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '/login' }), (req, res) => { res.redirect(req.session.returnTo || '/'); });

req.session.returnTo seems to be undefined using the above middleware