Added login functionality and a redirect if not logged in
This commit is contained in:
parent
27e4d10b78
commit
8e67a91dc1
5 changed files with 54 additions and 5 deletions
18
frontend/src/auth/PrivateRoute.js
Normal file
18
frontend/src/auth/PrivateRoute.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Component } from "react";
|
||||
import { Redirect, Route } from "react-router-dom";
|
||||
import { useAuth } from "./AuthProvider";
|
||||
|
||||
const PrivateRoute = ({ component: Component, ...rest }) => {
|
||||
const [logged] = useAuth();
|
||||
|
||||
return (
|
||||
<Route
|
||||
{...rest}
|
||||
render={(props) =>
|
||||
logged ? <Component {...props} /> : <Redirect to="/login" />
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default PrivateRoute
|
Loading…
Add table
Add a link
Reference in a new issue