Repository navigation
feat(studio): add legacy token mode to scoped pat creation flow - #48844
Conversation
Replaces the scoped form's inline account-level access mode with a proper legacy-token escape hatch: "Create legacy token" switches the sheet to the classic form (name + expiry only) and creates through the legacy endpoint, skipping the two-step review. Mirrors the mode-switch links in both directions and restores the "Generate token for experimental API" split-button dropdown, extracted into a shared ExperimentalTokenDropdown. Ported from origin/w3b6x9/scoped-pat-ui-rework, excluding its expiry handling (shipped in #48811) and MCP-unsupported warnings (follow-up PR). Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
📝 WalkthroughWalkthroughThe access-token flow now supports classic account-wide tokens, scoped project or organization tokens, and experimental V0 tokens. Classic and scoped forms use separate creation paths, shared success handling, and updated navigation and validation. ChangesAccess Token Creation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant AccountTokensPage
participant NewScopedTokenSheet
participant NewScopedTokenForm
participant AccessTokenMutation
participant ExperimentalTokenDropdown
participant NewTokenDialog
AccountTokensPage->>NewScopedTokenSheet: Provide onCreateExperimentalToken callback
NewScopedTokenSheet->>NewScopedTokenForm: Render classic or scoped access mode
NewScopedTokenForm->>AccessTokenMutation: Create classic or scoped token
AccessTokenMutation-->>NewScopedTokenSheet: Return created token
NewScopedTokenSheet->>AccountTokensPage: Store created token
NewScopedTokenSheet->>ExperimentalTokenDropdown: Render experimental token control
ExperimentalTokenDropdown->>NewTokenDialog: Open V0 token dialog
NewTokenDialog-->>NewScopedTokenSheet: Return created experimental token
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx (1)
105-119: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the classic request payload.
The mock discards the request. The classic path is the main behavior this PR adds, and the payload distinguishes it from the scoped path:
nameis trimmed,expires_atcomes from the preset, and noscopeis sent. Capture the body in the mock and assert it in the creation test.💚 Proposed test addition
-const mockCreateClassicToken = () => - addAPIMock({ +const mockCreateClassicToken = (onRequest?: (body: unknown) => void) => + addAPIMock({ method: 'post', path: '/platform/profile/access-tokens', - response: () => - HttpResponse.json<CreateClassicTokenResponse>({ + response: async ({ request }) => { + onRequest?.(await request.clone().json()) + return HttpResponse.json<CreateClassicTokenResponse>({ created_at: '', expires_at: null, id: 1, last_used_at: null, name: 'test', token: 'a_classic_token_value', token_alias: '', - }), + }) + }, })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx` around lines 105 - 119, Update mockCreateClassicToken to capture and inspect the POST request body, then extend the classic token creation test to assert that name is trimmed, expires_at matches the selected preset, and scope is omitted.apps/studio/components/interfaces/Account/AccessTokens/Classic/ExperimentalTokenDropdown.tsx (1)
26-28: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRename the boolean state to
isVisible.The coding guidelines require boolean names to begin with
is,has,can, orshould.♻️ Proposed rename
- const [visible, setVisible] = useState(false) + const [isVisible, setIsVisible] = useState(false)Update the two usages below:
- <DropdownMenuItem key="experimental-token" onClick={() => setVisible(true)}> + <DropdownMenuItem onClick={() => setIsVisible(true)}>- <NewTokenDialog - open={visible} - onOpenChange={setVisible} + <NewTokenDialog + open={isVisible} + onOpenChange={setIsVisible}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Account/AccessTokens/Classic/ExperimentalTokenDropdown.tsx` around lines 26 - 28, Rename the boolean state variable in ExperimentalTokenDropdown from visible to isVisible, updating its declaration and both associated usages while preserving the existing state behavior.Source: Coding guidelines
apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/NewScopedTokenForm.tsx (1)
114-127: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueExtract the reverse mode switch into a named handler.
handleSelectLegacyModeis documented as the single owner of the mode switch. The return path to scoped mode is an inlinesetValuecall, so the two directions are asymmetric. A namedhandleSelectScopedModekeeps both transitions in one place and gives a single point to add dependent resets later.♻️ Proposed refactor
+ const handleSelectScopedMode = () => { + form.setValue('resourceAccess', 'project', { shouldValidate: true }) + }<button type="button" className={InlineLinkClassName} - onClick={() => - form.setValue('resourceAccess', 'project', { shouldValidate: true }) - } + onClick={handleSelectScopedMode} tabIndex={0} >🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/NewScopedTokenForm.tsx` around lines 114 - 127, Extract the inline scoped-mode switch into a named handleSelectScopedMode handler near handleSelectLegacyMode, and update the “Create scoped token” button to call that handler instead of form.setValue directly. Keep the existing resourceAccess value and validation behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/ResourceAccessStep.tsx`:
- Around line 198-211: Update the MultiSelector’s disabled condition to use
organizationSlugs.length, disabling the project selector when the array is empty
while preserving enabled behavior when organizations are available. Keep the
existing label logic unchanged.
- Around line 122-129: Update the resourceAccess onValueChange handler to also
clear organizationSlugs when switching modes, alongside the existing projectRefs
reset. Ensure stale organization selections cannot affect projectsForOrg after
changing from organization to project mode.
---
Nitpick comments:
In
`@apps/studio/components/interfaces/Account/AccessTokens/Classic/ExperimentalTokenDropdown.tsx`:
- Around line 26-28: Rename the boolean state variable in
ExperimentalTokenDropdown from visible to isVisible, updating its declaration
and both associated usages while preserving the existing state behavior.
In
`@apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/NewScopedTokenForm.tsx`:
- Around line 114-127: Extract the inline scoped-mode switch into a named
handleSelectScopedMode handler near handleSelectLegacyMode, and update the
“Create scoped token” button to call that handler instead of form.setValue
directly. Keep the existing resourceAccess value and validation behavior
unchanged.
In
`@apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx`:
- Around line 105-119: Update mockCreateClassicToken to capture and inspect the
POST request body, then extend the classic token creation test to assert that
name is trimmed, expires_at matches the selected preset, and scope is omitted.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 795c2656-8a0c-4571-8fd9-f5fcb97ac01a
📒 Files selected for processing (11)
apps/studio/components/interfaces/Account/AccessTokens/AccessToken.constants.tsapps/studio/components/interfaces/Account/AccessTokens/Classic/ExperimentalTokenDropdown.tsxapps/studio/components/interfaces/Account/AccessTokens/Classic/NewTokenButton.tsxapps/studio/components/interfaces/Account/AccessTokens/Classic/NewTokenDialog.tsxapps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/NewScopedTokenForm.tsxapps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/NewScopedTokenForm.utils.tsapps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/NewScopedTokenFormReview.tsxapps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/ResourceAccessStep.tsxapps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsxapps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.tsxapps/studio/pages/account/tokens.tsx
💤 Files with no reviewable changes (1)
- apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/NewScopedTokenForm.utils.ts
| <RadioGroupStacked | ||
| value={resourceAccess} | ||
| onValueChange={(value) => { | ||
| field.onChange(value) | ||
| // Reset dependent selections when switching modes. | ||
| setValue('projectRefs', []) | ||
| }} | ||
| > |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Reset organizationSlugs when the resource mode changes.
The handler resets projectRefs only. organizationSlugs keeps its previous value across a mode switch. After a user selects several organizations in organization mode and then switches to project mode, the single Select at Line 166 displays only field.value[0], but projectsForOrg at Line 92 still filters projects for every retained slug. The project list then contains projects from organizations that the user cannot see in the Select.
🐛 Proposed fix
onValueChange={(value) => {
field.onChange(value)
// Reset dependent selections when switching modes.
+ setValue('organizationSlugs', [])
setValue('projectRefs', [])
}}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| <RadioGroupStacked | |
| value={resourceAccess} | |
| onValueChange={(value) => { | |
| field.onChange(value) | |
| // Reset dependent selections when switching modes. | |
| setValue('projectRefs', []) | |
| }} | |
| > | |
| <RadioGroupStacked | |
| value={resourceAccess} | |
| onValueChange={(value) => { | |
| field.onChange(value) | |
| // Reset dependent selections when switching modes. | |
| setValue('organizationSlugs', []) | |
| setValue('projectRefs', []) | |
| }} | |
| > |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/ResourceAccessStep.tsx`
around lines 122 - 129, Update the resourceAccess onValueChange handler to also
clear organizationSlugs when switching modes, alongside the existing projectRefs
reset. Ensure stale organization selections cannot affect projectsForOrg after
changing from organization to project mode.
| <MultiSelector | ||
| onValuesChange={field.onChange} | ||
| values={field.value} | ||
| disabled={!organizationSlugs} | ||
| className="w-full" | ||
| > | ||
| <MultiSelectorTrigger | ||
| id="organizationSlugs" | ||
| id="projectRefs" | ||
| mode="combobox" | ||
| label="Select organizations" | ||
| label={ | ||
| organizationSlugs.length > 0 | ||
| ? 'Select projects' | ||
| : 'Select an organization first' | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fix the always-false disabled check on the project selector.
organizationSlugs is an array. An empty array is truthy, so !organizationSlugs is always false and the selector is never disabled. The trigger label at Line 208 already uses organizationSlugs.length > 0, so the label states "Select an organization first" while the control stays open and lists nothing.
🐛 Proposed fix
<MultiSelector
onValuesChange={field.onChange}
values={field.value}
- disabled={!organizationSlugs}
+ disabled={organizationSlugs.length === 0}
className="w-full"
>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| <MultiSelector | |
| onValuesChange={field.onChange} | |
| values={field.value} | |
| disabled={!organizationSlugs} | |
| className="w-full" | |
| > | |
| <MultiSelectorTrigger | |
| id="organizationSlugs" | |
| id="projectRefs" | |
| mode="combobox" | |
| label="Select organizations" | |
| label={ | |
| organizationSlugs.length > 0 | |
| ? 'Select projects' | |
| : 'Select an organization first' | |
| } | |
| <MultiSelector | |
| onValuesChange={field.onChange} | |
| values={field.value} | |
| disabled={organizationSlugs.length === 0} | |
| className="w-full" | |
| > | |
| <MultiSelectorTrigger | |
| id="projectRefs" | |
| mode="combobox" | |
| label={ | |
| organizationSlugs.length > 0 | |
| ? 'Select projects' | |
| : 'Select an organization first' | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@apps/studio/components/interfaces/Account/AccessTokens/Scoped/Form/ResourceAccessStep.tsx`
around lines 198 - 211, Update the MultiSelector’s disabled condition to use
organizationSlugs.length, disabling the project selector when the array is empty
while preserving enabled behavior when organizations are available. Keep the
existing label logic unchanged.
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › realtime-inspector.spec.ts › Realtime Inspector › Basic Inspector UI › start/stop listening button works Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
🎭 Playwright Test Results (next)Details
Flaky testsFeatures › rls-policies.spec.ts › RLS Policies › Create RLS Policy › should create a DELETE policy Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx (1)
105-120: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAssert the classic-token request payload.
The new MSW handler returns a successful token for every request. The classic creation test can pass even if the form sends an incorrect
name,scope, orexpires_at. Parse the request body in the handler, or capture it and assert the expected legacy payload after submission.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx` around lines 105 - 120, Update mockCreateClassicToken to inspect and retain the POST request payload, then have the classic-token creation test assert the expected legacy name, scope, and expires_at values after submission instead of relying only on the successful response.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx`:
- Around line 105-120: Update mockCreateClassicToken to inspect and retain the
POST request payload, then have the classic-token creation test assert the
expected legacy name, scope, and expires_at values after submission instead of
relying only on the successful response.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 754e7288-91cd-4a6b-98f7-c68165f364f3
📒 Files selected for processing (1)
apps/studio/components/interfaces/Account/AccessTokens/Scoped/NewScopedTokenSheet.test.tsx
joshenlim
left a comment
There was a problem hiding this comment.
Preview test — ✅ all pass
No explicit "To test" section on this PR, so I inferred the plan from the diff and ran through it on the studio-staging preview (/account/tokens, scopedPAT flag was already on for this account).
| # | Test | Result |
|---|---|---|
| 1 | Experimental token dropdown still works after extraction into ExperimentalTokenDropdown |
✅ Chevron → "Generate token for experimental API" opens the V0 dialog with the expected copy |
| 2 | "Create legacy token" link switches resource-access step into classic mode | ✅ Warning admonition, resource-access cards + permissions gone, "Create scoped token" link shown, footer button reads "Generate token" with no step indicator |
| 3 | Switching back to scoped mode doesn't resurface stale errors | ✅ Triggered "Please select an organization to continue.", switched to legacy then back — scoped form restored cleanly, no stale error, no leftover warning admonition |
| 4 | Classic token creation end-to-end | ✅ Generate token → success screen → Copy → clipboard matched the shown token → confirm + Done |
| 5 | "create a legacy token" link on the review step (MCP tools section) | ✅ Jumps straight into classic mode, skipping back through the scoped form |
| 6 | Regression: scoped Project-scope creation | ✅ Review screen showed correct risk/scope/capabilities, Create token → success → clipboard verified |
| 7 | Regression: scoped Organization-scope creation | ✅ Same, correct risk/scope/capabilities, success → clipboard verified |
| 8 | Copy update on review screen | ✅ Reads "Token access can't be updated after creation" / "To change its access, delete this token and create a new one." — old "can't be edited"/"revoke" wording gone |
| 9 | Console errors | ✅ Zero errors before/after (one pre-existing unrelated warning throughout) |
Notes:
- Created 3 real access tokens on the test account during testing (
test-legacy-1,test-project-scope-2,test-org-scope-1) — left them in place, not revoked. - No projects/orgs created or deleted, reused the existing test org/project.
- No screenshots needed, everything passed cleanly.
joshenlim
left a comment
There was a problem hiding this comment.
Changes LGTM! Also manually verified on preview
Braintrust eval report
|
…for-pitr-archiving-stale * origin/master: (342 commits) feat(studio): role-aware access feedback in scoped token creation (#48858) Initialize notebook editor page (#48842) test(docs): scan changed pages for WCAG 2.1 A/AA in warn mode (#48727) docs(auth): clarify audit logs storage options and configuration (#48852) feat(studio): warn that scoped tokens don't support the MCP server (#48849) feat(studio): lifecycle and role-aware scoped token view sheet (#48848) feat(www): add Open Authorization Integration Addendum (#48804) feat(studio): add legacy token mode to scoped pat creation flow (#48844) Add blog post: Supabase is now a connector on Perplexity Computer (#48776) feat(studio): enforce expiry scoped pat (#48811) fix(studio): model scoped pat permissions as OR-of-AND alternatives - smaller version (#48809) fix(ui): opaque default button hover fills (#48837) fix(ui): restore normal alert text wrapping (#48840) feat: notebook content schema (#48813) fix(ui): remove extra spacing before custom reports section (#48796) feat(marketing): add hint text below Go page form labels (#48824) Initialize notebooks store (#48801) Use white wordmark for QA.tech primary logo (#48827) fix titleless Admonition alignment (#48784) fix inconsistent product menu dividers (#48787) ...
I have read the CONTRIBUTING.md file.
YES
What kind of change does this PR introduce?
Replaces the scoped form's inline account-level access mode with a proper legacy-token escape hatch: "Create legacy token" switches the sheet to the classic form (name + expiry only) and creates through the legacy endpoint, skipping the two-step review. Mirrors the mode-switch links in both directions and restores the "Generate token for experimental API" split-button dropdown, extracted into a shared ExperimentalTokenDropdown.
Ported from origin/w3b6x9/scoped-pat-ui-rework, excluding its expiry handling (shipped in #48811) and MCP-unsupported warnings (follow-up PR).
Summary by CodeRabbit
New Features
Improvements
Tests