This commit is contained in:
Joshen Lim committed 2024-11-06 22:31:07 +08:00
1 parent a0aed35e01
commit ac98343e50
17 files changed
+33 -24

No files matched your search

@@ -77,7 +77,6 @@ export const BanUserModal = ({ visible, user, onClose }: BanUserModalProps) => {
updateUser({
projectRef,
protocol: 'https',
endpoint,
serviceApiKey: serviceKey.api_key,
userId: user.id,
@@ -70,7 +70,6 @@ const CreateUserModal = ({ visible, setVisible }: CreateUserModalProps) => {
createUser({
projectRef,
endpoint,
protocol: 'https',
serviceApiKey: serviceKey.api_key,
user: values,
})
@@ -157,7 +157,6 @@ export const UserOverview = ({ user, onDeleteSuccess }: UserOverviewProps) => {
updateUser({
projectRef,
protocol: 'https',
endpoint,
serviceApiKey: serviceKey.api_key,
userId: user.id,
@@ -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) => {
@@ -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'
@@ -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`,
{
@@ -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 },
+1
View File
@@ -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', '')
@@ -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'
@@ -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,
@@ -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,
@@ -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 })
@@ -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,
@@ -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 })
@@ -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
@@ -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)
}
@@ -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: '',