From 508c41373ee58d6540a70cc4a54e839f459a3b54 Mon Sep 17 00:00:00 2001 From: jwu-fisker Date: Tue, 5 Jan 2021 17:31:10 -0800 Subject: [PATCH] Add Protected Routes --- src/components/Routes/ProtectedRoute.jsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/components/Routes/ProtectedRoute.jsx diff --git a/src/components/Routes/ProtectedRoute.jsx b/src/components/Routes/ProtectedRoute.jsx new file mode 100644 index 0000000..0779a8b --- /dev/null +++ b/src/components/Routes/ProtectedRoute.jsx @@ -0,0 +1,12 @@ +import React from 'react'; +import { Redirect, Route } from 'react-router-dom'; +import { useUserContext } from '../Contexts/UserContext'; + +export const ProtectedRoute = ({ render, ...others }) => { + const { user, setError } = useUserContext(); + if (!user || !user.sub || user.sub.length === 0) { + setError('Please sign in to access'); + return ; + } + return ; +} \ No newline at end of file