mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-10 01:16:39 +02:00
fix: update PR based on feedback
This commit is contained in:
parent
a47d53d0f4
commit
1796aeb3ea
@ -87,6 +87,7 @@ export const App = () => {
|
|||||||
path="/"
|
path="/"
|
||||||
unauthorized={isUnauthorized()}
|
unauthorized={isUnauthorized()}
|
||||||
component={Redirect}
|
component={Redirect}
|
||||||
|
renderProps={{ to: '/features' }}
|
||||||
/>
|
/>
|
||||||
{renderMainLayoutRoutes()}
|
{renderMainLayoutRoutes()}
|
||||||
{renderStandaloneRoutes()}
|
{renderStandaloneRoutes()}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Route, useLocation, useHistory } from 'react-router-dom';
|
import { Route, useLocation, Redirect } from 'react-router-dom';
|
||||||
|
|
||||||
const ProtectedRoute = ({
|
const ProtectedRoute = ({
|
||||||
component: Component,
|
component: Component,
|
||||||
@ -7,7 +7,6 @@ const ProtectedRoute = ({
|
|||||||
...rest
|
...rest
|
||||||
}) => {
|
}) => {
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
const history = useHistory();
|
|
||||||
const loginLink =
|
const loginLink =
|
||||||
pathname.length > 1 ? `/login?redirect=${pathname}` : '/login';
|
pathname.length > 1 ? `/login?redirect=${pathname}` : '/login';
|
||||||
return (
|
return (
|
||||||
@ -15,7 +14,7 @@ const ProtectedRoute = ({
|
|||||||
{...rest}
|
{...rest}
|
||||||
render={props => {
|
render={props => {
|
||||||
if (unauthorized) {
|
if (unauthorized) {
|
||||||
history.push(loginLink);
|
return <Redirect to={loginLink} />;
|
||||||
} else {
|
} else {
|
||||||
return <Component {...props} {...renderProps} />;
|
return <Component {...props} {...renderProps} />;
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,7 @@ const DemoAuth = ({ authDetails, redirect }) => {
|
|||||||
|
|
||||||
DemoAuth.propTypes = {
|
DemoAuth.propTypes = {
|
||||||
authDetails: PropTypes.object.isRequired,
|
authDetails: PropTypes.object.isRequired,
|
||||||
|
redirect: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DemoAuth;
|
export default DemoAuth;
|
||||||
|
@ -7,7 +7,7 @@ import { DEMO_TYPE } from '../../../constants/authTypes';
|
|||||||
import Authentication from '../Authentication/Authentication';
|
import Authentication from '../Authentication/Authentication';
|
||||||
import { useAuthDetails } from '../../../hooks/api/getters/useAuth/useAuthDetails';
|
import { useAuthDetails } from '../../../hooks/api/getters/useAuth/useAuthDetails';
|
||||||
import { useAuthUser } from '../../../hooks/api/getters/useAuth/useAuthUser';
|
import { useAuthUser } from '../../../hooks/api/getters/useAuth/useAuthUser';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { Redirect, useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
@ -15,11 +15,10 @@ const Login = () => {
|
|||||||
const { user } = useAuthUser();
|
const { user } = useAuthUser();
|
||||||
const query = useQueryParams();
|
const query = useQueryParams();
|
||||||
const resetPassword = query.get('reset') === 'true';
|
const resetPassword = query.get('reset') === 'true';
|
||||||
const redirect = query.get('redirect') || '/features';
|
const redirect = query.get('redirect') || '/';
|
||||||
const history = useHistory();
|
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
history.replace(redirect);
|
return <Redirect to={redirect} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user