Skip to content

Commit

Permalink
Merge pull request #15 from shubham7822/adding-private-routes
Browse files Browse the repository at this point in the history
added private routes
  • Loading branch information
sajidrsk committed Mar 22, 2021
2 parents 6429b36 + 998ee50 commit 827e02c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import { RecipeContextProvider } from "./contexts/recipe-context";
import Home from "./containers/Home";
import Login from "./containers/Login";
import Signup from "./containers/Signup";
import PrivateRoute from "./PrivateRoutes";

function App() {
const response =false;
return (
<SnackbarProvider maxSnack={3} autoHideDuration={2000} preventDuplicate>
<AuthContextProvider>
<RecipeContextProvider>
<Router>
<Switch>
<Route exact path="/" component={Home} />
<PrivateRoute auth={response} exact path="/" component={Home} />
<Route exact path="/signup" component={Signup} />
<Route exact path="/login" component={Login} />
</Switch>
Expand Down
15 changes: 15 additions & 0 deletions src/PrivateRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from "react";
import { Route, Redirect } from "react-router-dom";

const PrivateRoute = ({ auth, component: Component, ...rest }) => {
return (
<Route
{...rest}
render={(props) => {
return auth ? <Component {...props} /> : <Redirect to="/login" />;
}}
/>
);
};

export default PrivateRoute;

0 comments on commit 827e02c

Please sign in to comment.