Use /v1/me for CLI auth identity#40
Conversation
WalkthroughThis PR enriches auth state by adding a ChangesAuth credential field support
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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 |
|
Ran the updated Verdict: conditional pass. Findings:
File-size gate:
Validation limit:
|
|
Follow-up from
Validation run:
Validation note:
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/cli/tests/auth-ops.test.ts (1)
82-129: 🧹 Nitpick | 🔵 Trivial | 💤 Low valueConsider explicitly mocking
/v1/mefor fallback-path clarity.This test verifies the workspace-lookup fallback, but the mock (line 89–104) doesn't handle
/v1/me, so the code must throw and be caught internally. While the test passes, explicitly mocking/v1/meto returnnullor{ data: null }would make the fallback intent clearer and decouple the test from internal error-handling details.Example explicit fallback mock
const requireComputeAuth = vi.fn().mockResolvedValue({ GET: vi.fn().mockImplementation((pathName: string, request?: { params?: { path?: { id?: string } } }) => { + if (pathName === "/v1/me") { + return { data: null }; + } if (pathName === "/v1/workspaces/{id}" && request?.params?.path?.id === "cmmxlp7ae1251zyfs8mdpnavm") {🤖 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 `@packages/cli/tests/auth-ops.test.ts` around lines 82 - 129, Update the test's mocked requireComputeAuth GET handler used by readAuthState to explicitly handle the "/v1/me" endpoint (in addition to "/v1/workspaces/{id}") and return an explicit null response (e.g., null or { data: null }) so the workspace-lookup fallback path is clear; modify the vi.fn().mockImplementation for GET inside the requireComputeAuth mock to check for pathName === "/v1/me" and return the explicit null-shaped response before throwing for unexpected paths.packages/cli/src/lib/auth/auth-ops.ts (1)
46-55:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winPass the trimmed service token through the SDK path.
Line 48 normalizes
PRISMA_SERVICE_TOKEN, but Line 89 still builds the client from the originalenv. If the env var carries leading/trailing whitespace,/v1/meand/v1/workspaces/{id}will authenticate with a different value than the JWT fallback parses, soauth whoamican flip between signed-out and signed-in for the same token.Suggested fix
- return readServiceTokenAuthState(serviceToken, env); + return readServiceTokenAuthState(serviceToken, { + ...env, + [SERVICE_TOKEN_ENV_VAR]: serviceToken, + });Also applies to: 89-117
🤖 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 `@packages/cli/src/lib/auth/auth-ops.ts` around lines 46 - 55, The code trims PRISMA_SERVICE_TOKEN into rawServiceToken -> serviceToken but continues to build the SDK client from the original env (so whitespace in the env yields different auth behavior); update the SDK path to use the trimmed token by either assigning env[SERVICE_TOKEN_ENV_VAR] = serviceToken before constructing the client or by passing serviceToken directly into the client/auth builder (referencing SERVICE_TOKEN_ENV_VAR, rawServiceToken, serviceToken, and readServiceTokenAuthState) so both the JWT fallback and the SDK client use the identical trimmed token.
🤖 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.
Outside diff comments:
In `@packages/cli/src/lib/auth/auth-ops.ts`:
- Around line 46-55: The code trims PRISMA_SERVICE_TOKEN into rawServiceToken ->
serviceToken but continues to build the SDK client from the original env (so
whitespace in the env yields different auth behavior); update the SDK path to
use the trimmed token by either assigning env[SERVICE_TOKEN_ENV_VAR] =
serviceToken before constructing the client or by passing serviceToken directly
into the client/auth builder (referencing SERVICE_TOKEN_ENV_VAR,
rawServiceToken, serviceToken, and readServiceTokenAuthState) so both the JWT
fallback and the SDK client use the identical trimmed token.
In `@packages/cli/tests/auth-ops.test.ts`:
- Around line 82-129: Update the test's mocked requireComputeAuth GET handler
used by readAuthState to explicitly handle the "/v1/me" endpoint (in addition to
"/v1/workspaces/{id}") and return an explicit null response (e.g., null or {
data: null }) so the workspace-lookup fallback path is clear; modify the
vi.fn().mockImplementation for GET inside the requireComputeAuth mock to check
for pathName === "/v1/me" and return the explicit null-shaped response before
throwing for unexpected paths.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8f0af90d-ef27-45cd-932e-4fa499f56372
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (11)
docs/product/command-spec.mdpackages/cli/package.jsonpackages/cli/src/lib/auth/auth-ops.tspackages/cli/src/presenters/auth.tspackages/cli/src/types/auth.tspackages/cli/src/use-cases/auth.tspackages/cli/tests/auth-ops.test.tspackages/cli/tests/auth-real-mode.test.tspackages/cli/tests/auth-usecases.test.tspackages/cli/tests/auth.test.tspackages/cli/tests/project-usecases.test.ts
Summary
Updates
auth whoamito resolve the signed-in identity through the Management API/v1/meendpoint.@prisma/management-api-sdkto^1.34.0, which includes/v1/me/v1/mefor stored OAuth sessions andPRISMA_SERVICE_TOKENsessionsuser: email@example.comuser: <service token: name>oruser: <service token>user,workspace, andcredentialin JSON outputValidation
pnpm --filter @prisma/cli exec vitest run tests/auth-ops.test.ts tests/auth-real-mode.test.ts tests/auth-usecases.test.ts tests/auth.test.ts tests/project-usecases.test.tspnpm --filter @prisma/cli testgit diff --checkNotes
The Management API PR has landed and
@prisma/management-api-sdk@1.34.0has been published, so this PR now consumes the generated/v1/meSDK types directly.