Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(studio): oauth apps users own grant list in account settings (#50903)

Gildas Garcia88bc1ac38483
diff --git a/apps/studio/components/interfaces/Account/AccessTokens/AccessTokenList.tsx b/apps/studio/components/interfaces/Account/AccessTokens/AccessTokenList.tsx
index 5e0e91c9a4e..1e2811ba883 100644
--- a/apps/studio/components/interfaces/Account/AccessTokens/AccessTokenList.tsx
+++ b/apps/studio/components/interfaces/Account/AccessTokens/AccessTokenList.tsx
@@ -7,6 +7,7 @@ import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
+ DropdownMenuSeparator,
DropdownMenuTrigger,
TableCell,
TableRow,
@@ -154,10 +155,13 @@ export const AccessTokenList = ({
</DropdownMenuTrigger>
<DropdownMenuContent side="bottom" align="end" className="w-40">
{x.kind === 'scoped' && (
- <DropdownMenuItem className="gap-x-2" onClick={() => setTokenToShow(x)}>
- <Key size={12} />
- <p>View permissions</p>
- </DropdownMenuItem>
+ <>
+ <DropdownMenuItem className="gap-x-2" onClick={() => setTokenToShow(x)}>
+ <Key size={12} />
+ <p>View permissions</p>
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ </>
)}
<DropdownMenuItem className="gap-x-2" onClick={() => setTokenToDelete(x)}>
<Trash size={12} />
diff --git a/apps/studio/components/interfaces/Account/OAuthApps/GrantDisconnectDialogContent.tsx b/apps/studio/components/interfaces/Account/OAuthApps/GrantDisconnectDialogContent.tsx
new file mode 100644
index 00000000000..4e2b089d301
--- /dev/null
+++ b/apps/studio/components/interfaces/Account/OAuthApps/GrantDisconnectDialogContent.tsx
@@ -0,0 +1,68 @@
+import { ComponentProps } from 'react'
+import { toast } from 'sonner'
+import {
+ Button,
+ DialogClose,
+ DialogContent,
+ DialogFooter,
+ DialogHeader,
+ DialogSection,
+ DialogSectionSeparator,
+ DialogTitle,
+} from 'ui'
+
+import { useOAuthGrantRevokeMutation } from '@/data/oauth-apps/oauth-apps-revoke-grant-mutation'
+import { MemberOauthGrantItem } from '@/data/oauth-apps/types'
+
+interface GrantDisconnectDialogContentProps extends ComponentProps<typeof DialogContent> {
+ grant: MemberOauthGrantItem
+ onClose: () => void
+}
+
+export const GrantDisconnectDialogContent = ({
+ grant,
+ onClose,
+ ...props
+}: GrantDisconnectDialogContentProps) => {
+ const { mutate: revokeGrant, isPending } = useOAuthGrantRevokeMutation({
+ onSuccess: () => {
+ toast.success(`Revoked access for ${grant?.app?.name}`)
+ onClose()
+ },
+ })
+
+ return (
+ <DialogContent size="small" {...props}>
+ <DialogHeader>
+ <DialogTitle>Revoke access for {grant?.app?.name}</DialogTitle>
+ </DialogHeader>
+ <DialogSectionSeparator />
+ <DialogSection>
+ <div className="flex flex-col gap-4 text-sm text-foreground-light">
+ <p>
+ {grant?.app.name} will no longer be able to access your projects. To reconnect,
+ authorize {grant?.app.name} again and reselect your projects.
+ </p>
+ <p>Other organization members won't be affected.</p>
+ </div>
+ </DialogSection>
+
+ <DialogFooter>
+ <DialogClose asChild>
+ <Button variant="default" disabled={isPending}>
+ Cancel
+ </Button>
+ </DialogClose>
+ <Button
+ variant="danger"
+ loading={isPending}
+ onClick={() => {
+ if (grant) revokeGrant({ slug: grant.organization.slug, grantId: grant.grant_id })
+ }}
+ >
+ Revoke
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ )
+}
diff --git a/apps/studio/components/interfaces/Account/OAuthApps/GrantProjectsDialogContent.tsx b/apps/studio/components/interfaces/Account/OAuthApps/GrantProjectsDialogContent.tsx
new file mode 100644
index 00000000000..9747bb41608
--- /dev/null
+++ b/apps/studio/components/interfaces/Account/OAuthApps/GrantProjectsDialogContent.tsx
@@ -0,0 +1,66 @@
+import { BoxIcon } from 'lucide-react'
+import { ComponentProps } from 'react'
+import {
+ Button,
+ DialogClose,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogSection,
+ DialogSectionSeparator,
+ DialogTitle,
+} from 'ui'
+
+import {
+ OAuthGrantAccordion,
+ OAuthGrantAccordionItem,
+} from '@/components/interfaces/Organization/OAuthApps/OAuthGrantAccordionItem'
+import { MemberOauthGrantItem } from '@/data/oauth-apps/types'
+import { pluralize } from '@/lib/helpers'
+
+interface GrantProjectsDialogContentProps extends ComponentProps<typeof DialogContent> {
+ grant: MemberOauthGrantItem
+}
+
+export const GrantProjectsDialogContent = ({
+ grant,
+ ...props
+}: GrantProjectsDialogContentProps) => {
+ return (
+ <DialogContent size="medium" {...props}>
+ <DialogHeader>
+ <DialogTitle>Projects using {grant?.app.name}</DialogTitle>
+ <DialogDescription className="sr-only">
+ My authorized projects using {grant?.app.name}
+ </DialogDescription>
+ </DialogHeader>
+ <DialogSectionSeparator />
+ <DialogSection className="p-0">
+ <div className="max-h-94 overflow-y-auto">
+ <OAuthGrantAccordion>
+ {grant?.projects?.map((project) => {
+ const permissionCount = grant.approved_scopes.length
+
+ return (
+ <OAuthGrantAccordionItem
+ key={project.ref}
+ value={project.ref}
+ icon={<BoxIcon size={16} />}
+ title={project.name}
+ description={`${permissionCount} ${pluralize(permissionCount, 'permission')}`}
+ sections={[{ label: 'Permissions', values: grant.approved_scopes }]}
+ />
+ )
+ })}
+ </OAuthGrantAccordion>
+ </div>
+ </DialogSection>
+ <DialogFooter>
+ <DialogClose asChild>
+ <Button variant="default">Close</Button>
+ </DialogClose>
+ </DialogFooter>
+ </DialogContent>
+ )
+}
diff --git a/apps/studio/components/interfaces/Account/OAuthApps/GrantRow.tsx b/apps/studio/components/interfaces/Account/OAuthApps/GrantRow.tsx
new file mode 100644
index 00000000000..d97e5916c2d
--- /dev/null
+++ b/apps/studio/components/interfaces/Account/OAuthApps/GrantRow.tsx
@@ -0,0 +1,134 @@
+import { Boxes, MoreVertical, X } from 'lucide-react'
+import { useRef, useState } from 'react'
+import {
+ Button,
+ Dialog,
+ DialogTrigger,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+ TableCell,
+ TableRow,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from 'ui'
+import { TimestampInfo } from 'ui-patterns/TimestampInfo'
+
+import { GrantDisconnectDialogContent } from './GrantDisconnectDialogContent'
+import { GrantProjectsDialogContent } from './GrantProjectsDialogContent'
+import type { MemberOauthGrantItem } from '@/data/oauth-apps/types'
+
+export interface OAuthAppsAuthorizedRowProps {
+ grant: MemberOauthGrantItem
+}
+
+export const GrantRow = ({ grant }: OAuthAppsAuthorizedRowProps) => {
+ const [isDialogOpen, setIsDialogOpen] = useState(false)
+ const [dialogContent, setDialogContent] = useState<'projects' | 'disconnect' | null>(null)
+ const menuTriggerRef = useRef<HTMLButtonElement | null>(null)
+ return (
+ <TableRow>
+ <TableCell>
+ <div className="flex items-center gap-x-3">
+ <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: grant.app.icon ? `url('${grant.app.icon}')` : 'none' }}
+ >
+ {!!grant.app.icon ? '' : grant.app.name[0]}
+ </div>
+ <div className="flex flex-col">
+ <p className="min-w-0 truncate" title={grant.app.name}>
+ {grant.app.name}
+ </p>
+ <p className="min-w-0 text-foreground-lighter">
+ {grant.projects?.length ?? 'All'}{' '}
+ {grant.projects?.length === 1 ? 'project' : 'projects'}
+ </p>
+ </div>
+ </div>
+ </TableCell>
+ <TableCell>{grant.organization.name}</TableCell>
+ <TableCell>
+ <TimestampInfo
+ utcTimestamp={grant.approved_at ?? ''}
+ labelFormat="DD MMM YYYY"
+ className="text-sm"
+ />
+ </TableCell>
+ <TableCell className="text-right">
+ <Dialog
+ open={isDialogOpen}
+ onOpenChange={(open) => {
+ setIsDialogOpen(open)
+ // When users close the dialogs, we need to restore the focus on the menu button
+ // Done in a setTimeout because the dialog tries to restore focus on the trigger despite onCloseAutoFocus being cancelled in the dialog contents
+ setTimeout(() => {
+ if (!open && menuTriggerRef.current) {
+ menuTriggerRef.current.focus()
+ }
+ })
+ }}
+ >
+ <DropdownMenu>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <DropdownMenuTrigger asChild>
+ <Button
+ ref={menuTriggerRef}
+ icon={<MoreVertical />}
+ className="px-1"
+ aria-label="Manage app"
+ aria-describedby={undefined}
+ />
+ </DropdownMenuTrigger>
+ </TooltipTrigger>
+ <TooltipContent side="bottom">Manage app</TooltipContent>
+ </Tooltip>
+ <DropdownMenuContent align="end" side="bottom" className="w-40">
+ {grant.projects != null && grant.projects.length > 0 && (
+ <>
+ <DialogTrigger asChild>
+ <DropdownMenuItem
+ className="gap-x-2"
+ onClick={() => setDialogContent('projects')}
+ >
+ <Boxes size={14} />
+ View projects
+ </DropdownMenuItem>
+ </DialogTrigger>
+ <DropdownMenuSeparator />
+ </>
+ )}
+ <DialogTrigger asChild>
+ <DropdownMenuItem
+ className="gap-x-2"
+ onClick={() => setDialogContent('disconnect')}
+ >
+ <X size={14} />
+ Revoke access
+ </DropdownMenuItem>
+ </DialogTrigger>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ {dialogContent === 'projects' && (
+ <GrantProjectsDialogContent grant={grant} onCloseAutoFocus={preventDefault} />
+ )}
+ {dialogContent === 'disconnect' && (
+ <GrantDisconnectDialogContent
+ grant={grant}
+ onClose={() => setIsDialogOpen(false)}
+ onCloseAutoFocus={preventDefault}
+ />
+ )}
+ </Dialog>
+ </TableCell>
+ </TableRow>
+ )
+}
+
+const preventDefault = (event: Event) => {
+ event.preventDefault()
+}
diff --git a/apps/studio/components/interfaces/Account/OAuthApps/OAuthApps.tsx b/apps/studio/components/interfaces/Account/OAuthApps/OAuthApps.tsx
new file mode 100644
index 00000000000..348fe104707
--- /dev/null
+++ b/apps/studio/components/interfaces/Account/OAuthApps/OAuthApps.tsx
@@ -0,0 +1,111 @@
+import { useIntersectionObserver } from '@uidotdev/usehooks'
+import { Fragment, useEffect } from 'react'
+import { Card, 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 { GrantRow } from './GrantRow'
+import { AlertError } from '@/components/ui/AlertError'
+import { useOAuthGrantsQuery } from '@/data/oauth-apps/oauth-apps-grants-query'
+
+export const OAuthApps = () => {
+ const {
+ data,
+ hasNextPage,
+ fetchNextPage,
+ isFetchingNextPage,
+ isPending,
+ isSuccess,
+ isError,
+ error,
+ } = useOAuthGrantsQuery({})
+
+ const [sentinelRef, entry] = useIntersectionObserver({
+ root: null,
+ threshold: 0,
+ rootMargin: '0px',
+ })
+
+ useEffect(() => {
+ if (hasNextPage && entry?.isIntersecting) {
+ fetchNextPage()
+ }
+ }, [hasNextPage, entry?.isIntersecting, fetchNextPage])
+
+ 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="flex flex-col gap-4">
+ {isPending && (
+ <div className="space-y-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ )}
+
+ {isError && <AlertError subject="Failed to retrieve authorized apps" error={error} />}
+
+ {isSuccess && (
+ <Card>
+ <Table>
+ <TableHeader>
+ <TableRow>
+ <TableHead>App</TableHead>
+ <TableHead>Organization</TableHead>
+ <TableHead>Approved at</TableHead>
+ <TableHead className="text-right">
+ <span className="sr-only">Actions</span>
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {data.pages.length === 0 || data.pages[0].data.length === 0 ? (
+ <TableRow className="[&>td]:hover:bg-inherit">
+ <TableCell colSpan={4}>
+ <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((grant) => (
+ <GrantRow key={grant.grant_id} grant={grant} />
+ ))}
+ </Fragment>
+ ))}
+ <TableRow ref={sentinelRef} className="[&>td]:hover:bg-inherit">
+ <TableCell colSpan={4} className={isFetchingNextPage ? '' : 'p-0 hidden'}>
+ <p aria-live="polite" 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/OAuthAppsMemberGrantsDialogContent.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppsMemberGrantsDialogContent.tsx
index 72f6334f614..f2e5233aca9 100644
--- a/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppsMemberGrantsDialogContent.tsx
+++ b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthAppsMemberGrantsDialogContent.tsx
@@ -1,12 +1,8 @@
import { useIntersectionObserver } from '@uidotdev/usehooks'
import { useParams } from 'common'
import { Building, User } from 'lucide-react'
-import { ComponentProps, Fragment, useEffect, useMemo } from 'react'
+import { ComponentProps, useEffect, useMemo } from 'react'
import {
- Accordion,
- AccordionContent,
- AccordionItem,
- AccordionTrigger,
Button,
cn,
DialogClose,
@@ -19,6 +15,7 @@ import {
} from 'ui'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
+import { OAuthGrantAccordion, OAuthGrantAccordionItem } from './OAuthGrantAccordionItem'
import { AlertError } from '@/components/ui/AlertError'
import { useOAuthAppMemberGrantsQuery } from '@/data/oauth-apps/oauth-apps-member-grants-query'
import type { OAuthApprovalItem, OAuthGrantItem } from '@/data/oauth-apps/types'
@@ -66,7 +63,8 @@ export const OAuthAppsMemberGrantsDialogContent = ({
return 'Grants loaded'
}, [isPending, isFetchingNextPage, isError])
- const isEmpty = !data || data.pages.length === 0 || data.pages[0].data.length === 0
+ const memberGrants = data?.pages.flatMap((page) => page.data) ?? []
+ const isEmpty = memberGrants.length === 0
if (!approval) return null
@@ -98,15 +96,11 @@ export const OAuthAppsMemberGrantsDialogContent = ({
{isEmpty ? 'No grants have been authorized for this application.' : ''}
</p>
- <Accordion type="multiple" className="divide-y! divide-border!">
- {data.pages.map((page, pageIndex) => (
- <Fragment key={pageIndex}>
- {page.data.map((grant) => (
- <GrantAccordionItem key={grant.grant_id} grant={grant} />
- ))}
- </Fragment>
+ <OAuthGrantAccordion>
+ {memberGrants.map((grant) => (
+ <GrantAccordionItem key={grant.grant_id} grant={grant} />
))}
- </Accordion>
+ </OAuthGrantAccordion>
<p ref={sentinelRef} className="text-sm text-foreground-lighter">
{isFetchingNextPage ? 'Loading...' : ''}
</p>
@@ -125,44 +119,24 @@ export const OAuthAppsMemberGrantsDialogContent = ({
const GrantAccordionItem = ({ grant }: { grant: OAuthGrantItem }) => {
const isOrganizationBound = grant.kind === 'organization_bound'
const permissionCount = grant.approved_scopes.length
+ const Icon = isOrganizationBound ? Building : User
+
+ const projectsSummary =
+ grant.projects == null
+ ? 'All projects'
+ : `${grant.projects.length} ${pluralize(grant.projects.length, 'project')}`
return (
- <AccordionItem value={grant.grant_id} className="border-b-0">
- <AccordionTrigger className="hover:no-underline gap-x-4 py-3.5">
- {isOrganizationBound ? (
- <Building size={16} className="shrink-0 text-foreground-lighter rotate-0!" />
- ) : (
- <User size={16} className="shrink-0 text-foreground-lighter rotate-0!" />
- )}
- <div className="min-w-0 flex-1 flex flex-col gap-y-1">
- <p className="truncate text-sm text-foreground">{getGrantLabel(grant)}</p>
- <p className="text-xs text-foreground-lighter">
- {grant.projects == null
- ? 'All projects'
- : `${grant.projects.length} ${pluralize(grant.projects.length, 'project')}`}
- {' · '}
- {permissionCount} {pluralize(permissionCount, 'permission')}
- </p>
- </div>
- </AccordionTrigger>
- <AccordionContent>
- <div className="flex flex-col gap-y-2 pl-8">
- {grant.projects != null && grant.projects.length > 0 && (
- <div className="flex flex-col gap-1">
- <p className="font-mono text-xs uppercase text-foreground-light">Projects</p>
- <p className="text-xs text-foreground">
- {grant.projects.map((project) => project.name).join(', ')}
- </p>
- </div>
- )}
-
- <div className="flex flex-col gap-1">
- <p className="font-mono text-xs uppercase text-foreground-light">Permissions</p>
- <p className="text-xs text-foreground">{grant.approved_scopes.join(', ')}</p>
- </div>
- </div>
- </AccordionContent>
- </AccordionItem>
+ <OAuthGrantAccordionItem
+ value={grant.grant_id}
+ icon={<Icon size={16} />}
+ title={getGrantLabel(grant)}
+ description={`${projectsSummary} · ${permissionCount} ${pluralize(permissionCount, 'permission')}`}
+ sections={[
+ { label: 'Projects', values: grant.projects?.map((project) => project.name) ?? [] },
+ { label: 'Permissions', values: grant.approved_scopes },
+ ]}
+ />
)
}
diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/OAuthGrantAccordionItem.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthGrantAccordionItem.tsx
new file mode 100644
index 00000000000..fb1382dcb03
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/OAuthApps/OAuthGrantAccordionItem.tsx
@@ -0,0 +1,48 @@
+import { ReactNode } from 'react'
+import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from 'ui'
+
+export const OAuthGrantAccordion = ({ children }: { children: ReactNode }) => (
+ <Accordion type="multiple" className="divide-y! divide-border!">
+ {children}
+ </Accordion>
+)
+
+interface OAuthGrantAccordionItemProps {
+ value: string
+ icon: ReactNode
+ title: string
+ description: string
+ sections: { label: string; values: string[] }[]
+}
+
+export const OAuthGrantAccordionItem = ({
+ value,
+ icon,
+ title,
+ description,
+ sections,
+}: OAuthGrantAccordionItemProps) => {
+ return (
+ <AccordionItem value={value} className="border-b-0">
+ <AccordionTrigger className="hover:no-underline gap-x-4 py-3.5">
+ <span className="shrink-0 text-foreground-lighter">{icon}</span>
+ <div className="min-w-0 flex-1 flex flex-col gap-y-1">
+ <p className="truncate text-sm text-foreground">{title}</p>
+ <p className="text-xs text-foreground-lighter">{description}</p>
+ </div>
+ </AccordionTrigger>
+ <AccordionContent>
+ <div className="flex flex-col gap-y-2 pl-8">
+ {sections
+ .filter((section) => section.values.length > 0)
+ .map((section) => (
+ <div key={section.label} className="flex flex-col gap-1">
+ <p className="font-mono text-xs uppercase text-foreground-light">{section.label}</p>
+ <p className="text-xs text-foreground">{section.values.join(', ')}</p>
+ </div>
+ ))}
+ </div>
+ </AccordionContent>
+ </AccordionItem>
+ )
+}
diff --git a/apps/studio/components/interfaces/Organization/OAuthApps/PublishableApps.tsx b/apps/studio/components/interfaces/Organization/OAuthApps/PublishableApps.tsx
index c693194d924..92a2ca67b34 100644
--- a/apps/studio/components/interfaces/Organization/OAuthApps/PublishableApps.tsx
+++ b/apps/studio/components/interfaces/Organization/OAuthApps/PublishableApps.tsx
@@ -205,7 +205,7 @@ export const PublishableApps = () => {
>
<span className="sr-only">Avatar</span>
</TableHead>
- <TableHead className={cn('pl-0', !hasPublishedApps && 'text-foreground-muted')}>
+ <TableHead className={cn(!hasPublishedApps ? 'text-foreground-muted' : 'pl-0')}>
Name
</TableHead>
<TableHead className={cn(!hasPublishedApps && 'text-foreground-muted')}>
diff --git a/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx b/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx
index 6a7b39be1cd..47ab6f3dd33 100644
--- a/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx
+++ b/apps/studio/components/layouts/AccountLayout/AccountLayout.tsx
@@ -1,3 +1,4 @@
+import { useFlag } from 'common'
import Head from 'next/head'
import { useRouter } from 'next/router'
import type { PropsWithChildren } from 'react'
@@ -27,7 +28,7 @@ const AccountLayout = ({ children, title }: PropsWithChildren<AccountLayoutProps
const currentPath = router.pathname
const showSecuritySettings = useIsFeatureEnabled('account:show_security_settings')
-
+ const showOAuthApps = useFlag('OauthAppScopedGrants')
const { appTitle } = useCustomContent(['app:title'])
const brandTitle = appTitle || 'Supabase'
const surfaceLabel = IS_PLATFORM ? 'Account' : 'Preferences'
@@ -91,6 +92,16 @@ const AccountLayout = ({ children, title }: PropsWithChildren<AccountLayoutProps
},
]
: []),
+ ...(showOAuthApps
+ ? [
+ {
+ key: 'oauth-apps',
+ label: 'OAuth Apps',
+ href: '/account/apps',
+ isActive: currentPath === '/account/apps',
+ },
+ ]
+ : []),
],
},
{
@@ -106,7 +117,7 @@ const AccountLayout = ({ children, title }: PropsWithChildren<AccountLayoutProps
],
},
],
- [currentPath, showSecuritySettings]
+ [currentPath, showOAuthApps, showSecuritySettings]
)
useLayoutEffect(() => {
diff --git a/apps/studio/data/oauth-apps/oauth-apps-grants-query.ts b/apps/studio/data/oauth-apps/oauth-apps-grants-query.ts
index f5f300fc160..bea46826f85 100644
--- a/apps/studio/data/oauth-apps/oauth-apps-grants-query.ts
+++ b/apps/studio/data/oauth-apps/oauth-apps-grants-query.ts
@@ -1,9 +1,9 @@
-import { useQuery } from '@tanstack/react-query'
+import { InfiniteData, useInfiniteQuery } from '@tanstack/react-query'
import { oauthAppsKeys } from './keys'
import { getMockOAuthOwnGrants, USE_MOCKS } from './mocks'
import type { ListOwnGrantsResponse } from './types'
-import type { ResponseError, UseCustomQueryOptions } from '@/types'
+import type { ResponseError, UseCustomInfiniteQueryOptions } from '@/types'
export type OAuthGrantsVariables = {
cursor?: string
@@ -27,11 +27,19 @@ export const useOAuthGrantsQuery = <TData = OAuthGrantsData>(
{
enabled = true,
...options
- }: UseCustomQueryOptions<OAuthGrantsData, OAuthGrantsError, TData> = {}
+ }: UseCustomInfiniteQueryOptions<
+ OAuthGrantsData,
+ OAuthGrantsError,
+ InfiniteData<TData>,
+ readonly unknown[],
+ string | undefined
+ > = {}
) =>
- useQuery<OAuthGrantsData, OAuthGrantsError, TData>({
+ useInfiniteQuery({
queryKey: oauthAppsKeys.grants(cursor),
- queryFn: () => getOAuthGrants({ cursor }),
+ queryFn: ({ pageParam }) => getOAuthGrants({ cursor: pageParam }),
+ initialPageParam: cursor,
+ getNextPageParam: (lastPage) => lastPage.pagination.next_cursor,
enabled: enabled && USE_MOCKS,
...options,
})
diff --git a/apps/studio/pages/account/apps.tsx b/apps/studio/pages/account/apps.tsx
new file mode 100644
index 00000000000..32581ed4b1a
--- /dev/null
+++ b/apps/studio/pages/account/apps.tsx
@@ -0,0 +1,57 @@
+import { useFeatureFlags, useFlag } from 'common'
+import { useRouter } from 'next/router'
+import { useEffect } from 'react'
+import { PageContainer } from 'ui-patterns/PageContainer'
+import {
+ PageHeader,
+ PageHeaderDescription,
+ PageHeaderMeta,
+ PageHeaderSummary,
+ PageHeaderTitle,
+} from 'ui-patterns/PageHeader'
+
+import { OAuthApps } from '@/components/interfaces/Account/OAuthApps/OAuthApps'
+import AccountLayout from '@/components/layouts/AccountLayout/AccountLayout'
+import { AppLayout } from '@/components/layouts/AppLayout/AppLayout'
+import { DefaultLayout } from '@/components/layouts/DefaultLayout'
+import type { NextPageWithLayout } from '@/types'
+
+const UserOAuthApps: NextPageWithLayout = () => {
+ const isOAuthAppScopedGrantsEnabled = useFlag('OauthAppScopedGrants')
+ const { hasLoaded } = useFeatureFlags()
+ const router = useRouter()
+ useEffect(() => {
+ if (hasLoaded && !isOAuthAppScopedGrantsEnabled) {
+ router.replace('/404')
+ }
+ }, [hasLoaded, isOAuthAppScopedGrantsEnabled, router])
+
+ if (!hasLoaded || !isOAuthAppScopedGrantsEnabled) {
+ return null
+ }
+
+ return (
+ <>
+ <PageHeader size="small">
+ <PageHeaderMeta>
+ <PageHeaderSummary>
+ <PageHeaderTitle>OAuth Apps</PageHeaderTitle>
+ <PageHeaderDescription>View and manage your personal grants</PageHeaderDescription>
+ </PageHeaderSummary>
+ </PageHeaderMeta>
+ </PageHeader>
+ <PageContainer size="small">
+ <OAuthApps />
+ </PageContainer>
+ </>
+ )
+}
+
+UserOAuthApps.getLayout = (page) => (
+ <AppLayout>
+ <DefaultLayout headerTitle="Account">
+ <AccountLayout title="OAuth Apps">{page}</AccountLayout>
+ </DefaultLayout>
+ </AppLayout>
+)
+export default UserOAuthApps
diff --git a/apps/studio/routeTree.gen.ts b/apps/studio/routeTree.gen.ts
index 546ac6c42d6..084b014185d 100644
--- a/apps/studio/routeTree.gen.ts
+++ b/apps/studio/routeTree.gen.ts
@@ -53,6 +53,7 @@ import { Route as NewSlugRouteImport } from './routes/new/$slug'
import { Route as OrgChar91_Char93RouteImport } from './routes/org.[_]'
import { Route as ProjectRefRouteImport } from './routes/project/$ref'
import { Route as ProjectChar91_Char93RouteImport } from './routes/project.[_]'
+import { Route as AppAccountAppsRouteImport } from './routes/_app/account/apps'
import { Route as AppAccountAuditRouteImport } from './routes/_app/account/audit'
import { Route as AppAccountMeRouteImport } from './routes/_app/account/me'
import { Route as AppAccountSecurityRouteImport } from './routes/_app/account/security'
@@ -556,6 +557,11 @@ const ProjectChar91_Char93Route = ProjectChar91_Char93RouteImport.update({
path: '/project/_',
getParentRoute: () => rootRouteImport,
} as any)
+const AppAccountAppsRoute = AppAccountAppsRouteImport.update({
+ id: '/apps',
+ path: '/apps',
+ getParentRoute: () => AppAccountRoute,
+} as any)
const AppAccountAuditRoute = AppAccountAuditRouteImport.update({
id: '/audit',
path: '/audit',
@@ -2188,6 +2194,7 @@ export interface FileRoutesByFullPath {
'/org/_': typeof OrgChar91_Char93RouteWithChildren
'/project/$ref': typeof ProjectRefRouteWithChildren
'/project/_': typeof ProjectChar91_Char93RouteWithChildren
+ '/account/apps': typeof AppAccountAppsRoute
'/account/audit': typeof AppAccountAuditRoute
'/account/me': typeof AppAccountMeRoute
'/account/security': typeof AppAccountSecurityRoute
@@ -2510,6 +2517,7 @@ export interface FileRoutesByTo {
'/new/$slug': typeof NewSlugRoute
'/org/_': typeof OrgChar91_Char93RouteWithChildren
'/project/_': typeof ProjectChar91_Char93RouteWithChildren
+ '/account/apps': typeof AppAccountAppsRoute
'/account/audit': typeof AppAccountAuditRoute
'/account/me': typeof AppAccountMeRoute
'/account/security': typeof AppAccountSecurityRoute
@@ -2824,6 +2832,7 @@ export interface FileRoutesById {
'/org/_': typeof OrgChar91_Char93RouteWithChildren
'/project/$ref': typeof ProjectRefRouteWithChildren
'/project/_': typeof ProjectChar91_Char93RouteWithChildren
+ '/_app/account/apps': typeof AppAccountAppsRoute
'/_app/account/audit': typeof AppAccountAuditRoute
'/_app/account/me': typeof AppAccountMeRoute
'/_app/account/security': typeof AppAccountSecurityRoute
@@ -3150,6 +3159,7 @@ export interface FileRouteTypes {
| '/org/_'
| '/project/$ref'
| '/project/_'
+ | '/account/apps'
| '/account/audit'
| '/account/me'
| '/account/security'
@@ -3472,6 +3482,7 @@ export interface FileRouteTypes {
| '/new/$slug'
| '/org/_'
| '/project/_'
+ | '/account/apps'
| '/account/audit'
| '/account/me'
| '/account/security'
@@ -3785,6 +3796,7 @@ export interface FileRouteTypes {
| '/org/_'
| '/project/$ref'
| '/project/_'
+ | '/_app/account/apps'
| '/_app/account/audit'
| '/_app/account/me'
| '/_app/account/security'
@@ -4504,6 +4516,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof ProjectChar91_Char93RouteImport
parentRoute: typeof rootRouteImport
}
+ '/_app/account/apps': {
+ id: '/_app/account/apps'
+ path: '/apps'
+ fullPath: '/account/apps'
+ preLoaderRoute: typeof AppAccountAppsRouteImport
+ parentRoute: typeof AppAccountRoute
+ }
'/_app/account/audit': {
id: '/_app/account/audit'
path: '/audit'
@@ -6468,6 +6487,7 @@ declare module '@tanstack/react-router' {
}
interface AppAccountRouteChildren {
+ AppAccountAppsRoute: typeof AppAccountAppsRoute
AppAccountAuditRoute: typeof AppAccountAuditRoute
AppAccountMeRoute: typeof AppAccountMeRoute
AppAccountSecurityRoute: typeof AppAccountSecurityRoute
@@ -6476,6 +6496,7 @@ interface AppAccountRouteChildren {
}
const AppAccountRouteChildren: AppAccountRouteChildren = {
+ AppAccountAppsRoute: AppAccountAppsRoute,
AppAccountAuditRoute: AppAccountAuditRoute,
AppAccountMeRoute: AppAccountMeRoute,
AppAccountSecurityRoute: AppAccountSecurityRoute,
diff --git a/apps/studio/routes/_app/account/apps.tsx b/apps/studio/routes/_app/account/apps.tsx
new file mode 100644
index 00000000000..47435e80336
--- /dev/null
+++ b/apps/studio/routes/_app/account/apps.tsx
@@ -0,0 +1,15 @@
+import { createFileRoute } from '@tanstack/react-router'
+
+import OAuthAppsPage from '@/pages/account/apps'
+
+export const Route = createFileRoute('/_app/account/apps')({
+ component: AccountOAuthAppsPage,
+ staticData: {
+ defaultLayoutHeaderTitle: 'Account',
+ accountLayoutTitle: 'OAuth Apps',
+ },
+})
+
+function AccountOAuthAppsPage() {
+ return <OAuthAppsPage dehydratedState={undefined} />
+}
diff --git a/knip.jsonc b/knip.jsonc
index aedbe4db165..d7c60d89b6a 100644
--- a/knip.jsonc
+++ b/knip.jsonc
@@ -65,12 +65,6 @@
// read are documentation of the valid values, not dead code. Scoped to
// this file so `enumMembers` keeps working everywhere else.
"data/database/constraints-query.ts": ["enumMembers"],
- // Org settings authorized-apps data layer, landed in #49476 ahead of the
- // tables that consume it. Scoped to the remaining files rather than the whole
- // 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-grants-query.ts": ["files"],
- "data/oauth-apps/oauth-apps-revoke-grant-mutation.ts": ["files"],
"hooks/misc/useTrackExperimentExposure.ts": ["files"],
// Staging-only pinned Postgres image + FDW request payload for creating
// Warehouse test projects by hand. Nothing imports it yet — it's kept