diff --git a/apps/studio/components/interfaces/Auth/Users/BanUserModal.tsx b/apps/studio/components/interfaces/Auth/Users/BanUserModal.tsx index aa19b6e4c80..294eb928514 100644 --- a/apps/studio/components/interfaces/Auth/Users/BanUserModal.tsx +++ b/apps/studio/components/interfaces/Auth/Users/BanUserModal.tsx @@ -77,7 +77,6 @@ export const BanUserModal = ({ visible, user, onClose }: BanUserModalProps) => { updateUser({ projectRef, - protocol: 'https', endpoint, serviceApiKey: serviceKey.api_key, userId: user.id, diff --git a/apps/studio/components/interfaces/Auth/Users/CreateUserModal.tsx b/apps/studio/components/interfaces/Auth/Users/CreateUserModal.tsx index 41a421ddcd6..259f212a8d1 100644 --- a/apps/studio/components/interfaces/Auth/Users/CreateUserModal.tsx +++ b/apps/studio/components/interfaces/Auth/Users/CreateUserModal.tsx @@ -70,7 +70,6 @@ const CreateUserModal = ({ visible, setVisible }: CreateUserModalProps) => { createUser({ projectRef, endpoint, - protocol: 'https', serviceApiKey: serviceKey.api_key, user: values, }) diff --git a/apps/studio/components/interfaces/Auth/Users/UserOverview.tsx b/apps/studio/components/interfaces/Auth/Users/UserOverview.tsx index e477d825e43..646dc2a8c0f 100644 --- a/apps/studio/components/interfaces/Auth/Users/UserOverview.tsx +++ b/apps/studio/components/interfaces/Auth/Users/UserOverview.tsx @@ -157,7 +157,6 @@ export const UserOverview = ({ user, onDeleteSuccess }: UserOverviewProps) => { updateUser({ projectRef, - protocol: 'https', endpoint, serviceApiKey: serviceKey.api_key, userId: user.id, diff --git a/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts b/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts index 2397b6b1d5d..d6c1c5dfdd1 100644 --- a/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts +++ b/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts @@ -8,6 +8,7 @@ import { Dispatch, SetStateAction, useCallback, useEffect, useReducer, useState import { toast } from 'sonner' import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query' +import { IS_PLATFORM } from 'lib/constants' import { uuidv4 } from 'lib/helpers' import { EMPTY_ARR } from 'lib/void' import { useRoleImpersonationStateSnapshot } from 'state/role-impersonation-state' @@ -82,8 +83,11 @@ export const useRealtimeMessages = ( const host = settings ? `https://${settings.app_config?.endpoint}` : `https://${projectRef}.supabase.co` - - const realtimeUrl = `${host}/realtime/v1`.replace(/^http/i, 'ws') + // protocol should be ws for self host, and wss for hosted + // as per https://github.com/supabase/realtime-js + const realtimeUrl = IS_PLATFORM + ? `${host}/realtime/v1`.replace(/^http/i, 'ws') + : 'http://localhost:4000/socket' const [logData, dispatch] = useReducer(reducer, [] as LogData[]) const pushMessage = (messageType: string, metadata: any) => { diff --git a/apps/studio/components/layouts/StorageLayout/StorageLayout.tsx b/apps/studio/components/layouts/StorageLayout/StorageLayout.tsx index cacfb57f7e3..89cdc1bb4cb 100644 --- a/apps/studio/components/layouts/StorageLayout/StorageLayout.tsx +++ b/apps/studio/components/layouts/StorageLayout/StorageLayout.tsx @@ -37,7 +37,7 @@ const StorageLayout = ({ title, children }: StorageLayoutProps) => { if (isPaused) return if (endpoint) { - storageExplorerStore.initStore(projectRef!, endpoint, serviceApiKey, 'https') + storageExplorerStore.initStore(projectRef!, endpoint, serviceApiKey) } else { toast.error( 'Failed to fetch project configuration. Try refreshing your browser, or reach out to us at support@supabase.io' diff --git a/apps/studio/data/auth/user-create-mutation.ts b/apps/studio/data/auth/user-create-mutation.ts index 08e60d7e962..de904224c9d 100644 --- a/apps/studio/data/auth/user-create-mutation.ts +++ b/apps/studio/data/auth/user-create-mutation.ts @@ -6,10 +6,11 @@ import { post } from 'lib/common/fetch' import type { ResponseError } from 'types' import { authKeys } from './keys' import { sqlKeys } from 'data/sql/keys' +import { IS_PLATFORM } from 'lib/constants' +import { PROJECT_ENDPOINT_PROTOCOL } from 'pages/api/constants' export type UserCreateVariables = { projectRef?: string - protocol: string endpoint: string serviceApiKey: string user: { @@ -36,7 +37,8 @@ export type UserCreateResponse = { user_metadata: any } -export async function createUser({ protocol, endpoint, serviceApiKey, user }: UserCreateVariables) { +export async function createUser({ endpoint, serviceApiKey, user }: UserCreateVariables) { + const protocol = IS_PLATFORM ? 'https' : PROJECT_ENDPOINT_PROTOCOL const response = await post( `${protocol}://${endpoint}/auth/v1/admin/users`, { diff --git a/apps/studio/data/auth/user-update-mutation.ts b/apps/studio/data/auth/user-update-mutation.ts index 776462ddece..d7dc3be0b17 100644 --- a/apps/studio/data/auth/user-update-mutation.ts +++ b/apps/studio/data/auth/user-update-mutation.ts @@ -1,14 +1,14 @@ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query' import { toast } from 'sonner' -import { useFlag } from 'hooks/ui/useFlag' import { put } from 'lib/common/fetch' +import { IS_PLATFORM } from 'lib/constants' import type { ResponseError } from 'types' import { authKeys } from './keys' +import { PROJECT_ENDPOINT_PROTOCOL } from 'pages/api/constants' export type UserUpdateVariables = { projectRef?: string - protocol: string endpoint: string serviceApiKey: string @@ -18,7 +18,6 @@ export type UserUpdateVariables = { } export async function updateUser({ - protocol, endpoint, serviceApiKey, userId, @@ -26,6 +25,7 @@ export async function updateUser({ }: UserUpdateVariables) { // [Joshen] This is probably the only endpoint that needs the put method from lib/common/fetch // as it's not our internal API. + const protocol = IS_PLATFORM ? 'https' : PROJECT_ENDPOINT_PROTOCOL const response = await put( `${protocol}://${endpoint}/auth/v1/admin/users/${userId}`, { ban_duration: typeof banDuration === 'number' ? `${banDuration}h` : banDuration }, diff --git a/apps/studio/data/fetchers.ts b/apps/studio/data/fetchers.ts index 7835a462188..2ff7d97aa34 100644 --- a/apps/studio/data/fetchers.ts +++ b/apps/studio/data/fetchers.ts @@ -46,6 +46,7 @@ export const get: typeof _get = async (url, init) => { const headers = await constructHeaders(init?.headers) // on self-hosted, we don't have a /platform prefix + // !IS_PLATFORM if (!IS_PLATFORM && url.startsWith('/platform')) { // @ts-ignore url = url.replace('/platform', '') diff --git a/apps/studio/data/telemetry/send-event-mutation.ts b/apps/studio/data/telemetry/send-event-mutation.ts index 893f724a5ec..fab0cc4d7e2 100644 --- a/apps/studio/data/telemetry/send-event-mutation.ts +++ b/apps/studio/data/telemetry/send-event-mutation.ts @@ -3,6 +3,7 @@ import { components } from 'api-types' import { isBrowser, LOCAL_STORAGE_KEYS } from 'common' import { handleError, post } from 'data/fetchers' +import { IS_PLATFORM } from 'lib/constants' import { useRouter } from 'next/router' import type { ResponseError } from 'types' diff --git a/apps/studio/data/telemetry/send-groups-identify-mutation.ts b/apps/studio/data/telemetry/send-groups-identify-mutation.ts index 98f636ff34f..6ad7e4a534c 100644 --- a/apps/studio/data/telemetry/send-groups-identify-mutation.ts +++ b/apps/studio/data/telemetry/send-groups-identify-mutation.ts @@ -3,6 +3,7 @@ import { useMutation, UseMutationOptions } from '@tanstack/react-query' import { components } from 'api-types' import { LOCAL_STORAGE_KEYS } from 'common' import { handleError, post } from 'data/fetchers' +import { IS_PLATFORM } from 'lib/constants' import type { ResponseError } from 'types' export type SendGroupsIdentifyVariables = components['schemas']['TelemetryGroupsIdentityBody'] @@ -13,7 +14,7 @@ export async function sendGroupsIdentify({ body }: { body: SendGroupsIdentifyVar ? localStorage.getItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT) : null) === 'true' - if (!consent) return undefined + if (!consent || !IS_PLATFORM) return undefined const { data, error } = await post(`/platform/telemetry/groups/identify`, { body, diff --git a/apps/studio/data/telemetry/send-groups-reset-mutation.ts b/apps/studio/data/telemetry/send-groups-reset-mutation.ts index 586e4b5982b..28805372b52 100644 --- a/apps/studio/data/telemetry/send-groups-reset-mutation.ts +++ b/apps/studio/data/telemetry/send-groups-reset-mutation.ts @@ -3,6 +3,7 @@ import { useMutation, UseMutationOptions } from '@tanstack/react-query' import { components } from 'api-types' import { LOCAL_STORAGE_KEYS } from 'common' import { handleError, post } from 'data/fetchers' +import { IS_PLATFORM } from 'lib/constants' import type { ResponseError } from 'types' export type SendGroupsResetVariables = components['schemas']['TelemetryGroupsResetBody'] @@ -13,7 +14,7 @@ export async function sendGroupsReset({ body }: { body: SendGroupsResetVariables ? localStorage.getItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT) : null) === 'true' - if (!consent) return undefined + if (!consent || !IS_PLATFORM) return undefined const { data, error } = await post(`/platform/telemetry/groups/reset`, { body, diff --git a/apps/studio/data/telemetry/send-identify-mutation.ts b/apps/studio/data/telemetry/send-identify-mutation.ts index 640ddf51b45..3d64cc2c899 100644 --- a/apps/studio/data/telemetry/send-identify-mutation.ts +++ b/apps/studio/data/telemetry/send-identify-mutation.ts @@ -4,6 +4,7 @@ import { components } from 'api-types' import { LOCAL_STORAGE_KEYS } from 'common' import { handleError, post } from 'data/fetchers' import { Profile } from 'data/profile/types' +import { IS_PLATFORM } from 'lib/constants' import type { ResponseError } from 'types' type SendIdentify = components['schemas']['TelemetryIdentifyBodyV2'] @@ -22,7 +23,7 @@ export async function sendIdentify({ body }: { body: SendIdentifyPayload }) { ? localStorage.getItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT) : null) === 'true' - if (!consent) return undefined + if (!consent || !IS_PLATFORM) return undefined const headers = { Version: '2' } const { data, error } = await post(`/platform/telemetry/identify`, { body, headers }) diff --git a/apps/studio/data/telemetry/send-page-leave-mutation.ts b/apps/studio/data/telemetry/send-page-leave-mutation.ts index d813dff1c2e..97d3b7cf9e0 100644 --- a/apps/studio/data/telemetry/send-page-leave-mutation.ts +++ b/apps/studio/data/telemetry/send-page-leave-mutation.ts @@ -3,6 +3,7 @@ import { components } from 'api-types' import { LOCAL_STORAGE_KEYS } from 'common' import { handleError, post } from 'data/fetchers' +import { IS_PLATFORM } from 'lib/constants' import { useRouter } from 'next/router' import type { ResponseError } from 'types' @@ -14,7 +15,7 @@ export async function sendPageLeave({ body }: { body: SendPageLeaveBody }) { ? localStorage.getItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT) : null) === 'true' - if (!consent) return undefined + if (!consent || !IS_PLATFORM) return undefined const { data, error } = await post(`/platform/telemetry/page-leave`, { body, diff --git a/apps/studio/data/telemetry/send-page-mutation.ts b/apps/studio/data/telemetry/send-page-mutation.ts index d85e13fb6f6..498b83af048 100644 --- a/apps/studio/data/telemetry/send-page-mutation.ts +++ b/apps/studio/data/telemetry/send-page-mutation.ts @@ -3,6 +3,7 @@ import { useMutation, UseMutationOptions } from '@tanstack/react-query' import { components } from 'api-types' import { isBrowser, LOCAL_STORAGE_KEYS } from 'common' import { handleError, post } from 'data/fetchers' +import { IS_PLATFORM } from 'lib/constants' import { useRouter } from 'next/router' import type { ResponseError } from 'types' @@ -20,7 +21,7 @@ export async function sendPage({ body }: { body: SendPagePayload }) { ? localStorage.getItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT) : null) === 'true' - if (!consent) return undefined + if (!consent || !IS_PLATFORM) return undefined const headers = { Version: '2' } const { data, error } = await post(`/platform/telemetry/page`, { body, headers }) diff --git a/apps/studio/data/telemetry/send-reset-mutation.ts b/apps/studio/data/telemetry/send-reset-mutation.ts index 070824b9f67..73ce7964570 100644 --- a/apps/studio/data/telemetry/send-reset-mutation.ts +++ b/apps/studio/data/telemetry/send-reset-mutation.ts @@ -1,9 +1,12 @@ import { useMutation, UseMutationOptions } from '@tanstack/react-query' import { handleError, post } from 'data/fetchers' +import { IS_PLATFORM } from 'lib/constants' import type { ResponseError } from 'types' export async function sendReset() { + if (!IS_PLATFORM) return undefined + const { data, error } = await post(`/platform/telemetry/reset`, {}) if (error) handleError(error) return data diff --git a/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx b/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx index 24e60285183..74e57cb2efa 100644 --- a/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx +++ b/apps/studio/localStores/storageExplorer/StorageExplorerStore.tsx @@ -128,14 +128,10 @@ class StorageExplorerStore { } } - initStore( - projectRef: string, - url: string, - serviceKey: string, - protocol: string = PROJECT_ENDPOINT_PROTOCOL - ) { + initStore(projectRef: string, url: string, serviceKey: string) { + const protocol = IS_PLATFORM ? 'https' : PROJECT_ENDPOINT_PROTOCOL this.projectRef = projectRef - this.resumableUploadUrl = `${IS_PLATFORM ? 'https' : protocol}://${url}/storage/v1/upload/resumable` + this.resumableUploadUrl = `${protocol}://${url}/storage/v1/upload/resumable` this.serviceKey = serviceKey if (serviceKey !== undefined) this.initializeSupabaseClient(serviceKey, url, protocol) } diff --git a/apps/studio/pages/api/projects/[ref]/settings.ts b/apps/studio/pages/api/projects/[ref]/settings.ts index f80694a590a..563a69a90c3 100644 --- a/apps/studio/pages/api/projects/[ref]/settings.ts +++ b/apps/studio/pages/api/projects/[ref]/settings.ts @@ -22,7 +22,7 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => { const response: components['schemas']['ProjectSettingsResponse'] = { app_config: { db_schema: 'public', - endpoint: '', + endpoint: 'localhost:8000', }, cloud_provider: 'AWS', db_dns_name: '',