Skip to content

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

feat: add Realtime private only feature flag (#37026)

Wen Bo Xie2f6977edc315
diff --git a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreview.constants.tsx b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreview.constants.tsx
index c2b2c54f742..2db32d6c747 100644
--- a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreview.constants.tsx
+++ b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreview.constants.tsx
@@ -1,11 +1,18 @@
import { LOCAL_STORAGE_KEYS } from 'common'
export const FEATURE_PREVIEWS = [
+ {
+ key: LOCAL_STORAGE_KEYS.UI_PREVIEW_REALTIME_SETTINGS,
+ name: 'Realtime settings',
+ discussionsUrl: undefined,
+ isNew: true,
+ isPlatformOnly: true,
+ },
{
key: LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR,
name: 'Directly edit database entities',
discussionsUrl: 'https://github.com/orgs/supabase/discussions/33690',
- isNew: true,
+ isNew: false,
isPlatformOnly: false,
},
{
diff --git a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx
index bef4199d7cc..01ed929dc86 100644
--- a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx
+++ b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx
@@ -79,3 +79,8 @@ export const useIsInlineEditorEnabled = () => {
const { flags } = useFeaturePreviewContext()
return flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR]
}
+
+export const useIsRealtimeSettingsEnabled = () => {
+ const { flags } = useFeaturePreviewContext()
+ return flags[LOCAL_STORAGE_KEYS.UI_PREVIEW_REALTIME_SETTINGS]
+}
diff --git a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
index bfa693f84b2..477392fa4f6 100644
--- a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
+++ b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
@@ -5,6 +5,7 @@ import { ReactNode } from 'react'
import { LOCAL_STORAGE_KEYS, useParams } from 'common'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
+import { useIsRealtimeSettingsFFEnabled } from 'hooks/ui/useFlag'
import { IS_PLATFORM } from 'lib/constants'
import { useAppStateSnapshot } from 'state/app-state'
import { Badge, Button, Modal, ScrollArea, cn } from 'ui'
@@ -13,10 +14,12 @@ import { CLSPreview } from './CLSPreview'
import { FEATURE_PREVIEWS } from './FeaturePreview.constants'
import { useFeaturePreviewContext } from './FeaturePreviewContext'
import { InlineEditorPreview } from './InlineEditorPreview'
+import { RealtimeSettingsPreview } from './RealtimeSettingsPreview'
const FEATURE_PREVIEW_KEY_TO_CONTENT: {
[key: string]: ReactNode
} = {
+ [LOCAL_STORAGE_KEYS.UI_PREVIEW_REALTIME_SETTINGS]: <RealtimeSettingsPreview />,
[LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR]: <InlineEditorPreview />,
[LOCAL_STORAGE_KEYS.UI_PREVIEW_API_SIDE_PANEL]: <APISidePanelPreview />,
[LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS]: <CLSPreview />,
@@ -29,9 +32,13 @@ const FeaturePreviewModal = () => {
const featurePreviewContext = useFeaturePreviewContext()
const { mutate: sendEvent } = useSendEventMutation()
+ const isRealtimeSettingsEnabled = useIsRealtimeSettingsFFEnabled()
+
// [Joshen] Use this if we want to feature flag previews
function isReleasedToPublic(feature: (typeof FEATURE_PREVIEWS)[number]) {
switch (feature.key) {
+ case 'supabase-ui-realtime-settings':
+ return isRealtimeSettingsEnabled
default:
return true
}
diff --git a/apps/studio/components/interfaces/App/FeaturePreview/RealtimeSettingsPreview.tsx b/apps/studio/components/interfaces/App/FeaturePreview/RealtimeSettingsPreview.tsx
new file mode 100644
index 00000000000..43a9c283f25
--- /dev/null
+++ b/apps/studio/components/interfaces/App/FeaturePreview/RealtimeSettingsPreview.tsx
@@ -0,0 +1,49 @@
+import Image from 'next/image'
+
+import { useParams } from 'common'
+import { InlineLink } from 'components/ui/InlineLink'
+import { BASE_PATH } from 'lib/constants'
+import { useIsRealtimeSettingsEnabled } from './FeaturePreviewContext'
+
+export const RealtimeSettingsPreview = () => {
+ const { ref } = useParams()
+ const isRealtimeSettingsEnabled = useIsRealtimeSettingsEnabled()
+
+ return (
+ <div>
+ <p className="text-sm text-foreground-light mb-4">
+ Allows you to setup several configurations for Realtime, including configuration channel
+ restrictions where you can enable or disable public channels from being able to connect.
+ Learn more about how Realtime Authorization works{' '}
+ <InlineLink href="https://supabase.com/docs/guides/realtime/authorization">
+ in our documentation
+ </InlineLink>
+ .
+ </p>
+ <Image
+ src={`${BASE_PATH}/img/previews/realtime-settings-preview.png`}
+ width={1296}
+ height={900}
+ alt="api-docs-side-panel-preview"
+ className="rounded border mb-4"
+ />
+ <div className="space-y-2 !mt-4">
+ <p className="text-sm">Enabling this preview will:</p>
+ <ul className="list-disc pl-6 text-sm text-foreground-light space-y-1">
+ <li>
+ Allow you to configure realtime settings for your project from the{' '}
+ <InlineLink
+ href={
+ isRealtimeSettingsEnabled
+ ? `/project/${ref}/realtime/settings`
+ : `/project/${ref}/realtime/inspector`
+ }
+ >
+ realtime section.
+ </InlineLink>
+ </li>
+ </ul>
+ </div>
+ </div>
+ )
+}
diff --git a/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx b/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
index 112d89c0fac..8da40366074 100644
--- a/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
+++ b/apps/studio/components/layouts/RealtimeLayout/RealtimeLayout.tsx
@@ -1,10 +1,11 @@
import { useRouter } from 'next/router'
import { PropsWithChildren } from 'react'
+import { useIsRealtimeSettingsEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { ProductMenu } from 'components/ui/ProductMenu'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { withAuth } from 'hooks/misc/withAuth'
-import { useFlag } from 'hooks/ui/useFlag'
+import { useIsRealtimeSettingsFFEnabled } from 'hooks/ui/useFlag'
import ProjectLayout from '../ProjectLayout/ProjectLayout'
import { generateRealtimeMenu } from './RealtimeMenu.utils'
@@ -14,18 +15,10 @@ export interface RealtimeLayoutProps {
const RealtimeLayout = ({ title, children }: PropsWithChildren<RealtimeLayoutProps>) => {
const project = useSelectedProject()
- // the flag is used to enable/disable the realtime settings for all projects
- const enableRealtimeSettingsFlag = useFlag('enableRealtimeSettings')
- // the flag is used to enable/disable the realtime settings for specific projects. Will be overridden by the enableRealtimeSettingsFlag if it is enabled.
- const approvedProjects = useFlag<string>('isRealtimeSettingsEnabledOnProjects')
+ const enableRealtimeSettingsFF = useIsRealtimeSettingsFFEnabled()
+ const enableRealtimeSettingsFP = useIsRealtimeSettingsEnabled()
- const isEnabledOnProject =
- !!project?.ref &&
- typeof approvedProjects === 'string' &&
- (approvedProjects ?? '')
- .split(',')
- .map((it) => it.trim())
- .includes(project?.ref)
+ const enableRealtimeSettings = enableRealtimeSettingsFF && enableRealtimeSettingsFP
const router = useRouter()
const page = router.pathname.split('/')[4]
@@ -37,9 +30,7 @@ const RealtimeLayout = ({ title, children }: PropsWithChildren<RealtimeLayoutPro
productMenu={
<ProductMenu
page={page}
- menu={generateRealtimeMenu(project!, {
- enableRealtimeSettings: enableRealtimeSettingsFlag || isEnabledOnProject,
- })}
+ menu={generateRealtimeMenu(project!, { enableRealtimeSettings })}
/>
}
>
diff --git a/apps/studio/hooks/ui/useFlag.ts b/apps/studio/hooks/ui/useFlag.ts
index 0b2416ef627..be76ab33fa0 100644
--- a/apps/studio/hooks/ui/useFlag.ts
+++ b/apps/studio/hooks/ui/useFlag.ts
@@ -2,6 +2,7 @@ import * as Sentry from '@sentry/nextjs'
import { useFeatureFlags } from 'common'
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
+import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { trackFeatureFlag } from 'lib/posthog'
const isObjectEmpty = (obj: Object) => {
@@ -55,3 +56,23 @@ export function usePHFlag<T = string | boolean>(name: string) {
return flagValue as T
}
+
+export const useIsRealtimeSettingsFFEnabled = () => {
+ const project = useSelectedProject()
+
+ // This flag is used to enable/disable the realtime settings for specific projects.
+ const approvedProjects = useFlag<string>('isRealtimeSettingsEnabledOnProjects')
+ // This flag is used to enable/disable the realtime settings for all projects.
+ // Will override isRealtimeSettingsEnabledOnProjects if enabled
+ const enableRealtimeSettingsFlag = useFlag('enableRealtimeSettings')
+
+ const isEnabledOnProject =
+ !!project?.ref &&
+ typeof approvedProjects === 'string' &&
+ (approvedProjects ?? '')
+ .split(',')
+ .map((it) => it.trim())
+ .includes(project?.ref)
+
+ return enableRealtimeSettingsFlag || isEnabledOnProject
+}
diff --git a/apps/studio/public/img/previews/assistant-v2.png b/apps/studio/public/img/previews/assistant-v2.png
deleted file mode 100644
index f30a43eeb30..00000000000
Binary files a/apps/studio/public/img/previews/assistant-v2.png and /dev/null differ
diff --git a/apps/studio/public/img/previews/layout-update.png b/apps/studio/public/img/previews/layout-update.png
deleted file mode 100644
index b51db67c005..00000000000
Binary files a/apps/studio/public/img/previews/layout-update.png and /dev/null differ
diff --git a/apps/studio/public/img/previews/realtime-settings-preview.png b/apps/studio/public/img/previews/realtime-settings-preview.png
new file mode 100644
index 00000000000..9f1cd2970b3
Binary files /dev/null and b/apps/studio/public/img/previews/realtime-settings-preview.png differ
diff --git a/apps/studio/public/img/previews/rls-ai-assistant-preview.png b/apps/studio/public/img/previews/rls-ai-assistant-preview.png
deleted file mode 100644
index 4c646ff445b..00000000000
Binary files a/apps/studio/public/img/previews/rls-ai-assistant-preview.png and /dev/null differ
diff --git a/apps/studio/public/img/previews/tabs-editor.png b/apps/studio/public/img/previews/tabs-editor.png
deleted file mode 100644
index e040742c864..00000000000
Binary files a/apps/studio/public/img/previews/tabs-editor.png and /dev/null differ
diff --git a/apps/studio/public/img/previews/tabs-sql.png b/apps/studio/public/img/previews/tabs-sql.png
deleted file mode 100644
index c20bf073e14..00000000000
Binary files a/apps/studio/public/img/previews/tabs-sql.png and /dev/null differ
diff --git a/packages/common/constants/local-storage.ts b/packages/common/constants/local-storage.ts
index e986052e82c..dda4acaa245 100644
--- a/packages/common/constants/local-storage.ts
+++ b/packages/common/constants/local-storage.ts
@@ -11,6 +11,8 @@ export const LOCAL_STORAGE_KEYS = {
UI_PREVIEW_CLS: 'supabase-ui-cls',
UI_PREVIEW_INLINE_EDITOR: 'supabase-ui-preview-inline-editor',
UI_ONBOARDING_NEW_PAGE_SHOWN: 'supabase-ui-onboarding-new-page-shown',
+ UI_PREVIEW_REALTIME_SETTINGS: 'supabase-ui-realtime-settings',
+
NEW_LAYOUT_NOTICE_ACKNOWLEDGED: 'new-layout-notice-acknowledge',
TABS_INTERFACE_ACKNOWLEDGED: 'tabs-interface-acknowledge',
TERMS_OF_SERVICE_ACKNOWLEDGED: 'terms-of-service-acknowledged',
@@ -104,6 +106,7 @@ const LOCAL_STORAGE_KEYS_ALLOWLIST = [
LOCAL_STORAGE_KEYS.HIDE_PROMO_TOAST,
LOCAL_STORAGE_KEYS.BLOG_VIEW,
LOCAL_STORAGE_KEYS.AI_ASSISTANT_MCP_OPT_IN,
+ LOCAL_STORAGE_KEYS.UI_PREVIEW_REALTIME_SETTINGS,
]
export function clearLocalStorage() {