-
Notifications
You must be signed in to change notification settings - Fork 55
feat: added FPApiToken decode without verify #1617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds a new async Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 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)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@core/protocols/dashboard/token.ts`:
- Around line 128-136: The decode method in token.ts calls decodeJwt which can
throw on malformed tokens; wrap the decodeJwt call with exception2Result so that
exceptions are converted into a Result.Err instead of an unhandled rejection.
Update the async decode(token: string) in the token.ts file to use
exception2Result(() => decodeJwt(token)) (or equivalent) and handle the Result
to return Result.Ok({...}) on success or propagate/return Result.Err on failure;
reference the decode function and decodeJwt and use the same exception2Result
helper pattern used in ClerkApiToken.decode.
- Around line 50-61: In decode, wrap the call to decodeJwt in the same
exception-to-Result pattern used by verify (use exception2Result or equivalent)
so malformed tokens return Result.Err instead of throwing, and adjust the value
passed to FPClerkClaimSchema.safeParse to match the schema shape (wrap the
decoded payload as { payload: decodedPayload } and include protectedHeader if
required); if the header is needed, obtain it with decodeProtectedHeader or use
jwtDecode(..., { complete: true }) before parsing — mirror how
verify/verifyToken constructs and parses the object so
FPClerkClaimSchema.safeParse succeeds.
🧹 Nitpick comments (1)
dashboard/backend/tests/auth-handler.test.ts (1)
51-58: No test exercises the newdecodepath.The mock is added to satisfy the interface, but there's no test case that actually calls
decode. Consider adding a test to verify the decode-without-verify behavior, especially since it's the feature being introduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@core/tests/protocols/dashboard/clerk-dash-api.test.ts`:
- Around line 129-158: The test uses a hardcoded real JWT with PII; replace it
with a synthetic token constructed at test runtime (not committed) that has fake
claims so ClerkApiToken.decode(clerkToken) still parses structure: create a
minimal unsigned/signed JWT via jose.SignJWT or by base64url-encoding a fake
header and payload (claims like email: "test@example.com", name: "Test User",
userId: "test_user", image_url: "https://example.com/img.png") and a dummy
signature, assign it to the clerkToken variable, then run the same assertions
against the synthetic claims so the test verifies decode() behavior without
exposing real PII.
🧹 Nitpick comments (2)
core/tests/protocols/dashboard/clerk-dash-api.test.ts (2)
163-166: Casting{} as DeviceIdCAis acceptable here sincedecodenever touches it.This works for the decode-only test path, but consider adding a brief comment (e.g.,
// unused by decode()) so future readers don't wonder if this is a bug.
126-127:ensureSuperThis()called at describe-block scope — works but is unconventional.Typically test scaffolding is set up inside
beforeAll/beforeEach. SinceensureSuperThis()is synchronous, this works fine here. Just noting for awareness — if it ever becomes async or has side effects that need teardown, this would need to move.
Summary by CodeRabbit