Skip to content

Instantly share code, notes, and snippets.

@Y-Taras
Created May 19, 2017 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Y-Taras/bfb84c7bf27656bbc2cb6d9c7dee454c to your computer and use it in GitHub Desktop.
Save Y-Taras/bfb84c7bf27656bbc2cb6d9c7dee454c to your computer and use it in GitHub Desktop.
import React, { PropTypes } from 'react';
import { Route, Redirect } from 'react-router-dom';
const Authenticated = ({ loggingIn, authenticated, component, ...rest }) => (
<Route {...rest} render={(props) => {
if (loggingIn) return <div></div>;
return authenticated ?
(React.createElement(component, { ...props, loggingIn, authenticated })) :
(<Redirect to="/login" />);
}} />
);
Authenticated.propTypes = {
loggingIn: PropTypes.bool,
authenticated: PropTypes.bool,
component: PropTypes.func,
};
export default Authenticated;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment