-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathgatsby-browser.tsx
More file actions
30 lines (27 loc) · 873 Bytes
/
gatsby-browser.tsx
File metadata and controls
30 lines (27 loc) · 873 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
import { type GatsbyBrowser } from "gatsby"
import { AuthProvider } from "react-oidc-context"
import keycloakConfig from "~/utils/keycloak"
import { SWRConfig, SWRConfiguration } from "swr"
import "~/styles/inter.css"
export const wrapRootElement: GatsbyBrowser["wrapRootElement"] = ({
element,
}) => {
const options: SWRConfiguration = {
fetcher: (url: string) => {
if (process.env.NODE_ENV === "production" && url.startsWith("/api")) {
url = "https://api.ocf.berkeley.edu" + url.replace("/api", "")
}
return fetch(url).then((r) => r.json())
},
refreshInterval: 15 * 1000, // 15 seconds
}
const config = {
...keycloakConfig,
redirect_uri: window.location.origin,
} as typeof keycloakConfig
return (
<SWRConfig value={options}>
<AuthProvider {...config}>{element}</AuthProvider>
</SWRConfig>
)
}