Skip to content

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

feat(studio): add sign in with ChatGPT (#47772)

Cemal Kılıç366760189521
diff --git a/apps/studio/hooks/misc/__tests__/useEnabledIdentityProviders.test.ts b/apps/studio/hooks/misc/__tests__/useEnabledIdentityProviders.test.ts
index f68a28dd2a3..b82728b4227 100644
--- a/apps/studio/hooks/misc/__tests__/useEnabledIdentityProviders.test.ts
+++ b/apps/studio/hooks/misc/__tests__/useEnabledIdentityProviders.test.ts
@@ -2,29 +2,77 @@ import { renderHook } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { useEnabledIdentityProviders } from '../useEnabledIdentityProviders'
-import { GITHUB_IDENTITY_PROVIDER } from '@/lib/external-identity-providers'
+import {
+ CHATGPT_IDENTITY_PROVIDER,
+ GITHUB_IDENTITY_PROVIDER,
+} from '@/lib/external-identity-providers'
const mockIsFeatureEnabled = vi.hoisted(() => vi.fn())
+const mockUseLocalStorageQuery = vi.hoisted(() => vi.fn())
vi.mock('../useIsFeatureEnabled', () => ({
useIsFeatureEnabled: mockIsFeatureEnabled,
}))
+vi.mock('../useLocalStorage', () => ({
+ useLocalStorageQuery: mockUseLocalStorageQuery,
+}))
+
describe('useEnabledIdentityProviders', () => {
it('returns every provider when all flags are enabled', () => {
mockIsFeatureEnabled.mockReturnValue({
dashboardAuthSignInWithGithub: true,
+ dashboardAuthSignInWithChatgpt: true,
})
+ mockUseLocalStorageQuery.mockReturnValue([true])
const { result } = renderHook(() => useEnabledIdentityProviders())
- expect(result.current).toEqual([GITHUB_IDENTITY_PROVIDER])
+ expect(result.current).toEqual([GITHUB_IDENTITY_PROVIDER, CHATGPT_IDENTITY_PROVIDER])
})
it('returns no providers when all flags are disabled', () => {
mockIsFeatureEnabled.mockReturnValue({
dashboardAuthSignInWithGithub: false,
+ dashboardAuthSignInWithChatgpt: false,
+ })
+ mockUseLocalStorageQuery.mockReturnValue([false])
+
+ const { result } = renderHook(() => useEnabledIdentityProviders())
+
+ expect(result.current).toEqual([])
+ })
+
+ it('includes ChatGPT when its flag is enabled and the local storage switch is truthy', () => {
+ mockIsFeatureEnabled.mockReturnValue({
+ dashboardAuthSignInWithGithub: false,
+ dashboardAuthSignInWithChatgpt: true,
+ })
+ mockUseLocalStorageQuery.mockReturnValue([true])
+
+ const { result } = renderHook(() => useEnabledIdentityProviders())
+
+ expect(result.current).toEqual([CHATGPT_IDENTITY_PROVIDER])
+ })
+
+ it('excludes ChatGPT when its flag is enabled but the local storage switch is unset', () => {
+ mockIsFeatureEnabled.mockReturnValue({
+ dashboardAuthSignInWithGithub: false,
+ dashboardAuthSignInWithChatgpt: true,
+ })
+ mockUseLocalStorageQuery.mockReturnValue([false])
+
+ const { result } = renderHook(() => useEnabledIdentityProviders())
+
+ expect(result.current).toEqual([])
+ })
+
+ it('excludes ChatGPT when the local storage switch is truthy but its flag is disabled', () => {
+ mockIsFeatureEnabled.mockReturnValue({
+ dashboardAuthSignInWithGithub: false,
+ dashboardAuthSignInWithChatgpt: false,
})
+ mockUseLocalStorageQuery.mockReturnValue([true])
const { result } = renderHook(() => useEnabledIdentityProviders())
diff --git a/apps/studio/hooks/misc/useEnabledIdentityProviders.ts b/apps/studio/hooks/misc/useEnabledIdentityProviders.ts
index 4823f9117b3..83aa7c1b18d 100644
--- a/apps/studio/hooks/misc/useEnabledIdentityProviders.ts
+++ b/apps/studio/hooks/misc/useEnabledIdentityProviders.ts
@@ -1,7 +1,10 @@
+import { LOCAL_STORAGE_KEYS } from 'common'
import { useMemo } from 'react'
import { useIsFeatureEnabled } from './useIsFeatureEnabled'
+import { useLocalStorageQuery } from './useLocalStorage'
import {
+ CHATGPT_IDENTITY_PROVIDER,
GITHUB_IDENTITY_PROVIDER,
type ExternalIdentityProviderConfig,
} from '@/lib/external-identity-providers'
@@ -10,11 +13,29 @@ import {
* Returns the statically-declared identity providers whose feature flag is currently enabled.
* To add a provider: declare its config in `lib/external-identity-providers.ts`, add a
* `dashboard_auth:sign_in_with_*` flag, and gate it here.
+ *
+ * ChatGPT is a deliberate exception: it's also gated behind a manual, localStorage-only rollout
+ * switch (`LOCAL_STORAGE_KEYS.SIGN_IN_CHATGPT_ENABLED`) on top of its feature flag, since it's WIP.
*/
export function useEnabledIdentityProviders(): ExternalIdentityProviderConfig[] {
const { dashboardAuthSignInWithGithub: githubEnabled } = useIsFeatureEnabled([
'dashboard_auth:sign_in_with_github',
])
- return useMemo(() => [...(githubEnabled ? [GITHUB_IDENTITY_PROVIDER] : [])], [githubEnabled])
+ const { dashboardAuthSignInWithChatgpt: chatgptEnabled } = useIsFeatureEnabled([
+ 'dashboard_auth:sign_in_with_chatgpt',
+ ])
+ const [chatgptLocalStorageEnabled] = useLocalStorageQuery(
+ LOCAL_STORAGE_KEYS.SIGN_IN_CHATGPT_ENABLED,
+ false
+ )
+
+ return useMemo(
+ () =>
+ [
+ githubEnabled && GITHUB_IDENTITY_PROVIDER,
+ chatgptEnabled && chatgptLocalStorageEnabled && CHATGPT_IDENTITY_PROVIDER,
+ ].filter((p): p is ExternalIdentityProviderConfig => Boolean(p)),
+ [githubEnabled, chatgptEnabled, chatgptLocalStorageEnabled]
+ )
}
diff --git a/apps/studio/lib/external-identity-providers.ts b/apps/studio/lib/external-identity-providers.ts
index 09bf0cef17d..a8ab1dcb5ed 100644
--- a/apps/studio/lib/external-identity-providers.ts
+++ b/apps/studio/lib/external-identity-providers.ts
@@ -40,9 +40,22 @@ export const GITHUB_IDENTITY_PROVIDER: ExternalIdentityProviderConfig = {
showInAccountPreferences: false,
}
+export const CHATGPT_IDENTITY_PROVIDER: ExternalIdentityProviderConfig = {
+ id: 'chatgpt',
+ authProvider: 'custom:openai',
+ displayName: 'ChatGPT',
+ iconPath: '/img/icons/openai-icon.svg',
+ showOnSignIn: true,
+ showOnSignUp: true,
+ showInAccountPreferences: false,
+}
+
// Registry of every known provider, independent of which are currently enabled. Used for config and
// display lookups (e.g. resolving the provider that a mid-flow interstitial was reached with).
-const IDENTITY_PROVIDERS: ExternalIdentityProviderConfig[] = [GITHUB_IDENTITY_PROVIDER]
+const IDENTITY_PROVIDERS: ExternalIdentityProviderConfig[] = [
+ GITHUB_IDENTITY_PROVIDER,
+ CHATGPT_IDENTITY_PROVIDER,
+]
export function normalizeIconPath(iconPath: string): string {
if (
diff --git a/apps/studio/public/img/icons/openai-icon.svg b/apps/studio/public/img/icons/openai-icon.svg
new file mode 100644
index 00000000000..f7acbf46ba8
--- /dev/null
+++ b/apps/studio/public/img/icons/openai-icon.svg
@@ -0,0 +1,3 @@
+<svg width="44" height="44" viewBox="0 0 44 44" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M40.7219 16.9834C41.7178 13.2511 40.7519 9.10385 37.8239 6.17584C34.896 3.24796 30.749 2.28205 27.0165 3.27798C24.282 0.549335 20.2078 -0.687768 16.2079 0.384089C12.2081 1.4557 9.29815 4.56433 8.29453 8.29462C4.56423 9.29825 1.45559 12.2085 0.383983 16.208C-0.687628 20.2079 0.549227 24.282 3.27813 27.0165C2.28219 30.7488 3.24823 34.896 6.17611 37.824C9.104 40.7519 13.251 41.718 16.9837 40.7219C19.718 43.4506 23.7926 44.6877 27.7921 43.616C31.7919 42.5444 34.7018 39.4359 35.7055 35.7056C39.4359 34.7019 42.5444 31.7918 43.616 27.7921C44.6876 23.7924 43.4509 19.7181 40.7219 16.9837V16.9834ZM36.0263 7.97393C38.0103 9.95811 38.8286 12.6664 38.4811 15.2482L29.1631 9.86829C28.7704 9.64151 28.2863 9.64151 27.8938 9.86829L16.9837 16.1672V12.0368C16.9837 11.7471 17.1389 11.476 17.3899 11.3311L25.6978 6.53462C28.9896 4.69596 33.2284 5.17606 36.0265 7.97393H36.0263ZM22.0001 16.2074L27.0167 19.1038V24.8965L22.0001 27.7929L16.9833 24.8965V19.1038L22.0001 16.2074ZM10.4551 11.0651C10.5086 7.29521 13.044 3.86428 16.866 2.84006C19.5763 2.11395 22.331 2.75954 24.3931 4.35108L15.0748 9.73071C14.682 9.95737 14.4401 10.3767 14.4401 10.83V23.4278L10.8631 21.3626C10.6123 21.2177 10.4551 20.9475 10.4551 20.6577V11.0648V11.0651ZM2.83983 16.8661C3.56594 14.156 5.50248 12.0929 7.91193 11.103V21.8627C7.91193 22.316 8.15384 22.7352 8.54661 22.962L19.4569 29.2609L15.8798 31.3262C15.6289 31.4711 15.3163 31.4719 15.0655 31.327L6.75757 26.5306C3.51929 24.5993 1.81598 20.688 2.83983 16.8661ZM7.97384 36.0263C5.98966 34.0422 5.17149 31.3339 5.51886 28.7521L14.8368 34.132C15.2297 34.3586 15.7137 34.3586 16.1062 34.132L27.0165 27.8331V31.9633C27.0165 32.2531 26.8613 32.5243 26.61 32.6692L18.3021 37.4656C15.0104 39.3042 10.7716 38.8241 7.97346 36.0263H7.97384ZM33.5449 32.9351C33.4914 36.7051 30.956 40.136 27.1339 41.1602C24.4236 41.8863 21.6689 41.2407 19.607 39.6491L28.9252 34.2694C29.3181 34.0428 29.5599 33.6236 29.5599 33.1702V20.5724L33.137 22.6377C33.3878 22.7826 33.5449 23.0528 33.5449 23.3426V32.9354V32.9351ZM41.1602 27.134C40.434 29.8443 38.4975 31.9072 36.0881 32.8971V22.1376C36.0881 21.6843 35.8463 21.265 35.4534 21.0383L24.5431 14.7394L28.1202 12.6741C28.371 12.5292 28.6837 12.5282 28.9345 12.6731L37.2424 17.4695C40.4807 19.401 42.1841 23.3123 41.1602 27.134Z" fill="black"/>
+</svg>
diff --git a/packages/common/constants/local-storage.ts b/packages/common/constants/local-storage.ts
index 9671d925e4e..0968d6892df 100644
--- a/packages/common/constants/local-storage.ts
+++ b/packages/common/constants/local-storage.ts
@@ -30,6 +30,7 @@ export const LOCAL_STORAGE_KEYS = {
UI_PREVIEW_MARKETPLACE: 'supabase-ui-marketplace',
AI_ASSISTANT_MCP_OPT_IN: 'ai-assistant-mcp-opt-in',
+ SIGN_IN_CHATGPT_ENABLED: 'siwc-enabled',
DASHBOARD_HISTORY: (ref: string) => `dashboard-history-${ref}`,
STORAGE_PREFERENCE: (ref: string) => `storage-explorer-${ref}`,
@@ -161,6 +162,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.SIGN_IN_CHATGPT_ENABLED,
LOCAL_STORAGE_KEYS.LINTER_SHOW_FOOTER,
LOCAL_STORAGE_KEYS.SIDEBAR_BEHAVIOR,
LOCAL_STORAGE_KEYS.UI_TIMEZONE,
diff --git a/packages/common/enabled-features/enabled-features.json b/packages/common/enabled-features/enabled-features.json
index 7e4fcb40075..bdf512b1e13 100644
--- a/packages/common/enabled-features/enabled-features.json
+++ b/packages/common/enabled-features/enabled-features.json
@@ -34,6 +34,7 @@
"dashboard_auth:sign_up": true,
"dashboard_auth:sign_in_with_github": true,
+ "dashboard_auth:sign_in_with_chatgpt": true,
"dashboard_auth:sign_in_with_sso": true,
"dashboard_auth:sign_in_with_email": true,
"dashboard_auth:show_testimonial": true,
diff --git a/packages/common/enabled-features/enabled-features.schema.json b/packages/common/enabled-features/enabled-features.schema.json
index 0a63c3e2b63..4b4694ad13f 100644
--- a/packages/common/enabled-features/enabled-features.schema.json
+++ b/packages/common/enabled-features/enabled-features.schema.json
@@ -115,6 +115,10 @@
"type": "boolean",
"description": "Enable the sign in with github provider"
},
+ "dashboard_auth:sign_in_with_chatgpt": {
+ "type": "boolean",
+ "description": "Enable the sign in with chatgpt provider"
+ },
"dashboard_auth:sign_in_with_sso": {
"type": "boolean",
"description": "Enable the sign in with sso provider"
@@ -468,6 +472,7 @@
"billing:all",
"dashboard_auth:sign_up",
"dashboard_auth:sign_in_with_github",
+ "dashboard_auth:sign_in_with_chatgpt",
"dashboard_auth:sign_in_with_sso",
"dashboard_auth:sign_in_with_email",
"dashboard_auth:show_tos",