mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 08:58:26 +00:00
Login redirection (#712)
Co-authored-by: navaneeth <navaneethpk@outlook.com>
This commit is contained in:
parent
980198c4fb
commit
9682a82d4b
3 changed files with 6 additions and 3 deletions
|
|
@ -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 });
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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 <Redirect to={{ pathname: '/login', state: { from: props.location } }} />;
|
||||
return <Redirect
|
||||
to={{ pathname: '/login', search: `?redirectTo=${props.location.pathname}`, state: { from: props.location } }} />;
|
||||
}
|
||||
|
||||
// authorised so return component
|
||||
|
|
|
|||
|
|
@ -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}`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue