Fixed redirection after auth
parent
192d66ca6f
commit
40808f8a05
|
@ -20,14 +20,7 @@ module.exports = (app, passport) => {
|
|||
failureFlash: true
|
||||
},
|
||||
loginCallback = (req,res)=>{
|
||||
// Prevent redirect loop
|
||||
if (req.session.next.substring(0,7)==='/login#'){
|
||||
req.session.next = '#';
|
||||
res.redirect('/map');
|
||||
}
|
||||
else {
|
||||
res.redirect( req.session.next || '/map' );
|
||||
}
|
||||
res.redirect( req.session.next || '/map' );
|
||||
};
|
||||
|
||||
// Login/-out
|
||||
|
@ -45,13 +38,7 @@ module.exports = (app, passport) => {
|
|||
app.get('/logout', (req,res)=>{
|
||||
req.logout();
|
||||
req.flash('success',`You have been logged out.`);
|
||||
// Prevent redirect loop
|
||||
if (req.session.next.substring(0,8)==='/logout#') {
|
||||
req.session.next = '#';
|
||||
res.redirect('/');
|
||||
} else {
|
||||
res.redirect(req.session.next || '/');
|
||||
}
|
||||
res.redirect( req.session.next || '/' );
|
||||
});
|
||||
|
||||
// Signup
|
||||
|
|
|
@ -80,7 +80,10 @@ const
|
|||
app.get( '*', (req,res,next)=>{
|
||||
|
||||
// Path for redirects
|
||||
req.session.next = ( req.path.substring(0, req.path.indexOf('#')) || req.path )+'#';
|
||||
let nextPath = ( req.path.substring(0, req.path.indexOf('#')) || req.path );
|
||||
if ( nextPath!=='/login' && nextPath!=='/logout' ){
|
||||
req.session.next = nextPath+'#';
|
||||
}
|
||||
|
||||
// User account
|
||||
res.locals.user = req.user;
|
||||
|
|
Loading…
Reference in New Issue