forked from ocf/ocfstatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-browser.tsx
35 lines (33 loc) · 1020 Bytes
/
gatsby-browser.tsx
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 { type GatsbyBrowser } from "gatsby"
import { ReactKeycloakProvider } from "@react-keycloak/web"
import keycloak 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
}
return (
<SWRConfig value={options}>
<ReactKeycloakProvider
authClient={keycloak}
initOptions={{
promiseType: "native",
onLoad: "check-sso",
silentCheckSsoRedirectUri:
window.location.origin + "/silent-check-sso.html",
}}
>
{element}
</ReactKeycloakProvider>
</SWRConfig>
)
}