Add Protected Routes

This commit is contained in:
jwu-fisker
2021-01-05 17:31:10 -08:00
parent 378d00b220
commit 508c41373e

View File

@@ -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 <Redirect to="/" />;
}
return <Route render {...others} />;
}