Skip to content

Instantly share code, notes, and snippets.

@DubiousS
Created June 18, 2019 11:45
Show Gist options
  • Save DubiousS/847910e1ae004f7923fd36f6331385a9 to your computer and use it in GitHub Desktop.
Save DubiousS/847910e1ae004f7923fd36f6331385a9 to your computer and use it in GitHub Desktop.
import React from 'react';
import PropTypes from 'prop-types';
import { Redirect, Route } from 'react-router-dom';
import { Routes } from 'common/constants';
/* The component draws pages for authentication, if the user is not authorized.
Otherwise, it redirects to the main page.
*/
const AuthLayoutComponent = ({
component: Component,
isAuthenticated,
path,
...restProps
}) => isAuthenticated
? <Redirect to={Routes.FEED} />
: (
<Route
{...restProps}
path={path}
render={props => <Component {...props} />}
/>
);
AuthLayoutComponent.propTypes = {
component: PropTypes.oneOfType([
PropTypes.node,
PropTypes.func,
]).isRequired,
isAuthenticated: PropTypes.bool.isRequired,
path: PropTypes.string.isRequired,
};
export default AuthLayoutComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment