Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passport.authenticate('local', { successReturnToOrRedirect: '/'}) not working properly #919

Open
Evalife opened this issue Jul 7, 2022 · 5 comments

Comments

@Evalife
Copy link

Evalife commented Jul 7, 2022

const router = require('express').Router()
const User = require('../models/user.model')
const { body, validationResult } = require('express-validator')
const passport = require('passport')

router.get('/login', ensureNotAuthenticated, async(req, res, next) => {
res.render('login')
})
router.post('/login', ensureNotAuthenticated,
passport.authenticate('local', {
successReturnToOrRedirect: '/',
failureRedirect: "/auth/login",
failureFlash: true
}))

if for example a user tries to access a protected route, say 'auth/profile', he gets redirected to the log in page, but on successfully logging in, he gets redirected to the route specified in 'successReturnToOrRedirect'. I was using passport 0.4.1 and there, it redirected back to the previous protected route after the user has successfully logged in

@Neil188
Copy link

Neil188 commented Jul 11, 2022

Having the same problem since updating from v0.5.3. I believe this is down to change a77271f55f045bd4fd2578a953256406b3621721 - authentice.js uses req.session.returnTo to redirect back to whatever page the user was visiting. But now sessionmanager.js is using req.session.regenerate - resulting in the returnTo property being lost, hence no redirect.

A workaround is to use options.keepSessionInfo to retain the session info:

passport.authenticate('oauth2', {
   successReturnToOrRedirect: '/home',
   failureRedirect: '/sign-in',
   keepSessionInfo: true
})

though this feels like it defeats the purpose of regenerating the session, when all we want to keep is the returnTo value.

Plus, if you are using Typescript keepSessionInfo isn't included in @types/passport

@ashishth09
Copy link

We tried moving to 0.6.0 to receive vulnerability fixes but hit with this issue. Since the PR is all ready can we expect a release

@sbsamaro
Copy link

sbsamaro commented Aug 22, 2022

@Evalife @ashishth09 Did this solve your issue? i added keepsessioninfo to the config and its still having the same behavior

@ashishth09
Copy link

@sbsamaro no it didn't solve for me either

@brookback
Copy link

Same problem. Hope #941 could fix this.

SISheogorath added a commit to SISheogorath/codimd-server that referenced this issue Jul 19, 2023
This patch should fix the broken redirect behaviour of the
authentication provider where users aren't redirected back to the note
they were send off, due to passport forgetting its session.

Reference:
jaredhanson/passport#919
SISheogorath added a commit to SISheogorath/codimd-server that referenced this issue Jul 19, 2023
This patch should fix the broken redirect behaviour of the
authentication provider where users aren't redirected back to the note
they were send off, due to passport forgetting its session.

Reference:
jaredhanson/passport#919

Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants