Files
supabase/apps/studio/components/interfaces/Organization/OAuthApps/Consent/ScopeGroupCardWithDiff.tsx
Danny White f6dede6c37 feat(studio): make OAuth permission changes easier to scan (#53700)
## Problem

When a returning app changes its permissions, the consent screen mixes
old and new access levels in a list of parenthetical labels.

## Solution

Show added, removed and unchanged permissions in their access groups. A
level change appears in both the old and new groups. Green comes from
the success token so it stays green across accent settings.

| Before | After |
| --- | --- |
| <img width="868" height="2164" alt="CleanShot 2026-11-20 at 12 40
23@2x"
src="https://github.com/user-attachments/assets/74e8462c-60eb-44c5-be25-7e683083be8d"
/> | <img width="866" height="1986" alt="CleanShot 2026-11-20 at 12 38
47@2x"
src="https://github.com/user-attachments/assets/a739e619-8fc7-4a91-9a28-4b3c176b882b"
/> |

## Review instructions

1. **Before:** Open the [Scoped OAuth
tester](https://api.supabase.green/v1/oauth/authorize?response_type=code&client_id=a3999bfe-cfc7-4584-9c5a-ab6828d35aa3&redirect_uri=http%3A%2F%2Flocalhost%3A8765%2Foauth%2Fcallback)
and leave consent open.
2. **After:** Open the [deploy preview consent
screen](https://studio-staging-git-dnywh-oauth-permission-diff-supabase.vercel.app/dashboard/authorize?auth_id=606dbb8e-60ea-4155-bb36-70a7d31378dd).

**What to check**

1. Open Chrome DevTools → **Network** → **Fetch/XHR**, filter by the
`auth_id` in the consent URL, and reload. Right-click each of these two
**GET** requests and select **Override content**. Choose a local
Overrides folder if Chrome prompts you.
- `/api/platform/oauth/authorizations/<auth_id>` is the new request. Set
its top-level `scopes` to
`["database:read","database:write","projects:read","storage:read"]`.
-
`/api/platform/organizations/<org-slug>/oauth/authorizations/<auth_id>/preflight`
is the existing grant check. In that response, replace
`"existing_grant": null` with this field and leave the rest of the
response intact.

     ```json
     "existing_grant": {
       "grant_id": "00000000-0000-4000-8000-000000000001",
"approved_scopes": ["database:read", "projects:read", "secrets:read"],
       "project_refs": null,
       "approved_at": "2026-11-19T00:00:00.000Z"
     },
     ```

2. Keep the other fields as returned. Save both overrides and reload
with DevTools open.
3. Check that Database management is removed from **Read only** and
added to **Read and write**, Projects is unchanged, Storage is added,
and Secrets is struck through. Clear the overrides when done.
2026-11-25 10:55:08 +11:00

87 lines
3.1 KiB
TypeScript

import { MinusIcon, PlusIcon } from 'lucide-react'
import { cn } from 'ui'
import {
formatPermissionName,
getDiffBetweenScopes,
ScopeGroupLevel,
} from './OAuthAppsAuthorizeScreen.utils'
import { ScopePermissionLabel } from './ScopeGroupCardItem'
export interface ScopeGroupCardProps {
scopes: string[]
previousScopes: string[]
}
const scopeLabels: Record<ScopeGroupLevel, string> = {
'read-write': 'Read and write',
write: 'Write',
read: 'Read only',
}
const scopeLevels = ['read-write', 'write', 'read'] as const
export const ScopeGroupCardWithDiff = (props: ScopeGroupCardProps) => {
const diff = getDiffBetweenScopes(props)
const removedPermissions = [
...diff.changed.removed,
...scopeLevels.flatMap((level) =>
diff.changed[level].filter(({ previousLevel }) => previousLevel)
),
]
return (
<div className="space-y-2">
{scopeLevels.map((level) => {
const rows = [
...diff.changed[level].map(({ permission }) => ({ permission, status: 'Added' })),
...removedPermissions
.filter(({ previousLevel }) => previousLevel === level)
.map(({ permission }) => ({ permission, status: 'Removed' })),
...diff.unchanged[level].map((permission) => ({ permission, status: 'Unchanged' })),
]
if (rows.length === 0) return null
return (
<div key={level} className="rounded-md border bg-surface-75 px-4 text-xs">
<h3 className="py-2 font-mono text-xs! uppercase text-foreground-light font-normal!">
{scopeLabels[level]}
</h3>
<ul className="divide-y border-t" aria-label={scopeLabels[level]}>
{rows.map(({ permission, status }) => (
<li
key={permission}
className={cn(
'flex items-center justify-between gap-2 py-2',
status === 'Added' && 'text-success',
status === 'Removed' && 'text-destructive',
status === 'Unchanged' && 'text-foreground-light'
)}
>
<span className="flex min-w-0 items-center gap-1.5">
{status === 'Added' && <PlusIcon size={12} className="shrink-0" aria-hidden />}
{status === 'Removed' && (
<MinusIcon size={12} className="shrink-0" aria-hidden />
)}
{status === 'Unchanged' && <span className="w-3 shrink-0" aria-hidden />}
<span className={cn('font-medium', status === 'Removed' && 'line-through')}>
{status === 'Removed' ? (
formatPermissionName(permission)
) : (
<ScopePermissionLabel permission={permission} />
)}
</span>
</span>
<span className={cn(status === 'Unchanged' && 'text-foreground-lighter')}>
{status}
</span>
</li>
))}
</ul>
</div>
)
})}
</div>
)
}