mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
feat: add redirect params to /login
This commit is contained in:
parent
f466a78193
commit
bcbfd3e38c
@ -41,7 +41,6 @@ export const App = () => {
|
|||||||
const renderRoute = (route: any) => {
|
const renderRoute = (route: any) => {
|
||||||
if (route.type === 'protected') {
|
if (route.type === 'protected') {
|
||||||
const unauthorized = isUnauthorized();
|
const unauthorized = isUnauthorized();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ProtectedRoute
|
<ProtectedRoute
|
||||||
key={route.path}
|
key={route.path}
|
||||||
@ -88,7 +87,6 @@ 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, Redirect } from 'react-router-dom';
|
import { Route, useLocation, useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
const ProtectedRoute = ({
|
const ProtectedRoute = ({
|
||||||
component: Component,
|
component: Component,
|
||||||
@ -6,12 +6,16 @@ const ProtectedRoute = ({
|
|||||||
renderProps = {},
|
renderProps = {},
|
||||||
...rest
|
...rest
|
||||||
}) => {
|
}) => {
|
||||||
|
const { pathname } = useLocation();
|
||||||
|
const history = useHistory();
|
||||||
|
const loginLink =
|
||||||
|
pathname.length > 1 ? `/login?redirect=${pathname}` : '/login';
|
||||||
return (
|
return (
|
||||||
<Route
|
<Route
|
||||||
{...rest}
|
{...rest}
|
||||||
render={props => {
|
render={props => {
|
||||||
if (unauthorized) {
|
if (unauthorized) {
|
||||||
return <Redirect to={'/login'} />;
|
history.push(loginLink);
|
||||||
} else {
|
} else {
|
||||||
return <Component {...props} {...renderProps} />;
|
return <Component {...props} {...renderProps} />;
|
||||||
}
|
}
|
||||||
|
@ -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 { Redirect } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
@ -15,9 +15,13 @@ 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 history = useHistory();
|
||||||
|
console.log(redirect);
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
return <Redirect to="/features" />;
|
console.log(redirect);
|
||||||
|
history.push(redirect);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user