From 84b45cd6b11347e66437cd92dc20372d0abd6eb9 Mon Sep 17 00:00:00 2001
From: Joseph Ditton <jditton.atomic@gmail.com>
Date: Wed, 1 Dec 2021 20:18:26 -0700
Subject: adds roles

---
 client/app.jsx | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

(limited to 'client/app.jsx')

diff --git a/client/app.jsx b/client/app.jsx
index e1e4c03..90ceb37 100644
--- a/client/app.jsx
+++ b/client/app.jsx
@@ -6,6 +6,8 @@ import { AuthContext } from './utils/auth_context';
 import { useApi } from './utils/use_api';
 import { useJwtRefresh } from './utils/use_jwt_refresh';
 import './app.css';
+import { RolesContext } from './utils/roles_context';
+import { parseJwt } from './utils/parse_jwt';
 
 export const App = () => {
   const [authToken, setAuthToken] = useState(null);
@@ -26,16 +28,21 @@ export const App = () => {
     setLoading(false);
   }, []);
 
-  // before displaying anything try getting a token using cookies,
+  const jwtPayload = parseJwt(authToken);
+  console.log(jwtPayload);
+
+  // don't display anything while trying to get user token
   // can display a loading screen here if desired
   if (loading) return null;
 
   return (
     <AuthContext.Provider value={[authToken, setAuthToken]}>
       <ApiContext.Provider value={api}>
-        <HashRouter>
-          <Router />
-        </HashRouter>
+        <RolesContext.Provider value={jwtPayload.roles}>
+          <HashRouter>
+            <Router />
+          </HashRouter>
+        </RolesContext.Provider>
       </ApiContext.Provider>
     </AuthContext.Provider>
   );
-- 
cgit v1.2.3-70-g09d2

