Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
notificationsLoading: boolean;
loggedIn: boolean;
isMounted: false;
user: {data: any, status: any};
}
const Loader = Loadable({
...loadableDefaults,
loader: () => import('./common/PageLoading'),
});
const UserIsAuthenticated = connectedReduxRedirect({
authenticatedSelector: (state: State) => !!state.user.data,
authenticatingSelector: (state: State) => state.user.status.isLoading ,
AuthenticatingComponent: Loader,
redirectAction: routerActions.replace,
wrapperDisplayName: 'UserIsAuthenticated',
redirectPath: '/login',
});
const UserIsNotAuthenticated = connectedReduxRedirect({
redirectAction: routerActions.replace,
wrapperDisplayName: 'UserIsNotAuthenticated',
authenticatedSelector: (state: State) => {
const checked = !state.user.data && state.user.status.isLoading === false;
return checked;
},
redirectPath: (state, ownProps: RouteComponentProps<{}, {}>) => {
const {redirect, next} = queryString.parse(ownProps.location.search);
return (redirect || next) || '/dashboard';
},
allowRedirectBack: false,
const LoginGuard = (Component: ComponentType) =>
connectedReduxRedirect({
allowRedirectBack: false,
authenticatedSelector: state => !selectIsLoggedIn(state),
authenticatingSelector: selectIsAuthenticating,
redirectAction: routerActions.replace,
redirectPath: (_, props) => locationHelper.getRedirectQueryParam(props) || rootPath,
wrapperDisplayName: 'LoginGuard',
})(Component);
const IsLoggedIn = (Component: ComponentType) =>
connectedReduxRedirect({
authenticatedSelector: selectIsLoggedIn,
authenticatingSelector: selectIsAuthenticating,
redirectAction: routerActions.replace,
redirectPath: AUTH_ROUTER_PATHS.login,
wrapperDisplayName: 'IsLoggedIn',
})(Component);
const LogoutGuard = (Component: ComponentType) =>
connectedReduxRedirect({
allowRedirectBack: false,
authenticatedSelector: selectIsLoggedIn,
authenticatingSelector: selectIsAuthenticating,
redirectAction: routerActions.replace,
redirectPath: AUTH_ROUTER_PATHS.login,
wrapperDisplayName: 'LogoutGuard',
})(Component);
const Loader = Loadable({
...loadableDefaults,
loader: () => import('./common/PageLoading'),
});
const UserIsAuthenticated = connectedReduxRedirect({
authenticatedSelector: (state: State) => !!state.user.data,
authenticatingSelector: (state: State) => state.user.status.isLoading ,
AuthenticatingComponent: Loader,
redirectAction: routerActions.replace,
wrapperDisplayName: 'UserIsAuthenticated',
redirectPath: '/login',
});
const UserIsNotAuthenticated = connectedReduxRedirect({
redirectAction: routerActions.replace,
wrapperDisplayName: 'UserIsNotAuthenticated',
authenticatedSelector: (state: State) => {
const checked = !state.user.data && state.user.status.isLoading === false;
return checked;
},
redirectPath: (state, ownProps: RouteComponentProps<{}, {}>) => {
const {redirect, next} = queryString.parse(ownProps.location.search);
return (redirect || next) || '/dashboard';
},
allowRedirectBack: false,
});
const UserCanViewErrorPage = connectedReduxRedirect({
redirectAction: routerActions.replace,
wrapperDisplayName: 'UserIsNotAuthenticated',
authenticatedSelector: (state: State) => {
const IsAnonymous = (Component: ComponentType) =>
connectedReduxRedirect({
allowRedirectBack: false,
authenticatedSelector: state => !selectIsLoggedIn(state),
authenticatingSelector: selectIsAuthenticating,
redirectAction: routerActions.replace,
redirectPath: rootPath,
wrapperDisplayName: 'IsAnonymous',
})(Component);