| 1 | "use client"; |
| 2 | |
| 3 | import { Databuddy } from "@databuddy/sdk/react"; |
| 4 | import { QueryClientProvider } |
| 5 | import Link from "next/link |
| 6 | import { useRouter } |
| 7 | import { ThemeProvider } |
| 8 | import type { ReactNode |
| 9 | |
| 10 | import { AuthProvider } |
| 11 | import { ThemeEffects } |
| 12 | import { apiKeyPlugin } |
| 13 | import { avatar } |
| 14 | import { deviceAuthorizationPlugin } |
| 15 | import { organizationPlugin } |
| 16 | import { usernamePlugin } |
| 17 | import { authClient } |
| 18 | import { DATABUDDY_CLIENT_ID, GITHUB_SIGN_IN |
| 19 | import { organizationRoleLabels } |
| 20 | import { getQueryClient } |
| 21 | import { APP_THEME_IDS } |
| 22 | |
| 23 | export function Providers({ |
| 24 | const router = |
| 25 | const queryClient = |
| 26 | |
| 27 | return ( |
| 28 | <ThemeProvider |
| 29 | attribute="class" |
| 30 | defaultTheme="system" |
| 31 | enableSystem |
| 32 | disableTransitionOnChange |
| 33 | themes={APP_THEME_IDS} |
| 34 | > |
| 35 | <ThemeEffects /> |
| 36 | {DATABUDDY_CLIENT_ID ? ( |
| 37 | <Databuddy |
| 38 | clientId={DATABUDDY_CLIENT_ID} |
| 39 | trackWebVitals={true} |
| 40 | trackErrors |
| 41 | trackInteractions |
| 42 | trackOutgoingLinks |
| 43 | trackHashChanges |
| 44 | trackAttributes |
| 45 | /> |
| 46 | ) : null} |
| 47 | <QueryClientProvider client={ |
| 48 | <AuthProvider |
| 49 | authClient={authClient} |
| 50 | avatar={avatar} |
| 51 | // Callback URLs go to the API, which resolves a relative one against its own origin. |
| 52 | baseURL={SITE_URL} |
| 53 | redirectTo="/dashboard" |
| 54 | socialProviders={GITHUB_SIGN_IN ? |
| 55 | plugins={[ |
| 56 | usernamePlugin(), |
| 57 | apiKeyPlugin(), |
| 58 | organizationPlugin({ |
| 59 | creatorRole: "owner", |
| 60 | roles: organizationRoleLabels, |
| 61 | teams: true, |
| 62 | }), |
| 63 | deviceAuthorizationPlugin(), |
| 64 | ]} |
| 65 | navigate={({ to |
| 66 | replace ? router. |
| 67 | } |
| 68 | Link={Link} |
| 69 | > |
| 70 | {children} |
| 71 | </AuthProvider> |
| 72 | </QueryClientProvider> |
| 73 | </ThemeProvider> |
| 74 | ); |
| 75 | } |