mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
> [!WARNING] > Partner eligibility requires [CTRL-2282](https://linear.app/supabase/issue/CTRL-2282) in the target environment; production deployment is pending. ## Problem Trusted Partners need to configure direct database access for OAuth apps. [DEPR-733](https://linear.app/supabase/issue/DEPR-733) ## Solution - Save and reload direct-access scopes independently of Database management. - Allow new grants only for eligible organisations and organisation-bound apps. - Allow existing direct access to be removed when eligibility changes. | After | | --- | | <img width="1280" height="754" alt="OAuth Apps Organization Settings Basket Supabase" src="https://github.com/user-attachments/assets/e9b78fb6-65e4-4299-ad07-a2f9538a36d5" /> | | `"is_trusted_partner": false` or missing | | <img width="1280" height="754" alt="OAuth Apps Organization Settings Basket Supabase (1)" src="https://github.com/user-attachments/assets/cf78db2c-952c-47e9-9239-82aab2c8398a" /> | | `"is_trusted_partner": true` | ## Review instructions 1. Open the [staging preview](https://studio-staging-git-dnywh-depr-733-oauth-app-dat-c71d4a-supabase.vercel.app/dashboard), select a test organisation and open **OAuth Apps**. It should already be `true, but enable `enableScopedOAuthPublish` in the Studio dev toolbar’s **Flags** tab if needed. 2. Open Chrome DevTools → **Network**, then click **Publish OAuth app**. 3. In Network, select the **GET** request whose URL ends in `/platform/organizations/YOUR_ORG_SLUG`, without `/oauth/apps` after it. Its response contains the organisation’s name and slug. 4. Right-click that request → **Override content**. Choose a local folder and click **Allow**. Add `"is_trusted_partner": true` to the top-level JSON object, keeping every other field. Save with **Cmd/Ctrl+S**. 5. Reload with DevTools open, reopen **Publish OAuth app**, and choose **An owner, once for the whole organization** under authorisation. 6. Under **Application permissions**, find **Direct database access**. Try **No access**, **Read only** and **Read and write**. Change **Database management** separately and check the two values stay independent. 7. With direct access selected, check **Each member, for themselves** is unavailable. Set direct access to **No access**, choose member authorisation, and check the Direct database access dropdown becomes disabled. 8. Switch back to organisation authorisation, select direct access and open **Preview consent for users**. Check its label and access level match the form. 9. Change the overridden field to `false`, save and reload. Reopen the new-app form and check Direct database access is hidden. 10. Disable **Sources → Overrides → Enable Local Overrides**. In a genuinely eligible staging organisation, create a disposable app with direct access, save and reopen it. Change its access level, save and reopen again, then remove direct access. Check Database management remains unchanged. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
63 lines
2.4 KiB
TypeScript
63 lines
2.4 KiB
TypeScript
import { QueryClient, useQuery } from '@tanstack/react-query'
|
|
import { platformComponents as components } from 'api-types'
|
|
import { z } from 'zod'
|
|
|
|
import { organizationKeys } from './keys'
|
|
import { getManagedByFromOrganizationPartner } from './managed-by-utils'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { StudioError } from '@/lib/errors/studio-errors'
|
|
import type { UseCustomQueryOptions } from '@/types'
|
|
|
|
export type OrganizationVariables = { slug?: string }
|
|
export type OrganizationDetail = components['schemas']['OrganizationSlugResponse_Output']
|
|
export type OrganizationPlanID = OrganizationDetail['plan']['id']
|
|
|
|
// [Joshen] Temporary patch, to be removed once API changes are deployed and prop lives in OrganizationSlugResponse_Output
|
|
const trustedPartnerEligibilitySchema = z.object({
|
|
is_trusted_partner: z.boolean().optional().default(false),
|
|
})
|
|
|
|
export function castOrganizationSlugResponseToOrganization(org: OrganizationDetail) {
|
|
return {
|
|
...org,
|
|
...trustedPartnerEligibilitySchema.parse(org),
|
|
billing_email: org.billing_email ?? 'Unknown',
|
|
managed_by: getManagedByFromOrganizationPartner(org.billing_partner, org.integration_source),
|
|
partner_id: org.slug.startsWith('vercel_') ? org.slug.replace('vercel_', '') : undefined,
|
|
}
|
|
}
|
|
|
|
export async function getOrganization({ slug }: OrganizationVariables, signal?: AbortSignal) {
|
|
if (!slug) throw new Error('Organization slug is required')
|
|
|
|
const { data, error } = await get('/platform/organizations/{slug}', {
|
|
params: { path: { slug } },
|
|
signal,
|
|
})
|
|
if (error) handleError(error)
|
|
return castOrganizationSlugResponseToOrganization(data)
|
|
}
|
|
|
|
export type OrganizationsData = Awaited<ReturnType<typeof getOrganization>>
|
|
export type OrganizationsError = StudioError
|
|
|
|
export const useOrganizationQuery = <TData = OrganizationsData>(
|
|
{ slug }: OrganizationVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<OrganizationsData, OrganizationsError, TData> = {}
|
|
) => {
|
|
return useQuery<OrganizationsData, OrganizationsError, TData>({
|
|
queryKey: organizationKeys.detail(slug),
|
|
queryFn: ({ signal }) => getOrganization({ slug }, signal),
|
|
enabled: enabled && typeof slug !== 'undefined',
|
|
...options,
|
|
staleTime: 30 * 60 * 1000,
|
|
})
|
|
}
|
|
|
|
export function invalidateOrganizationsQuery(client: QueryClient) {
|
|
return client.invalidateQueries({ queryKey: organizationKeys.list() })
|
|
}
|