forked from gatsbyjs/store.gatsbyjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-browser.js
More file actions
35 lines (30 loc) · 761 Bytes
/
Copy pathgatsby-browser.js
File metadata and controls
35 lines (30 loc) · 761 Bytes
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
import React from 'react';
import { ApolloProvider } from 'react-apollo';
import { client } from './src/context/ApolloContext';
import { silentAuth } from './src/utils/auth';
class SessionCheck extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: true
};
}
handleCheckSession = () => {
this.setState({ loading: false });
};
componentDidMount() {
silentAuth(this.handleCheckSession);
}
render() {
return (
this.state.loading === false && (
<React.Fragment>{this.props.children}</React.Fragment>
)
);
}
}
export const wrapRootElement = ({ element }) => (
<SessionCheck>
<ApolloProvider client={client}>{element}</ApolloProvider>
</SessionCheck>
);