diff --git a/frontend/src/LoginPage/LoginPage.jsx b/frontend/src/LoginPage/LoginPage.jsx index e0a841df8f..d6b9694a8b 100644 --- a/frontend/src/LoginPage/LoginPage.jsx +++ b/frontend/src/LoginPage/LoginPage.jsx @@ -2,6 +2,7 @@ import React from 'react'; import { authenticationService } from '@/_services'; import { toast } from 'react-toastify'; import { Link } from 'react-router-dom'; +import queryString from 'query-string'; class LoginPage extends React.Component { constructor(props) { @@ -30,7 +31,8 @@ class LoginPage extends React.Component { authenticationService.login(email, password).then( () => { - const { from } = this.props.location.state || { from: { pathname: '/' } }; + const params = queryString.parse(this.props.location.search) + const { from } = params.redirectTo ? { from: { pathname: params.redirectTo } } : { from: { pathname: '/' } }; this.props.history.push(from); this.setState({ isLoading: false }); }, diff --git a/frontend/src/_components/PrivateRoute.jsx b/frontend/src/_components/PrivateRoute.jsx index 9f06b30d1d..e34fcf6d1d 100644 --- a/frontend/src/_components/PrivateRoute.jsx +++ b/frontend/src/_components/PrivateRoute.jsx @@ -10,7 +10,8 @@ export const PrivateRoute = ({ component: Component, switchDarkMode, darkMode, . const currentUser = authenticationService.currentUserValue; if (!currentUser && !props.location.pathname.startsWith('/applications/')) { // not logged in so redirect to login page with the return url - return ; + return ; } // authorised so return component diff --git a/frontend/src/_services/authentication.service.js b/frontend/src/_services/authentication.service.js index 5d2b5dcaab..4d1c10c5b2 100644 --- a/frontend/src/_services/authentication.service.js +++ b/frontend/src/_services/authentication.service.js @@ -57,5 +57,5 @@ function logout() { // remove user from local storage to log user out localStorage.removeItem('currentUser'); currentUserSubject.next(null); - history.push('/login'); + history.push(`/login?redirectTo=${window.location.pathname}`); }