-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-browser.js
29 lines (27 loc) · 958 Bytes
/
gatsby-browser.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 './src/styles/styles.css'
import React from 'react'
import { ApolloProvider } from 'react-apollo'
import { client } from './src/apollo/client'
import uuidv1 from 'uuid/v1'
import { initAuth } from './src/admin/services/auth'
//Wrap the main component with the provedier from Apollo to query the graphql endpoint
export const wrapRootElement = ({ element }) => (
<ApolloProvider client={client}>{element}</ApolloProvider>
)
export const onClientEntry = () => {
if (typeof window !== 'undefined') {
if (window.localStorage.getItem('userId')) {
console.log(
'There is already a userId stored locally that will be added to state'
)
} else {
console.log(
'There is not a userId. It will be created, stored locally and added to state'
)
const userId = uuidv1()
window.localStorage.setItem('userId', userId)
}
initAuth()
console.log('This is logged using the client entry')
}
}