mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 21:05:06 +03:00
## Problem In local/self-hosted mode, tables incorrectly show "API disabled" even when they have valid RLS policies. This happens because: 1. `project.connectionString` is `null` for local/self-hosted (defaults to null per API types) 2. `useTablesRolesAccessQuery` has `!!connectionString` in its enabled condition 3. The query never runs, so the UI can't determine actual API access status ## Solution Removed `!!connectionString` check from `useTablesRolesAccessQuery`'s enabled condition. This is safe cause: - likewise `executeSql` already handles null/empty connectionString via `connectionString ?? ''` For local/self-hosted, the query works without connectionString (pg-meta uses direct database connection) The query now runs and correctly works Before: <img width="1577" alt="Before fix - API disabled shown incorrectly" src="https://github.com/user-attachments/assets/0510fe38-a4ff-4898-aacb-b2ec8f1a2182" /> After: <img width="1128" alt="After fix - API status displays correctly" src="https://github.com/user-attachments/assets/5784b76b-f7e7-4281-ac40-57408a17a294" /> - Closes #43081 Co-authored-by: Andrey A. <56412611+aantti@users.noreply.github.com>
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import { getTablesWithAnonAuthenticatedAccessSQL } from '@supabase/pg-meta/src/sql/studio/check-tables-anon-authenticated-access'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { executeSql, ExecuteSqlError } from '../sql/execute-sql-query'
|
|
import { tableKeys } from './keys'
|
|
import { UseCustomQueryOptions } from 'types'
|
|
|
|
type TablesRolesAccessArgs = {
|
|
schema: string
|
|
}
|
|
|
|
export type TablesRolesAccessVariables = TablesRolesAccessArgs & {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getTablesWithAnonAuthenticatedAccess(
|
|
{ schema, projectRef, connectionString }: TablesRolesAccessVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!schema) throw new Error('schema is required')
|
|
|
|
const sql = getTablesWithAnonAuthenticatedAccessSQL({ schema })
|
|
|
|
const { result } = (await executeSql(
|
|
{ projectRef, connectionString, sql, queryKey: ['TablesRolesAccess', schema] },
|
|
signal
|
|
)) as { result: { table_name: string }[] }
|
|
|
|
return new Set(result.map((r) => r.table_name))
|
|
}
|
|
|
|
export type TablesRolesAccessData = Awaited<ReturnType<typeof getTablesWithAnonAuthenticatedAccess>>
|
|
export type TablesRolesAccessError = ExecuteSqlError
|
|
|
|
export const useTablesRolesAccessQuery = <TData = TablesRolesAccessData>(
|
|
{ projectRef, connectionString, schema }: TablesRolesAccessVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<TablesRolesAccessData, TablesRolesAccessError, TData> = {}
|
|
) =>
|
|
useQuery<TablesRolesAccessData, TablesRolesAccessError, TData>({
|
|
queryKey: tableKeys.rolesAccess(projectRef, schema),
|
|
queryFn: ({ signal }) =>
|
|
getTablesWithAnonAuthenticatedAccess({ projectRef, connectionString, schema }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined' && typeof schema !== 'undefined',
|
|
...options,
|
|
})
|