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

29 lines
548 B
TypeScript
Raw Normal View History

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