-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminPage.js
29 lines (26 loc) · 979 Bytes
/
AdminPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { useAuth0 } from "@auth0/auth0-react";
import { createContext, useEffect, useState } from "react";
import { Outlet } from "react-router-dom";
//React context allows us to pass down and use (consume) data in whatever component we need in our React app without using props.
export const AdminContext = createContext(null);
function AdminPage() {
const { getAccessTokenSilently } = useAuth0();
const [tokenData, setTokenData] = useState(null);
useEffect(() => {
(async () => {
const audience = process.env.REACT_APP_AUDIENCE;
const token = await getAccessTokenSilently({ audience });
setTokenData(token);
})();
// useEffect call when dependency array changes (i.e it won't call every rerender)
}, []);
return (
<>
<AdminContext.Provider value={tokenData}>
{/* The Outlet component will always render the next match. */}
<Outlet />
</AdminContext.Provider>
</>
);
}
export default AdminPage;