fix: add Token Lifetime selector to Access Keys page#1084
fix: add Token Lifetime selector to Access Keys page#1084jeremyeder merged 4 commits intoambient-code:mainfrom
Conversation
The create key dialog was missing the expiration selector, causing all tokens to default to 1-hour expiration. Add a Token Lifetime dropdown with options from 1 day to no expiration (default: 90 days). Also remove dead KeysSection component that was never rendered. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughRemoves the KeysSection UI and its tests/exports, adds a "Token Lifetime" select to the project keys page that conditionally sends Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@components/frontend/src/app/projects/`[name]/keys/page.tsx:
- Around line 75-76: Reset the new key expiration whenever the create dialog is
closed (both on success and on cancel/close) rather than only after successful
creation: ensure any close handler that calls setShowCreate(false) also calls
setNewKeyExpiration(DEFAULT_EXPIRATION) (or add a centralized onClose function
used by both the success path and the cancel/close UI) so the component state
(setNewKeyExpiration and DEFAULT_EXPIRATION) is restored whenever the dialog is
dismissed.
🪄 Autofix (Beta)
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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 48cc6f2d-9bff-4f24-848b-af8ad9ad7d04
📒 Files selected for processing (6)
.gitignorecomponents/frontend/src/app/projects/[name]/keys/page.tsxcomponents/frontend/src/components/workspace-sections/__tests__/keys-section.test.tsxcomponents/frontend/src/components/workspace-sections/index.tscomponents/frontend/src/components/workspace-sections/keys-section.tsxcomponents/runners/ambient-runner/tests/test_shared_session_credentials.py
💤 Files with no reviewable changes (3)
- components/frontend/src/components/workspace-sections/index.ts
- components/frontend/src/components/workspace-sections/keys-section.tsx
- components/frontend/src/components/workspace-sections/tests/keys-section.test.tsx
| setNewKeyExpiration(DEFAULT_EXPIRATION); | ||
| setShowCreate(false); |
There was a problem hiding this comment.
Reset token lifetime when the dialog closes, not only on success
Line 75 resets the lifetime only after a successful create. If a user selects No expiration and closes/cancels, reopening can retain that prior value, increasing risk of accidentally creating long-lived keys.
Proposed fix
+ const handleCreateDialogOpenChange = useCallback((open: boolean) => {
+ setShowCreate(open);
+ if (!open) {
+ setNewKeyExpiration(DEFAULT_EXPIRATION);
+ }
+ }, []);
+
{/* Create Key Dialog */}
- <Dialog open={showCreate} onOpenChange={setShowCreate}>
+ <Dialog open={showCreate} onOpenChange={handleCreateDialogOpenChange}>
<DialogContent className="sm:max-w-[425px]">
...
<Button
variant="outline"
- onClick={() => setShowCreate(false)}
+ onClick={() => handleCreateDialogOpenChange(false)}
disabled={createKeyMutation.isPending}
>As per coding guidelines, "Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@components/frontend/src/app/projects/`[name]/keys/page.tsx around lines 75 -
76, Reset the new key expiration whenever the create dialog is closed (both on
success and on cancel/close) rather than only after successful creation: ensure
any close handler that calls setShowCreate(false) also calls
setNewKeyExpiration(DEFAULT_EXPIRATION) (or add a centralized onClose function
used by both the success path and the cancel/close UI) so the component state
(setNewKeyExpiration and DEFAULT_EXPIRATION) is restored whenever the dialog is
dismissed.
Addressing PR FeedbackFound 2 unaddressed item(s):
🤖 Prompt for all review comments with AI agents |
✅ Actions performedReview triggered.
|
Summary
/projects/[name]/keyswith 6 options (1 day, 7 days, 30 days, 90 days, 1 year, no expiration; default: 90 days)expirationSecondsto the backend API when creating keys — previously all tokens defaulted to 1-hour expirationKeysSectioncomponent and its tests (never imported or rendered anywhere).worktrees/to.gitignoreTest plan
npm run buildpasses (0 errors, 0 warnings)npx vitest runpasses (no regressions from deleted tests)/projects/<name>/keys, click Create Key, confirm Token Lifetime dropdown appears with 6 options defaulting to 90 daysexpirationSecondsis sent in the API requestexpirationSecondsis omitted from the request🤖 Generated with Claude Code