The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(studio): authorized apps table in org settings (#50529)
kemal.earth12ab771e863b
diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppRow.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppRow.tsxindex d46aa01f2e4..06b7ec61985 100644--- a/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppRow.tsx+++ b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppRow.tsx@@ -37,7 +37,7 @@ export const OAuthAppRow = ({ app, onSelectEdit, onSelectDelete }: OAuthAppRowPrreturn (<TableRow>- <TableCell className="w-[62px] min-w-[62px] max-w-[62px]">+ <TableCell className="w-[54px] min-w-[54px] max-w-[54px] pr-2"><divclassName="w-[30px] h-[30px] rounded-full bg-no-repeat bg-cover bg-center border border-control flex items-center justify-center text-xs"style={{ backgroundImage: app.icon ? `url('${app.icon}')` : 'none' }}@@ -45,7 +45,7 @@ export const OAuthAppRow = ({ app, onSelectEdit, onSelectDelete }: OAuthAppRowPr{!!app.icon ? '' : `${app.name[0]}`}</div></TableCell>- <TableCell>+ <TableCell className="pl-0"><p title={app.name} className="truncate">{app.name}</p>diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsxindex 938d3077f69..c424a95ad86 100644--- a/apps/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx+++ b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx@@ -1,7 +1,10 @@+import { useFeatureFlags, useFlag } from 'common'import { PageContainer } from 'ui-patterns/PageContainer'import { AuthorizedApps } from './AuthorizedApps'+import { OAuthAppsAuthorizedList } from './OAuthAppsAuthorizedList'import { PublishableApps } from './PublishableApps'+import { USE_MOCKS } from '@/data/oauth-apps/mocks'// [Joshen] Note on nav UX// Kang Ming mentioned that it might be better to split Published Apps and Authorized Apps into 2 separate tabs@@ -9,12 +12,20 @@ import { PublishableApps } from './PublishableApps'// check in again after we wrap up Vercel integrationexport const OAuthApps = () => {+ const areOAuthAppScopedGrantsEnabled = useFlag('OauthAppScopedGrants')+ const { hasLoaded } = useFeatureFlags()+ const shouldShowNewOAuthApps = areOAuthAppScopedGrantsEnabled && USE_MOCKSreturn (<><PageContainer size="default" className="pb-16"><PublishableApps />- {/* Here we'll display the OAuth App Scoped Grants depending on the feature flag in future PRs */}- <AuthorizedApps />+ {hasLoaded ? (+ shouldShowNewOAuthApps ? (+ <OAuthAppsAuthorizedList />+ ) : (+ <AuthorizedApps />+ )+ ) : null}</PageContainer></>)diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppsAuthorizedList.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppsAuthorizedList.tsxnew file mode 100644index 00000000000..430987e69ae--- /dev/null+++ b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppsAuthorizedList.tsx@@ -0,0 +1,159 @@+import { PermissionAction } from '@supabase/shared-types/out/constants'+import { useIntersectionObserver } from '@uidotdev/usehooks'+import { useParams } from 'common'+import { Fragment, useEffect, useMemo } from 'react'+import { Card, cn, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from 'ui'+import {+ PageSection,+ PageSectionContent,+ PageSectionDescription,+ PageSectionMeta,+ PageSectionSummary,+ PageSectionTitle,+} from 'ui-patterns/PageSection'+import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'++import { OAuthAppsAuthorizedRow } from './OAuthAppsAuthorizedRow'+import { AlertError } from '@/components/ui/AlertError'+import { NoPermission } from '@/components/ui/NoPermission'+import { useOAuthApprovalsQuery } from '@/data/oauth-apps/oauth-apps-approvals-query'+import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'++export const OAuthAppsAuthorizedList = () => {+ const { slug } = useParams()++ const { can: canReadOAuthApps, isLoading: isLoadingPermissions } = useAsyncCheckPermissions(+ PermissionAction.READ,+ 'approved_oauth_apps'+ )++ const {+ data,+ isPending,+ isSuccess,+ isError,+ error,+ hasNextPage,+ fetchNextPage,+ isFetchingNextPage,+ } = useOAuthApprovalsQuery({ slug })++ const [sentinelRef, entry] = useIntersectionObserver({+ root: null,+ threshold: 0,+ rootMargin: '0px',+ })++ useEffect(() => {+ if (hasNextPage && entry?.isIntersecting) {+ fetchNextPage()+ }+ }, [hasNextPage, entry?.isIntersecting, fetchNextPage])++ const statusText = useMemo(() => {+ if (isFetchingNextPage) return 'Loading more authorized apps...'+ if (isPending || isLoadingPermissions) return 'Loading...'+ return 'Authorized apps loaded'+ }, [isPending, isLoadingPermissions, isFetchingNextPage])++ const hasAuthorizedApps = isSuccess && data.pages.length > 0 && data.pages[0].data.length > 0++ return (+ <PageSection id="authorized-apps">+ <PageSectionMeta>+ <PageSectionSummary>+ <PageSectionTitle>Authorized apps</PageSectionTitle>+ <PageSectionDescription>+ Applications that have access to your organizations and projects+ </PageSectionDescription>+ </PageSectionSummary>+ </PageSectionMeta>++ <PageSectionContent className="space-y-4">+ <p aria-live="polite" className="sr-only">+ {statusText}+ </p>+ {(isPending || isLoadingPermissions) && !isFetchingNextPage && (+ <div className="space-y-2">+ <ShimmeringLoader />+ <ShimmeringLoader className="w-3/4" />+ </div>+ )}++ {!isLoadingPermissions && !canReadOAuthApps && (+ <NoPermission resourceText="view authorized apps" />+ )}++ {isError && <AlertError subject="Failed to retrieve authorized apps" error={error} />}++ {isSuccess && canReadOAuthApps && (+ <Card>+ <Table>+ <TableHeader>+ <TableRow>+ <TableHead+ className={cn(+ hasAuthorizedApps+ ? 'w-[54px] min-w-[54px] max-w-[54px]'+ : 'w-0 min-w-0 max-w-0 p-0',+ !hasAuthorizedApps && 'text-foreground-muted'+ )}+ >+ <span className="sr-only">Application icon</span>+ </TableHead>+ <TableHead className={cn('pl-0', !hasAuthorizedApps && 'text-foreground-muted')}>+ App+ </TableHead>+ <TableHead className={cn(!hasAuthorizedApps && 'text-foreground-muted')}>+ Access+ </TableHead>+ </TableRow>+ </TableHeader>+ <TableBody>+ {data.pages.length === 0 ? (+ <TableRow className="[&>td]:hover:bg-inherit">+ <TableCell colSpan={3}>+ <p className="text-sm text-foreground">No results found</p>+ <p className="text-sm text-foreground-lighter">+ No apps have been authorized in this organization yet.+ </p>+ </TableCell>+ </TableRow>+ ) : (+ <>+ {data.pages.map((page, pageIndex) => (+ <Fragment key={pageIndex}>+ {page.data.map((approval, index) => (+ <OAuthAppsAuthorizedRow+ key={approval.app.id}+ approval={approval}+ className={cn(+ pageIndex === data.pages.length - 1 &&+ index === page.data.length - 1 &&+ !isFetchingNextPage &&+ 'border-none'+ )}+ />+ ))}+ </Fragment>+ ))}+ <TableRow+ ref={sentinelRef}+ className={cn('[&>td]:hover:bg-inherit', !isFetchingNextPage && 'hidden')}+ >+ <TableCell colSpan={3}>+ <p className="text-sm text-foreground-lighter">+ {isFetchingNextPage ? 'Loading...' : ''}+ </p>+ </TableCell>+ </TableRow>+ </>+ )}+ </TableBody>+ </Table>+ </Card>+ )}+ </PageSectionContent>+ </PageSection>+ )+}diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppsAuthorizedRow.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppsAuthorizedRow.tsxnew file mode 100644index 00000000000..89cc20da275--- /dev/null+++ b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppsAuthorizedRow.tsx@@ -0,0 +1,38 @@+import { TableCell, TableRow } from 'ui'++import type { OAuthApprovalItem, OAuthApprovalTarget } from '@/data/oauth-apps/types'++export interface OAuthAppsAuthorizedRowProps {+ approval: OAuthApprovalItem+ className?: string+}++export const OAuthAppsAuthorizedRow = ({ approval, className }: OAuthAppsAuthorizedRowProps) => {+ return (+ <TableRow className={className}>+ <TableCell className="pr-2">+ <div+ className="flex h-[30px] w-[30px] shrink-0 items-center justify-center rounded-full border border-control bg-cover bg-center bg-no-repeat text-xs"+ style={{ backgroundImage: approval.app.icon ? `url('${approval.app.icon}')` : 'none' }}+ >+ {!!approval.app.icon ? '' : approval.app.name[0]}+ </div>+ </TableCell>+ <TableCell className="pl-0">+ <div>+ <p className="min-w-0 truncate" title={approval.app.name}>+ {approval.app.name}+ </p>+ <p className="min-w-0 text-foreground-lighter font-mono">{approval.app.id}</p>+ </div>+ </TableCell>+ <TableCell>{getGrantTargetLabel(approval.grant_target)}</TableCell>+ </TableRow>+ )+}++const getGrantTargetLabel = (target: OAuthApprovalTarget) => {+ if (target === 'members') return 'Members'+ if (target === 'organization') return 'Organization'+ return 'Organization & members'+}diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/PublishableApps.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/PublishableApps.tsxindex 49838700d0c..c693194d924 100644--- a/apps/studio/components/interfaces/Organization/OAuthApps/PublishableApps.tsx+++ b/apps/studio/components/interfaces/Organization/OAuthApps/PublishableApps.tsx@@ -93,7 +93,7 @@ export const PublishableApps = () => {<PageSection id="published-apps" className="pt-12"><PageSectionMeta><PageSectionSummary>- <PageSectionTitle>Published apps</PageSectionTitle>+ <PageSectionTitle>Publishable apps</PageSectionTitle><PageSectionDescription>Build integrations that extend Supabase's functionality</PageSectionDescription>@@ -198,14 +198,14 @@ export const PublishableApps = () => {<TableHeadclassName={cn(hasPublishedApps- ? 'w-[62px] min-w-[62px] max-w-[62px]'+ ? 'w-[54px] min-w-[54px] max-w-[54px]': 'w-0 min-w-0 max-w-0 p-0',!hasPublishedApps && 'text-foreground-muted')}><span className="sr-only">Avatar</span></TableHead>- <TableHead className={cn(!hasPublishedApps && 'text-foreground-muted')}>+ <TableHead className={cn('pl-0', !hasPublishedApps && 'text-foreground-muted')}>Name</TableHead><TableHead className={cn(!hasPublishedApps && 'text-foreground-muted')}>diff --git a/apps/studio/data/oauth-apps/mocks.ts b/apps/studio/data/oauth-apps/mocks.tsindex cd80e7c1585..eab1016a5fc 100644--- a/apps/studio/data/oauth-apps/mocks.ts+++ b/apps/studio/data/oauth-apps/mocks.ts@@ -331,7 +331,7 @@ const MOCK_APPROVALS: ListOAuthApprovalsResponse = {icon: null,created_by: '',},- grant_target: 'members',+ grant_target: 'organization_and_members',org_grant: null,},{diff --git a/apps/studio/data/oauth-apps/oauth-apps-approvals-query.ts b/apps/studio/data/oauth-apps/oauth-apps-approvals-query.tsindex f440618196b..ac6b49788ea 100644--- a/apps/studio/data/oauth-apps/oauth-apps-approvals-query.ts+++ b/apps/studio/data/oauth-apps/oauth-apps-approvals-query.ts@@ -1,9 +1,9 @@-import { useQuery } from '@tanstack/react-query'+import { InfiniteData, useInfiniteQuery } from '@tanstack/react-query'import { oauthAppsKeys } from './keys'import { getMockOAuthApprovals, USE_MOCKS } from './mocks'import type { ListOAuthApprovalsResponse } from './types'-import type { ResponseError, UseCustomQueryOptions } from '@/types'+import type { ResponseError, UseCustomInfiniteQueryOptions } from '@/types'export type OAuthApprovalsVariables = {slug?: string@@ -30,11 +30,19 @@ export const useOAuthApprovalsQuery = <TData = OAuthApprovalsData>({enabled = true,...options- }: UseCustomQueryOptions<OAuthApprovalsData, OAuthApprovalsError, TData> = {}+ }: UseCustomInfiniteQueryOptions<+ OAuthApprovalsData,+ OAuthApprovalsError,+ InfiniteData<TData>,+ readonly unknown[],+ string | undefined+ > = {}) =>- useQuery<OAuthApprovalsData, OAuthApprovalsError, TData>({+ useInfiniteQuery({queryKey: oauthAppsKeys.approvals(slug, cursor),- queryFn: () => getOAuthApprovals({ slug, cursor }),+ queryFn: ({ pageParam }) => getOAuthApprovals({ slug, cursor: pageParam }),enabled: enabled && USE_MOCKS && Boolean(slug),+ initialPageParam: cursor,+ getNextPageParam: (lastPage) => lastPage.pagination.next_cursor,...options,})diff --git a/knip.jsonc b/knip.jsoncindex fb2517a84b7..89373180d61 100644--- a/knip.jsonc+++ b/knip.jsonc@@ -70,7 +70,6 @@// folder so everything else here stays gated.// TODO(FE-4330): remove — used from #50529, drop this entry in that PR."data/oauth-apps/oauth-apps-approvals-query.ts": ["files"],- "data/oauth-apps/oauth-apps-authorized-apps-query.ts": ["files"],"data/oauth-apps/oauth-apps-grants-query.ts": ["files"],"data/oauth-apps/oauth-apps-member-grants-query.ts": ["files"],"data/oauth-apps/oauth-apps-preflight-validation-query.ts": ["files"],