-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrap-with-provider.js
56 lines (47 loc) · 1.31 KB
/
wrap-with-provider.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React, { Fragment } from "react";
import { navigate } from "gatsby";
import { withTheme } from "styled-components";
import {
setLayoutBase,
setFirebaseClass,
setWithAuthorizationWrapper,
WithAuthorizationClass,
} from "upe-react-components";
import Firebase from "./src/components/Firebase";
import Header from "./src/components/Header";
import "bootstrap/dist/css/bootstrap.min.css";
export default ({ element }) => {
setFirebaseClass(Firebase);
const WithAuthorizationWrapper = props => {
const AuthorizationFailed = () => (
<div>
<h3>You don't have permission to view this page!</h3>
<p>If you believe you should have access, please contact an admin.</p>
</div>
);
return (
<WithAuthorizationClass
firebaseAuthNext={authUser => {
if (!authUser) {
navigate("/");
}
}}
firebaseAuthFallback={() => {
navigate("/");
}}
authorizationFailed={<AuthorizationFailed />}
{...props}
/>
);
};
setWithAuthorizationWrapper(WithAuthorizationWrapper);
const LayoutBase = withTheme(({ theme, children }) => (
<Fragment>
<Header />
{children}
</Fragment>
));
LayoutBase.displayName = "LayoutBase";
setLayoutBase(LayoutBase);
return element;
};