Skip to content

Commit

Permalink
fix: Navigation to page fails if user re-login is required (#2369)
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy authored Jan 25, 2023
1 parent 2e65067 commit 0db6f55
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
16 changes: 11 additions & 5 deletions Parse-Dashboard/Authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@ function initialize(app, options) {

app.post('/login',
csrf(),
passport.authenticate('local', {
successRedirect: `${self.mountPath}apps`,
failureRedirect: `${self.mountPath}login`,
failureFlash : true
})
(req,res,next) => {
let redirect = 'apps';
if (req.body.redirect) {
redirect = req.body.redirect.charAt(0) === '/' ? req.body.redirect.substring(1) : req.body.redirect
}
return passport.authenticate('local', {
successRedirect: `${self.mountPath}${redirect}`,
failureRedirect: `${self.mountPath}login${req.body.redirect ? `?redirect=${req.body.redirect}` : ''}`,
failureFlash : true
})(req, res, next)
},
);

app.get('/logout', function(req, res){
Expand Down
5 changes: 3 additions & 2 deletions Parse-Dashboard/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ module.exports = function(config, options) {
}

app.get('/login', csrf(), function(req, res) {
const redirectURL = req.url.includes('?redirect=') && req.url.split('?redirect=')[1];
if (!users || (req.user && req.user.isAuthenticated)) {
return res.redirect(`${mountPath}apps`);
return res.redirect(`${mountPath}${redirectURL || 'apps'}`);
}

let errors = req.flash('error');
Expand Down Expand Up @@ -206,7 +207,7 @@ module.exports = function(config, options) {
// For every other request, go to index.html. Let client-side handle the rest.
app.get('/*', function(req, res) {
if (users && (!req.user || !req.user.isAuthenticated)) {
return res.redirect(`${mountPath}login`);
return res.redirect(`${mountPath}login?redirect=${req.url.replace('/login', '')}`);
}
if (users && req.user && req.user.matchingUsername ) {
res.append('username', req.user.matchingUsername);
Expand Down
10 changes: 9 additions & 1 deletion src/login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ export default class Login extends React.Component {
}
}

const url = new URL(window.location);
const redirect = url.searchParams.get('redirect');
this.state = {
forgot: false,
username: sessionStorage.getItem('username') || '',
password: sessionStorage.getItem('password') || ''
password: sessionStorage.getItem('password') || '',
redirect
};
sessionStorage.clear();
setBasePath(props.path);
Expand Down Expand Up @@ -106,6 +109,11 @@ export default class Login extends React.Component {
ref={this.inputRefPass}
/>
} />
{this.state.redirect && <input
name='redirect'
type='hidden'
value={this.state.redirect}
/>}
{
this.errors && this.errors.includes('one-time') ?
<LoginRow
Expand Down

0 comments on commit 0db6f55

Please sign in to comment.