Created
June 18, 2019 11:45
-
-
Save DubiousS/847910e1ae004f7923fd36f6331385a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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