+
+ Sign in
+
+ This is a dev-only route to sign in and test authenticated actions within docs. In staging
+ and production, signin is managed via dashboard because docs and dashboard are proxied to
+ the same domain.
+
+
+
+
+ )
+}
diff --git a/apps/docs/pages/_app.tsx b/apps/docs/pages/_app.tsx
index aa5e3aaeb73..c03c39c44e7 100644
--- a/apps/docs/pages/_app.tsx
+++ b/apps/docs/pages/_app.tsx
@@ -6,21 +6,49 @@ import '../styles/prism-okaidia.scss'
import { SessionContextProvider } from '@supabase/auth-helpers-react'
import { createClient } from '@supabase/supabase-js'
+import { QueryClientProvider, useQueryClient } from '@tanstack/react-query'
import { AuthProvider, ThemeProvider, useTelemetryProps, useThemeSandbox } from 'common'
import { useRouter } from 'next/router'
-import { useCallback, useEffect, useState } from 'react'
+import { PropsWithChildren, useCallback, useEffect, useState } from 'react'
import { AppPropsWithLayout } from 'types'
import { CommandMenuProvider, PortalToast, useConsent } from 'ui'
import { TabsProvider } from 'ui/src/components/Tabs'
import Favicons from '~/components/Favicons'
import SiteLayout from '~/layouts/SiteLayout'
-import { API_URL, IS_PLATFORM } from '~/lib/constants'
-import { post } from '~/lib/fetchWrappers'
+import { IS_PLATFORM } from '~/lib/constants'
+import { unauthedAllowedPost } from '~/lib/fetch/fetchWrappers'
+import { useRootQueryClient } from '~/lib/fetch/queryClient'
+import { useOnLogout } from '~/lib/userAuth'
+import { LOCAL_STORAGE_KEYS, remove } from '~/lib/storage'
+
+/**
+ *
+ * !!! IMPORTANT !!!
+ * Ensure data is cleared on sign out.
+ *
+ * **/
+function SignOutHandler({ children }: PropsWithChildren) {
+ const queryClient = useQueryClient()
+
+ const cleanUp = useCallback(() => {
+ queryClient.cancelQueries()
+ queryClient.clear()
+
+ Object.keys(LOCAL_STORAGE_KEYS).forEach((key) => {
+ remove('local', LOCAL_STORAGE_KEYS[key])
+ })
+ }, [queryClient])
+
+ useOnLogout(cleanUp)
+
+ return <>{children}>
+}
function MyApp({ Component, pageProps }: AppPropsWithLayout) {
const router = useRouter()
const telemetryProps = useTelemetryProps()
const { consentValue, hasAcceptedConsent } = useConsent()
+ const queryClient = useRootQueryClient()
useThemeSandbox()
@@ -35,15 +63,22 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) {
const handlePageTelemetry = useCallback(
(route: string) => {
- return post(`${API_URL}/telemetry/page`, {
- referrer: document.referrer,
- title: document.title,
- route,
- ga: {
- screen_resolution: telemetryProps?.screenResolution,
- language: telemetryProps?.language,
- },
- })
+ if (IS_PLATFORM) {
+ unauthedAllowedPost('/platform/telemetry/page', {
+ body: {
+ referrer: document.referrer,
+ title: document.title,
+ route,
+ ga: {
+ screen_resolution: telemetryProps?.screenResolution,
+ language: telemetryProps?.language,
+ session_id: '',
+ },
+ },
+ }).catch((e) => {
+ console.error('Problem sending telemetry:', e)
+ })
+ }
},
[telemetryProps]
)
@@ -73,7 +108,7 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) {
return () => {
router.events.off('routeChangeComplete', handleRouteChange)
}
- }, [router, handlePageTelemetry, consentValue])
+ }, [router, handlePageTelemetry, consentValue, hasAcceptedConsent])
/**
* Save/restore scroll position when reloading or navigating back/forward.
@@ -120,7 +155,7 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) {
if (router.isReady) {
handlePageTelemetry(router.basePath + router.asPath)
}
- }, [router, handlePageTelemetry, consentValue])
+ }, [router, handlePageTelemetry, consentValue, hasAcceptedConsent])
/**
* Reference docs use `history.pushState()` to jump to
@@ -141,33 +176,35 @@ function MyApp({ Component, pageProps }: AppPropsWithLayout) {
}
}, [router])
- const SITE_TITLE = 'Supabase Documentation'
-
- const AuthContainer = (props) => {
+ const AuthContainer = ({ children }) => {
return IS_PLATFORM ? (