## Problem
Nothing is tracked on the API keys pages (new and legacy), so we can't
tell which keys people copy, how often they create or delete keys, or
how quickly projects disable legacy keys. Closes FE-5030.
## Solution
Adds five events, defined in `packages/common/telemetry-constants.ts`
and fired through `useTrack()`:
| Event | When | Properties |
| --- | --- | --- |
| `api_key_copied` | User copies a publishable, secret, or legacy
anon/service_role key with its Copy button. Keyboard copies aren't
counted. Not fired when blocked by permissions or when the copy fails. |
`keyType` |
| `api_key_reveal_clicked` | User reveals a secret or legacy
service_role key (not on hide) | `keyType` |
| `api_key_created` | Key created from the dialog, or by the first-time
setup (fires once per key) | `keyType`, `source` |
| `api_key_removed` | Key deleted after confirming in the modal |
`keyType` |
| `legacy_api_keys_updated` | Legacy keys disabled or re-enabled |
`enabled` |
- Create, delete, and legacy toggle fire in the mutation hook's
`onSuccess`, so failed attempts aren't counted and the event still fires
if the component unmounts mid-request. They're attributed to the
mutation's own project. Copy and reveal fire in the click handler.
- Delete is tracked in `SecretAPIKeys` / `PublishableAPIKeys`, where the
confirm modal and mutation live, not in the dropdown item.
- No key names or values in properties.
- `data-attr` added to the copy, reveal, create, delete, and docs
controls (static strings; Studio's PostHog autocapture is currently off,
so these send nothing today). `DocsButton` gets an optional `data-attr`
prop.
- `ui-patterns` `Input` gets optional `onReveal` and `onCopied`
callbacks. `onCopied` fires only for the Copy button, so legacy and new
keys count copies the same way.
- The empty-state sample keys are `inert`, so their buttons don't copy
or track.
- New `getLegacyApiKeyType` helper maps the legacy `anon` /
`service_role` tags to the event's `keyType`.
Tests cover copy, reveal, the no-event-on-hide and denied-grant cases,
the legacy toggle, and the key-type helper. Success paths for the create
dialogs and delete aren't covered.
## How to test
- [ ] Open `/project/[ref]/settings/api-keys`, copy a publishable and a
secret key, reveal a secret key, and check `api_key_copied` and
`api_key_reveal_clicked` in PostHog (staging) with the expected
`keyType`
- [ ] Create and delete a publishable and a secret key and check
`api_key_created` / `api_key_removed`
- [ ] On the legacy page, copy anon and service_role, reveal
service_role, then disable and re-enable the keys and check
`legacy_api_keys_updated`
Resolves
[FE-4732](https://linear.app/supabase/issue/FE-4732/grants-rollout-jwt-signing-keys-legacy-api-keys-and-third-party-auth).
## Changes
Gates the JWT signing keys, legacy API keys, and third-party auth
endpoints on grants instead of `unguarded.migrating`, and replaces their
V2 permission guards with `useGrant`:
- **Data layer (11 sites):** `data/jwt-signing-keys/*`,
`data/api-keys/legacy-api-keys-status-query`,
`data/api-keys/legacy-api-key-toggle-mutation`, and
`data/third-party-auth/*`. Queries become grant-gated query option
factories; mutations take the grant in their variables.
- **Consumers:** the JWT settings page, the JWT signing keys table and
its dialogs, `jwt-settings`, `ToggleLegacyApiKeys`, `Project/APIKeys`,
and the third-party auth page, form, and create dialogs. Each consumer
renders denied and error states.
- **JWT signing keys table:**
- It's gated only on the signing keys reads (`GET signing-keys` and `GET
signing-keys/legacy`, both `auth_signing_keys_read`).
- The legacy API keys status is only used by the revoke dialogs. If it
can't be read, revoking the legacy JWT secret fails closed: the user
sees the "disable legacy API keys first" warning, with copy explaining
why, instead of the confirm modal.
- **Legacy JWT secret query:** a 404 (secret not imported as a signing
key yet) resolves to `null` and shows the "Migrate JWT secret" panel.
Other errors now render an error instead of being treated as "not
migrated".
- **Write actions:**
- `getWriteGrantTooltip` moves from `APIKeys.utils` to `lib/grants` and
takes a resource noun. Disabled write actions use it to explain why
they're disabled.
- New `getWriteGrantToastMessage`: handlers that run without a grant now
show a toast instead of silently doing nothing. This includes the API
keys handlers from #52966.
## Permission changes
- **Legacy API keys toggle and status** (`GET`/`PUT
/v1/projects/{ref}/api-keys/legacy`): the guard moves from
`auth_signing_keys_read`/`_write` to the endpoint annotation,
`api_gateway_keys_read`/`_write`. The annotation was confirmed against
the backend controller (FE-4728). As a result, the JWT signing keys
table's legacy revoke check now depends on `api_gateway_keys_read`.
- **API keys last-used analytics**
(`/platform/projects/{ref}/analytics/endpoints/api_keys.last_used.otel`):
this endpoint uses legacy permissions (`analytics:Read` on `logflare`),
not FGA. Its check moves from the V2 `auth_signing_keys_read` check to
`useAsyncCheckPermissions(PermissionAction.ANALYTICS_READ, 'logflare')`.
- Every other guard already matched its annotation:
- `auth_signing_keys_read`/`_write` for signing keys
- `auth_config_read`/`_write` for third-party auth
## Testing
- Data layer: `jwt-signing-keys.test.ts`, `legacy-api-keys.test.ts`, and
`third-party-auth.test.ts` cover every migrated fetcher, check that
factories stay disabled without a grant, and cover legacy-key 404 vs.
500.
- `jwt-secret-keys-table/index.platform.test.tsx`:
- Legacy status denied: the table still renders, and revoking the legacy
key shows only the warning.
- Legacy status known enabled or disabled.
- Signing keys read denied.
- Legacy key 404 vs. 500.
- `create-key-dialog.platform.test.tsx`: triggering create without a
grant shows the toast and sends no request.
- `ToggleLegacyApiKeys.platform.test.tsx`,
`ThirdPartyAuthForm.platform.test.tsx`, and
`settings/jwt/index.platform.test.tsx`: granted, denied, error, and
partial-permission cases.
- `lib/grants.test.ts`: the tooltip and toast helpers.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Part 6 of 6 in a stack for
[FE-4731](https://linear.app/supabase/issue/FE-4731/grants-rollout-api-keys-consumers-that-only-need-publishable-keys).
Based on #52965.
## Stack
1. #52961 Docs and project API docs consumers
2. #52962 Edge functions and vector bucket examples
3. #52963 Integrations landing data
4. #52964 Connect sheet and project connection popover; remove the
transitional api-keys hooks
5. #52965 `reveal` refinement for single api-key reads; API key pill
6. 👉#52966 API key create and delete
## Changes
Gates the api-key write endpoints (both require
`api_gateway_keys_write`) on grants instead of `unguarded.migrating`:
- `api-key-create-mutation` and `api-key-delete-mutation` take the grant
in their variables.
- `APIKeyDeleteDialog` uses the `DELETE` grant instead of its V2 check,
and is disabled with a tooltip when denied or errored. `SecretAPIKeys`
and `PublishableAPIKeys` pass the grant to the mutation.
- `CreateNewAPIKeysButton` and the create publishable and secret key
dialogs mint the `POST` grant. Their triggers and submit buttons are
disabled with a tooltip unless granted.
- `useConnectedResourceMutations`: the api-key delete call takes the
grant. Without it, the mutation shows an error toast and throws.
**New guard:** creating API keys had no UI guard. Users without
`api_gateway_keys_write` could open the dialogs and get a 403; the
controls are now disabled for them. The delete guard already matched the
annotation.
Out of scope: the legacy API key toggle and status (FE-4732).
## Testing
- `CreateAPIKeyDialogs.platform.test.tsx` (renamed from
`CreateAPIKeyDialogs.test.tsx`, the mutation mock removed): denied and
permission-check error disable the triggers and the submit button.
- `APIKeyDeleteDialog.platform.test.tsx`: granted, denied, and
permission-check error.
- `data/api-keys/api-key-write-mutations.test.ts`: create and delete
send their requests with a grant.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Part 2 of 4 in a stack for
[FE-4694](https://linear.app/supabase/issue/FE-4694/pilot-split-api-keys-queries-and-add-first-refinement-reveal-variant).
Based on #52723.
## Stack
1. #52723 Reveal refinement and split api-keys queries
2. 👉#52724 API keys settings UI and command menu
3. #52727 Database and edge functions consumers that reveal secret keys
4. #52728 Storage, cron, and Realtime consumers; remove the transitional
reveal path
## Changes
Moves the API keys settings UI off the V2 permission checks and onto
`useGrant('GET /v1/projects/{ref}/api-keys')` with the new query
options:
- `PublishableAPIKeys`, `SecretAPIKeys`, `Project/APIKeys`, and the
api-keys settings page use a plain grant. They never requested revealed
keys; individual secrets still come from the per-key endpoint.
- The command menu's API keys commands use the `reveal` grant, since
they copy secret key values.
- Each consumer renders loading, denied (`NoPermission`),
permission-check error (`AlertError`), and the existing data states.
`Project/APIKeys` now shows `NoPermission` when denied instead of a
skeleton that never resolved.
## Testing
- Migrates `PublishableAPIKeys.test.tsx`,
`CommandMenu/ApiKeys.test.tsx`, and the api-keys settings page test to
MSW and `customRender`, without mocking the data module or the V2
permissions hook.
- Adds `PublishableAPIKeys.platform.test.tsx` and
`CommandMenu/ApiKeys.platform.test.tsx` for granted, denied, and error
states. The denied test waits for the denied grant before asserting that
no api-keys request was made.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude <noreply@anthropic.com>
## Problem
Migrating Studio's permission checks from the old RLS json logic to
openfga backed permissions.
### New hooks and helpers
- `usePermissionsQueryV2` fetches the new profile openfga permisisons
- `useAsyncCheckPermissionsV2` the replacement for the old check hook;
takes an FGA permission string (or a list)
- `FGA_PERMISSIONS` permission constants derived from
`@supabase/shared-types`. At the moment, the hook also accepts plain
strings for permissions not yet published in the package
- `useAsyncCheckUserContentPermissions` new hook for permission checks
on user content (SQL snippets, reports, log snippets). This wraps
``useAsyncCheckPermissionsV2` and adds existing content level rules on
top of the fga permission check
### Notes
- ~~Need api to support new permissions: project_operations_write,
billing_read/write, audit_logs_read~~ [DONE]
- ~~Still need to support: organization_config_read/write, auth hooks
and users permissions~~ [DONE]
---------
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
This PR removes all `paths` in `tsconfig.json` for all apps and
packages. They were added previosly because some of the components had a
`_Shadcn` suffix because of an ongoing migration. How that the migration
is done, the paths can be removed.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Refactor**
* Standardized shared UI component, utility, and icon imports across
design-system examples and application screens.
* Simplified shared component access and project configuration.
* Added shared access to anchor-link helpers and animation styles.
* **Compatibility**
* Updated component exports and imports without changing existing
behavior.
* No changes to user-facing workflows, screens, or functionality.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
## Problem
The "last used" indicator for the legacy `anon` / `service_role` API
keys (Project API keys settings) was disabled because it ran a BigQuery
`edge_logs` query. It is now re-enabled against the ClickHouse-backed
`api_keys.last_used.otel` analytics endpoint.
## Current behavior
- The `anon` / `service_role` "last used" indicator is off (the
BigQuery-backed query was disabled).
## New behavior
- New `useApiKeysLastUsedQuery` hook calls the `api_keys.last_used.otel`
endpoint (timestamp params only, no SQL sent), plus its query key and
the generated platform API type.
- `DisplayApiSettings` reads last-used from this hook instead of posting
BigQuery `edge_logs` SQL. The pure `getLastUsedAPIKeys` shaper is kept
and unit-tested. Still gated by the `showApiKeysLastUsed` flag.
- Removed the disabled secret-keys (`sb_secret_`) BigQuery last-used
path, which has no ClickHouse endpoint to migrate to: drops the dead
`useLastSeen` query, the `APIKeyRow` "Last Used" column, and the unused
`showLastSeen` prop.
- Reworded the delete-confirmation copy to be accurate for both secret
and publishable keys.
## Additional context
- Backed by the platform endpoint in supabase/platform#34892 (merged and
deployed).
- Scope: `anon` / `service_role` legacy keys. Secret/publishable and JWT
signing-key "last used" are follow-ups, pending the endpoint returning
those key types.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Improvements**
* Updated API key settings to show “last used” activity for the past 24
hours using a dedicated data source and time window.
* Added clearer messaging when recent API key activity fails to load.
* Removed the “Last Used” column from API key management tables.
* **Bug Fixes**
* Improved mapping so “last used” values correctly match the intended
key and role.
* Updated API key deletion confirmation to explain required backend
changes and resulting unauthorized behavior.
* **Tests**
* Added unit tests to validate “last used” computation and edge-case
filtering.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
## Context
Just extracting the fixes which I think are applicable from this
[PR](https://github.com/supabase/supabase/pull/47695)
Main files are
- `apps/studio/hooks/analytics/useLogsQuery.tsx`
- `packages/common/auth.tsx`
- `packages/common/feature-flags.tsx`
## Changes involved
- Adjust `useLogsQuery` to accept an object as prop, rather than 4
individual params
- This one doesn't address any Sentry issues, but is just a improvement
to the function's API imo, more readable
- Adjust how user email is retrieved in `feature-flags`
- Related Sentry issue
[here](https://supabase.sentry.io/issues/7592718607/?project=5459134)
- The error is a bit vague, but Claude's attempt to fix looks alright in
general IMO
- Minimally verified that feature flags are loading as expected still
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved log-related screens and queries for more reliable loading and
filtering across the app.
* Fixed profile and account data handling so identity details are
retrieved more consistently.
* Improved authentication handling to better recognize missing user data
and keep the app stable.
* Updated feature flag personalization to use more accurate account
information.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This PR migrates the whole monorepo to use Tailwind v4:
- Removed `@tailwindcss/container-queries` plugin since it's included by
default in v4,
- Bump all instances of Tailwind to v4. Made minimal changes to the
shared config to remove non-supported features (`alpha` mentions),
- Migrate all apps to be compatible with v4 configs,
- Fix the `typography.css` import in 3 apps,
- Add missing rules which were included by default in v3,
- Run `pnpm dlx @tailwindcss/upgrade` on all apps, which renames a lot
of classes
- Rename all misnamed classes according to
https://tailwindcss.com/docs/upgrade-guide#renamed-utilities in all
apps.
---------
Co-authored-by: Jordi Enric <jordi.err@gmail.com>
## Context
Related to FE-2461
Just following from the previous part
[here](https://github.com/supabase/supabase/pull/41819)
PR removes the usage of `useQueryStateWithSelect` in
- Publishable API Keys (Delete)
- Secret API Keys (Delete)
- Auth Hooks (Edit)
- Database Indexes (Edit + Delete)
-
Ensures that the appropriate behaviours are in place too
- Toast should show when landing on a page with an invalid ID param that
entity doesn't exist
- Toast should not show when deleting the param (which
useQueryStateWithSelect was using useRef as a workaround prior)
## To test
- [ ] API keys (Both publishable and secret key)
- URL updates when deleting a key
- Refresh the page, delete dialog should open with the right key
- Update the query param to something invalid, should see the "not
found" toast
- Delete a key, should only see a success toast
- [ ] Auth Hooks
- URL updates when adding / edit a hook
- Refresh the page, panel should open with the right hook
- Update the query param to something invalid, should see the "not
found" toast
- [ ] Database Indexes
- URL updates when editing/deleting an index
- Refresh the page, delete dialog should open with the right index
- Update the query param to something invalid, should see the "not
found" toast
- Delete an index, should only see a success toast
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved error handling and user notifications when API keys, hooks,
or indexes are deleted or become unavailable; users now see clear toasts
when a target item cannot be found.
* **Refactoring**
* Internal state and dialog visibility handling for API keys, hooks, and
database indexes have been simplified to make UI flows more reliable and
consistent.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Ali Waseem <waseema393@gmail.com>
* Bump the deps, refactor deprecated code.
* Migrate keepPreviousData usage.
* Migrate all uses of InfiniteQuery.
* Fix refetchInterval in queries.
* Migrate all use of isLoading to isPending in mutations.
* Fix accessing location in claim-project.
* Fix a bug in duplicate query keys.
* Migrate all queries to use isPending.
* Revert "Fix accessing location in claim-project."
This reverts commit 2a07df64b5.
* Revert the rss.xml file to master.
* chore(studio): add param routing to policies crud panels
* chore(studio): policy not found if opening edit or delete panel with wrong id
* integrate useQueryStateWithSelect to Policies
* add useQueryStateWithSelect to db triggers
* add useQueryStateWithSelect to AddUserDropdown
* add useQueryStateWithSelect to OAuthApps
* add useQueryStateWithSelect to API Keyys
* revert policies and users param routing
* Update perms checking in audit logs
* Deprecate useCheckPermissions, useIsPermissionsLoaded and useCheckProjectPermissions as they're no longer used
* Rename useAsyncCheckProjectPermissions to useAsyncCheckPermissions
* Fix TS
* Refactor Drawer component and add date-fns dependency
Refactored the Drawer component for improved slot-based structure, updated styles, and added 'use client' directive. Added 'date-fns' as a dependency in design-system, updated tsconfig paths for icons, and marked ToggleGroup as a client component.
* nit: add env for svg path
* fix: instructions
* accent color docs and basic tidy
* copy value feature
* improve color contrast
* increase contrast on text-warning in light mode
* update changelog
* replace outdated text-warning utility classes
* remove redundant warning-600
* minor design-system docs updates
* docs updates
* remove unused brand-button class
* update docs
* fix: restore brand default
* update docs brand text color
* low hanging branded text fruit
* Nit refactor and clean up
* re-add Kemal’s README instructions for hot reload
---------
Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
* Part 1 of swapping useCheckPermissions with useAsyncCheckProjectPermissions
* Update apps/studio/hooks/misc/useCheckPermissions.ts
Co-authored-by: Drake Costa <drake@saeris.io>
* Address feedback
---------
Co-authored-by: Drake Costa <drake@saeris.io>
* Improve layout and truncation in SigningKeyRow
Added flex and truncation classes to ensure status labels and key IDs are properly truncated and aligned. This enhances the table's appearance and prevents overflow issues for long text.
* Improve icon layout and badge styling in UI components
Added flex-shrink-0 to icons in AlgorithmHoverCard for better alignment. Updated InfoPill to use min-w-0, overflow-hidden, and improved badge and label layout for consistent appearance and handling of long content.
* Remove unused cn import from InfoPill component
The cn utility import was removed from InfoPill.tsx as it is no longer used. The Badge component now uses a direct className string instead.
* Update JWT key table columns and add rotation info
Removed the 'Key ID' column and added a 'Last rotated at' column to the JWT secret keys table. The signing key row now displays the relative time since the key was last updated for previously used keys.
* Add Key ID column to JWT secret keys table
Introduces a new 'Key ID' column to the JWTSecretKeysTable component for improved visibility and management of JWT secret keys.
* Improve JWT key table UI and add tooltip to key ID
Updated the JWT secret keys table to enhance the empty state with an icon and explanatory text, and adjusted column alignment and visibility for 'Last rotated at'. Added a tooltip to the key ID for better accessibility and ensured the 'Last rotated at' column displays for both previously used and revoked keys.
* Improve API key table layout and responsiveness
API key name and description are now grouped together, with description shown under the name. The last seen column is hidden on smaller screens and displays 'Never used' when appropriate. ApiKeyPill max width is now responsive to screen size. The description column was removed from SecretAPIKeys to streamline the table.
* Adjust API key pill and input sizing for responsiveness
Reduced max-widths for ApiKeyPill and updated PublishableAPIKeys layout to improve responsiveness. ApiKeyInput now uses dynamic min/max widths for better display across breakpoints.
* Adjust lg breakpoint min-width for API key input
Changed the lg:min-w value from 40rem to 24rem for the API key input field to improve layout responsiveness at large screen sizes.
* Update PublishableAPIKeys.tsx
* Remove unused file
* Minor refactors
---------
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
* first pass
* init
* updated types
* fix up key reveal
* Update QuickKeyCopy.tsx
* remove quick key copy
* api key pill now only allows reveal and copy if you have perm
* Update LegacyAPIKeys.tsx
* fix up layouts
* fix copy
* Fix action menu dropdown position, few small nudges
* Remove unused files.
* Remove the hardcoded and rename the feature flag for basic API keys.
* add support for name and description, some smaller improvements
* Fix the trims for the description.
---------
Co-authored-by: Terry Sutton <saltcod@gmail.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
* feat: add basic api keys ui
* init JWT secrets. rough
* Update JWTSecretKeysTable.tsx
* added some info hover cards.
• found this this is probably the wrong direction
• will create a new page for next iteration.
* init new version
* add illustrations
* Update JWTSecretKeysTablev2.tsx
* chore: delete API key now works
* some style changes
* added better tables
* Update JWTSecretKeysTablev2.tsx
* add public JWT dialog
* moar
* adding sub layout in
* starts adding in a ButtonGroup
* about to make into separate components
* added quick copy to project loading screen
* build state
* basic loading
* confirm dialog and loading states
* switched for better loading experience
* moved styles of Input to InputVariants
* issue with ref type
* loading,error and rest states
* new loading states
* alt l;ayout
* add group
* updated error states for permissions
* copy button behaviour for secret keys
* delete dialog
* Update QuickKeyCopy.tsx
* fix type errors
* Update JWTSecretKeysTablev2.tsx
* update menu to hide pages
* Update SettingsMenu.utils.tsx
* Update resource-query.ts
* remove old file
* moved JWT secrets to use valtio
* Update api-keys-query.ts
* fix typecheck
* rename files
* remove JWT stuff
* revert file
* remove more JWT stuff
* Update package.json
* Update pnpm-lock.yaml
* Update ProjectLayout.tsx
* Update PublishableAPIKeys.tsx
* Update api-keys-query.ts
* refactor api-keys-query
* Update SettingsMenu.utils.tsx
* Some clean up
* more clean up and refactor
* Update APIKeyRow.tsx
* Update LayoutHeader.tsx
* resolve comments
* Update CreateSecretAPIKeyModal.tsx
* Update APIKeyRow.tsx
* Add perms check for delete API keys
* Remove console log
* Delete ConnectDialog.tsx
* use project ref
---------
Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>