Skip to content

Commit 0db6f55

Browse files
authored
fix: Navigation to page fails if user re-login is required (#2369)
1 parent 2e65067 commit 0db6f55

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

Parse-Dashboard/Authentication.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,17 @@ function initialize(app, options) {
6767

6868
app.post('/login',
6969
csrf(),
70-
passport.authenticate('local', {
71-
successRedirect: `${self.mountPath}apps`,
72-
failureRedirect: `${self.mountPath}login`,
73-
failureFlash : true
74-
})
70+
(req,res,next) => {
71+
let redirect = 'apps';
72+
if (req.body.redirect) {
73+
redirect = req.body.redirect.charAt(0) === '/' ? req.body.redirect.substring(1) : req.body.redirect
74+
}
75+
return passport.authenticate('local', {
76+
successRedirect: `${self.mountPath}${redirect}`,
77+
failureRedirect: `${self.mountPath}login${req.body.redirect ? `?redirect=${req.body.redirect}` : ''}`,
78+
failureFlash : true
79+
})(req, res, next)
80+
},
7581
);
7682

7783
app.get('/logout', function(req, res){

Parse-Dashboard/app.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ module.exports = function(config, options) {
173173
}
174174

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

180181
let errors = req.flash('error');
@@ -206,7 +207,7 @@ module.exports = function(config, options) {
206207
// For every other request, go to index.html. Let client-side handle the rest.
207208
app.get('/*', function(req, res) {
208209
if (users && (!req.user || !req.user.isAuthenticated)) {
209-
return res.redirect(`${mountPath}login`);
210+
return res.redirect(`${mountPath}login?redirect=${req.url.replace('/login', '')}`);
210211
}
211212
if (users && req.user && req.user.matchingUsername ) {
212213
res.append('username', req.user.matchingUsername);

src/login/Login.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ export default class Login extends React.Component {
2828
}
2929
}
3030

31+
const url = new URL(window.location);
32+
const redirect = url.searchParams.get('redirect');
3133
this.state = {
3234
forgot: false,
3335
username: sessionStorage.getItem('username') || '',
34-
password: sessionStorage.getItem('password') || ''
36+
password: sessionStorage.getItem('password') || '',
37+
redirect
3538
};
3639
sessionStorage.clear();
3740
setBasePath(props.path);
@@ -106,6 +109,11 @@ export default class Login extends React.Component {
106109
ref={this.inputRefPass}
107110
/>
108111
} />
112+
{this.state.redirect && <input
113+
name='redirect'
114+
type='hidden'
115+
value={this.state.redirect}
116+
/>}
109117
{
110118
this.errors && this.errors.includes('one-time') ?
111119
<LoginRow

0 commit comments

Comments
 (0)