1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

fix: update PR based on feedback

This commit is contained in:
Youssef 2022-02-21 16:24:07 +01:00
parent a47d53d0f4
commit 1796aeb3ea
4 changed files with 7 additions and 7 deletions

View File

@ -87,6 +87,7 @@ export const App = () => {
path="/"
unauthorized={isUnauthorized()}
component={Redirect}
renderProps={{ to: '/features' }}
/>
{renderMainLayoutRoutes()}
{renderStandaloneRoutes()}

View File

@ -1,4 +1,4 @@
import { Route, useLocation, useHistory } from 'react-router-dom';
import { Route, useLocation, Redirect } from 'react-router-dom';
const ProtectedRoute = ({
component: Component,
@ -7,7 +7,6 @@ const ProtectedRoute = ({
...rest
}) => {
const { pathname } = useLocation();
const history = useHistory();
const loginLink =
pathname.length > 1 ? `/login?redirect=${pathname}` : '/login';
return (
@ -15,7 +14,7 @@ const ProtectedRoute = ({
{...rest}
render={props => {
if (unauthorized) {
history.push(loginLink);
return <Redirect to={loginLink} />;
} else {
return <Component {...props} {...renderProps} />;
}

View File

@ -90,6 +90,7 @@ const DemoAuth = ({ authDetails, redirect }) => {
DemoAuth.propTypes = {
authDetails: PropTypes.object.isRequired,
redirect: PropTypes.string.isRequired,
};
export default DemoAuth;

View File

@ -7,7 +7,7 @@ import { DEMO_TYPE } from '../../../constants/authTypes';
import Authentication from '../Authentication/Authentication';
import { useAuthDetails } from '../../../hooks/api/getters/useAuth/useAuthDetails';
import { useAuthUser } from '../../../hooks/api/getters/useAuth/useAuthUser';
import { useHistory } from 'react-router-dom';
import { Redirect, useHistory } from 'react-router-dom';
const Login = () => {
const styles = useStyles();
@ -15,11 +15,10 @@ const Login = () => {
const { user } = useAuthUser();
const query = useQueryParams();
const resetPassword = query.get('reset') === 'true';
const redirect = query.get('redirect') || '/features';
const history = useHistory();
const redirect = query.get('redirect') || '/';
if (user) {
history.replace(redirect);
return <Redirect to={redirect} />;
}
return (