PromucFlow_constructor/app/client/src/pages/common/ProtectedRoute.tsx

16 lines
519 B
TypeScript
Raw Normal View History

2019-09-02 14:50:01 +00:00
import * as React from "react"
import _ from "lodash"
import { Route, Redirect } from "react-router-dom";
2019-09-02 15:36:24 +00:00
import netlifyIdentity from 'netlify-identity-widget';
2019-09-02 14:50:01 +00:00
const ProtectedRoute = ({ path: path, component: Component, ...rest }: { path: string, component: React.ReactType }) => {
2019-09-05 17:47:50 +00:00
// let windowDoc: any = window
2019-09-02 14:50:01 +00:00
return (<Route {...rest} render={(props) => (
2019-09-02 15:36:24 +00:00
!_.isNil(netlifyIdentity.currentUser())
2019-09-02 14:50:01 +00:00
? <Component {...props} />
: <Redirect to={"/login"} />
)} />)
}
export default ProtectedRoute