-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-browser.js
42 lines (38 loc) · 1.23 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
import React from "react"
import netlifyIdentity from "netlify-identity-widget"
import { ApolloProvider } from "@apollo/react-hooks"
import { ApolloClient } from "apollo-client"
import { createHttpLink } from "apollo-link-http"
import { ApolloLink } from "apollo-link"
import { InMemoryCache } from "apollo-cache-inmemory"
import { getCurrentUser } from "./src/services/auth"
import { TwilioVideoProvider } from "./src/hooks/use-twilio-video"
const cache = new InMemoryCache()
const httpLink = createHttpLink({
uri: "https://rubbergoose.herokuapp.com/v1/graphql",
})
// inject auth
const middlewareLink = new ApolloLink((operation, forward) => {
operation.setContext({
headers: {
authorization: `Bearer ${getCurrentUser().token.access_token}` || null,
},
})
return forward(operation)
})
// use with apollo-client
const link = middlewareLink.concat(httpLink)
const client = new ApolloClient({
link,
cache,
})
window.netlifyIdentity = netlifyIdentity
// You must run this once before trying to interact with the widget
netlifyIdentity.init()
export const wrapRootElement = ({ element }) => {
return (
<TwilioVideoProvider>
<ApolloProvider client={client}>{element}</ApolloProvider>
</TwilioVideoProvider>
)
}