added protecrted routes and login page
This commit is contained in:
parent
bf69b401e7
commit
588db871ee
|
|
@ -4,7 +4,8 @@ import { Provider } from "react-redux";
|
|||
import "./index.css";
|
||||
import App from "./App";
|
||||
import Editor from "./pages/Editor";
|
||||
import PageNotFound from "./pages/PageNotFound";
|
||||
import PageNotFound from "./pages/common/PageNotFound";
|
||||
import LoginPage from "./pages/common/LoginPage";
|
||||
import * as serviceWorker from "./serviceWorker";
|
||||
import { BrowserRouter, Route, Switch } from "react-router-dom";
|
||||
import { createStore, applyMiddleware } from "redux";
|
||||
|
|
@ -14,6 +15,7 @@ import { ThemeProvider, theme } from "./constants/DefaultTheme";
|
|||
import createSagaMiddleware from 'redux-saga'
|
||||
import { rootSaga } from "./sagas"
|
||||
import { appInitializer } from "./utils/AppsmithUtils";
|
||||
import ProtectedRoute from "./pages/common/ProtectedRoute";
|
||||
|
||||
appInitializer()
|
||||
WidgetBuilderRegistry.registerWidgetBuilders();
|
||||
|
|
@ -26,7 +28,8 @@ ReactDOM.render(
|
|||
<BrowserRouter>
|
||||
<Switch>
|
||||
<Route exact path="/" component={App} />
|
||||
<Route exact path="/builder" component={Editor} />
|
||||
<ProtectedRoute path="/builder" component={Editor} />
|
||||
<Route exact path="/login" component={LoginPage} />
|
||||
<Route component={PageNotFound} />
|
||||
</Switch>
|
||||
</BrowserRouter>
|
||||
|
|
|
|||
23
app/client/src/pages/common/LoginPage.tsx
Normal file
23
app/client/src/pages/common/LoginPage.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import * as React from "react"
|
||||
|
||||
import { Card, Elevation } from "@blueprintjs/core"
|
||||
import { RouterProps } from "react-router";
|
||||
|
||||
class LoginPage extends React.PureComponent<RouterProps> {
|
||||
|
||||
componentDidMount() {
|
||||
let windowDoc: any = window
|
||||
windowDoc.netlifyIdentity.open();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div style={{ textAlign: "center" }}>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default LoginPage
|
||||
|
||||
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
import * as React from "react"
|
||||
|
||||
import { NonIdealState, Button, Card, Elevation } from "@blueprintjs/core"
|
||||
import App from "../App";
|
||||
import { RouterProps } from "react-router";
|
||||
|
||||
class PageNotFound extends React.PureComponent<RouterProps> {
|
||||
14
app/client/src/pages/common/ProtectedRoute.tsx
Normal file
14
app/client/src/pages/common/ProtectedRoute.tsx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import * as React from "react"
|
||||
import _ from "lodash"
|
||||
import { Route, Redirect } from "react-router-dom";
|
||||
|
||||
const ProtectedRoute = ({ path: path, component: Component, ...rest }: { path: string, component: React.ReactType }) => {
|
||||
let windowDoc: any = window
|
||||
return (<Route {...rest} render={(props) => (
|
||||
!_.isNil(windowDoc.netlifyIdentity.currentUser())
|
||||
? <Component {...props} />
|
||||
: <Redirect to={"/login"} />
|
||||
)} />)
|
||||
}
|
||||
|
||||
export default ProtectedRoute
|
||||
Loading…
Reference in New Issue
Block a user