Skip to content

Commit

Permalink
feat: add PrivateRoute utils
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppemilicia committed Dec 17, 2022
1 parent b3b5c59 commit 852c5c0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils/PrivateRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import {Navigate} from 'react-router-dom';
import {useSelector} from "react-redux";
import {userSelector} from "../slice/userSlice";

const PrivateRoute = ({ children }) => {
const { user } = useSelector(userSelector);

return user ? children: <Navigate to="/" replace />;
};

export default PrivateRoute;

0 comments on commit 852c5c0

Please sign in to comment.