-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIdentityProvider.tsx
33 lines (27 loc) · 1.03 KB
/
IdentityProvider.tsx
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
30
31
32
33
import React from "react";
import { withRouter } from "react-router-dom";
import AuthProvider, { AuthContext } from "./AuthProvider";
import FullPageLoader from "../generic/FullPageLoader";
import UserProvider, { UserContext } from "./UserProvider";
export const PUBLIC_PATHS = ["/", "/callback", "/register"];
export const IdentityProviderChildren = withRouter(({ history, children }) => {
const authData = React.useContext(AuthContext);
const userData = React.useContext(UserContext);
const pageIsPublic = PUBLIC_PATHS.includes(history.location.pathname);
const userIsAuthenticated = authData.state !== "loading" && !!userData;
return pageIsPublic || userIsAuthenticated ? (
<>{children}</>
) : (
<FullPageLoader />
);
});
const IdentityProvider: React.FC = ({ children }) => {
return (
<AuthProvider>
<UserProvider>
<IdentityProviderChildren children={children} />
</UserProvider>
</AuthProvider>
);
};
export default IdentityProvider;