Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Chore/finalize setup configcat www (#38236)

Joshen Lim32f55e82386b
diff --git a/apps/www/components/Hero/Hero.tsx b/apps/www/components/Hero/Hero.tsx
index 7146986b559..94d27bf0582 100644
--- a/apps/www/components/Hero/Hero.tsx
+++ b/apps/www/components/Hero/Hero.tsx
@@ -3,8 +3,6 @@ import Link from 'next/link'
import { Button } from 'ui'
import SectionContainer from '~/components/Layouts/SectionContainer'
import { useSendTelemetryEvent } from '~/lib/telemetry'
-import AnnouncementBadge from '../Announcement/Badge'
-import { announcement } from 'ui-patterns'
const Hero = () => {
const sendTelemetryEvent = useSendTelemetryEvent()
diff --git a/apps/www/components/Nav/index.tsx b/apps/www/components/Nav/index.tsx
index 8746eb592b9..c9232b6bc05 100644
--- a/apps/www/components/Nav/index.tsx
+++ b/apps/www/components/Nav/index.tsx
@@ -9,10 +9,10 @@ import { useIsLoggedIn, useUser } from 'common'
import { Button, buttonVariants, cn } from 'ui'
import { AuthenticatedDropdownMenu } from 'ui-patterns'
+import { useSendTelemetryEvent } from 'lib/telemetry'
import GitHubButton from './GitHubButton'
import HamburgerButton from './HamburgerMenu'
import RightClickBrandLogo from './RightClickBrandLogo'
-import { useSendTelemetryEvent } from 'lib/telemetry'
import useDropdownMenu from './useDropdownMenu'
import { getMenu } from 'data/nav'
diff --git a/apps/www/pages/_app.tsx b/apps/www/pages/_app.tsx
index f033817bc8a..be7a9e4042e 100644
--- a/apps/www/pages/_app.tsx
+++ b/apps/www/pages/_app.tsx
@@ -5,11 +5,12 @@ import '../styles/index.css'
import {
AuthProvider,
FeatureFlagProvider,
+ getFlags as getConfigCatFlags,
IS_PLATFORM,
PageTelemetry,
+ TelemetryTagManager,
ThemeProvider,
useThemeSandbox,
- TelemetryTagManager,
} from 'common'
import { DefaultSeo } from 'next-seo'
import { AppProps } from 'next/app'
@@ -86,7 +87,7 @@ export default function App({ Component, pageProps }: AppProps) {
/>
<AuthProvider>
- <FeatureFlagProvider API_URL={API_URL} enabled={IS_PLATFORM}>
+ <FeatureFlagProvider API_URL={API_URL} getConfigCatFlags={getConfigCatFlags}>
<ThemeProvider
themes={themes.map((theme) => theme.value)}
enableSystem
diff --git a/packages/common/configcat.ts b/packages/common/configcat.ts
index 534a3b0a77d..89046050d73 100644
--- a/packages/common/configcat.ts
+++ b/packages/common/configcat.ts
@@ -3,6 +3,17 @@ import * as configcat from 'configcat-js'
let client: configcat.IConfigCatClient
const endpoint = '/configuration-files/configcat-proxy/frontend-v2/config_v6.json'
+/**
+ * To set up ConfigCat for another app
+ * - Declare `FeatureFlagProvider` at the _app level
+ * - Pass in `getFlags` as `getConfigCatFlags` into `FeatureFlagProvider`
+ * - [Joshen] Wondering if this should just be baked into FeatureFlagProvider, rather than passed as a prop
+ * - Ensure that your app has the `NEXT_PUBLIC_CONFIGCAT_PROXY_URL` env var
+ * - [Joshen] Wondering if we can just set a default value for each env var, so can skip setting up env var in Vercel
+ * - Verify that your flags are now loading by console logging `flagValues` in `FeatureFlagProvider`'s useEffect
+ * - Can now use ConfigCat feature flags with the `useFlag` hook
+ */
+
export const fetchHandler: typeof fetch = async (input, init) => {
try {
return await fetch(input, init)
@@ -16,10 +27,14 @@ export const fetchHandler: typeof fetch = async (input, init) => {
}
async function getClient() {
- if (client) {
- return client
+ if (!process.env.NEXT_PUBLIC_CONFIGCAT_PROXY_URL) {
+ console.error(
+ 'Failed to get ConfigCat client: missing env var "NEXT_PUBLIC_CONFIGCAT_PROXY_URL"'
+ )
}
+ if (client) return client
+
const response = await fetchHandler(process.env.NEXT_PUBLIC_CONFIGCAT_PROXY_URL + endpoint)
const options = { pollIntervalSeconds: 7 * 60 } // 7 minutes
if (response.status !== 200) {
@@ -40,10 +55,11 @@ async function getClient() {
}
export async function getFlags(userEmail: string = '') {
+ const client = await getClient()
+
if (userEmail) {
- const client = await getClient()
return client.getAllValuesAsync(new configcat.User(userEmail))
+ } else {
+ return client.getAllValuesAsync()
}
-
- return []
}