fix(types): improve integration type inference and coverage - #256
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Warning Review limit reached
Next review available in: 44 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThe PR updates core and framework authentication types to propagate custom identity and sign-up schemas. It adds inferred API contracts, framework instance types, declaration tests, and Vitest type-checking scripts and configurations. ChangesCore inference
Framework integrations
Validation and support
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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: 8
🤖 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 `@packages/core/test/identity.test.ts`:
- Around line 579-672: Ensure the new inference assertions in
packages/core/test/identity.test.ts (lines 579-672) run under Vitest typecheck
mode by moving them into an appropriate *.test-d.ts file, or update
packages/core/vitest.config.ts (lines 34-36) so test.typecheck.include also
covers identity.test.ts; preserve all existing assertions and runtime test
behavior.
- Line 592: Remove the duplicate Identity type alias in identity.test.ts,
keeping the declaration whose shape matches the intended identity structure and
deleting the other same-scope declaration to eliminate the TypeScript duplicate
identifier.
In `@packages/elysia/test/types.test-d.ts`:
- Around line 90-92: Update the api.signUp type assertions in
packages/elysia/test/types.test-d.ts:90-92 and
packages/express/test/types.test-d.ts:90-92 to pass each test’s explicit custom
sign-up payload type to SignUpAPIOptions instead of Record<string, any>,
ensuring the configured schema type is preserved.
In `@packages/hono/test/types.test-d.ts`:
- Around line 90-92: Update the api.signUp type assertion in the “api.signUp”
test to expect InferSignUp<typeof auth> instead of
SignUpAPIOptions<Record<string, any>>, ensuring the configured schema from the
auth setup is propagated. If the assertion fails, correct the production
api.signUp type path rather than weakening the test.
In `@packages/next/src/lib/api.ts`:
- Around line 199-201: Update the exported api function’s signUp exposure so it
preserves the SignUpSchema generic from api<DefaultUser, SignUpSchema>. In the
api implementation, type signUp with SignUpSchema and construct it through
signUp<DefaultUser, SignUpSchema>(config), keeping the existing DefaultUser
generic intact.
In `@packages/next/test/types.test-d.ts`:
- Around line 44-83: Replace the commented auth.api.signUp test in the custom
schema describe block with type assertions for valid and invalid payloads, using
the schema fields nickname, email, and password. Verify a complete payload is
accepted and payloads missing any required field are rejected, so
auth.api.signUp enforces the sign-up schema.
In `@packages/oak/test/types.test-d.ts`:
- Around line 90-92: The api.signUp type assertion currently uses the broad
Record<string, any> type, so it does not verify custom schema propagation.
Update the Parameters<typeof api.signUp>[0] assertion in the “api.signUp” test
to expect the concrete payload containing nickname, email, and password with
their defined types.
In `@packages/react-router/src/lib/api.ts`:
- Around line 123-129: Update the exported signUp helper’s AuthInstance generic
to include and capture its configured SignUpSchema, then use that instance-bound
schema type for the api.signUp payload and related
ReactRouterSignUpAPIOptions/ReactRouterSignUpReturn types instead of allowing a
separate caller-provided schema generic.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 45ddec6c-efd0-4003-90e6-3a6b8ea46ab1
📒 Files selected for processing (46)
packages/core/package.jsonpackages/core/src/@types/utility.tspackages/core/test/identity.test.tspackages/core/vitest.config.tspackages/elysia/package.jsonpackages/elysia/src/@types/index.tspackages/elysia/src/createAuth.tspackages/elysia/test/types.test-d.tspackages/elysia/vitest.config.tspackages/express/package.jsonpackages/express/src/@types/index.tspackages/express/src/createAuth.tspackages/express/src/lib/with-auth.tspackages/express/test/types.test-d.tspackages/express/vitest.config.tspackages/hono/package.jsonpackages/hono/src/@types/index.tspackages/hono/src/createAuth.tspackages/hono/src/lib/handler.tspackages/hono/src/lib/with-auth.tspackages/hono/test/types.test-d.tspackages/hono/vitest.config.tspackages/next/package.jsonpackages/next/src/@types/api.tspackages/next/src/@types/index.tspackages/next/src/createAuth.tspackages/next/src/lib/api.tspackages/next/test/types.test-d.tspackages/next/vitest.config.tspackages/oak/package.jsonpackages/oak/src/createAuth.tspackages/oak/src/lib/handler.tspackages/oak/src/lib/with-auth.tspackages/oak/src/types/index.tspackages/oak/test/types.test-d.tspackages/oak/vitest.config.tspackages/react-router/CHANGELOG.mdpackages/react-router/package.jsonpackages/react-router/src/@types/api.tspackages/react-router/src/@types/index.tspackages/react-router/src/createAuth.tspackages/react-router/src/lib/api.tspackages/react-router/test/types.test-d.tspackages/react-router/vitest.config.tspackages/react/package.jsonpackages/react/vitest.config.ts
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@packages/core/test/instance.test-d.ts`:
- Line 30: Update the type assertion in the InferUser test to compare against
Wrap<Identity> rather than deriving both sides from InferUser<typeof auth>,
ensuring the concrete custom identity shape, including role and nickname, is
validated.
- Around line 94-100: The api.signUp type tests must constrain options to the
configured schema instead of permissive Record<string, any>. In
packages/core/test/instance.test-d.ts:94-100 and
packages/elysia/test/types.test-d.ts:98-102, update the expected parameter type
to SignUpAPIOptions<InferSignUp<typeof auth>> and add rejection coverage proving
payloads that omit configured required fields such as password are rejected.
In `@packages/oak/deno.json`:
- Line 10: Update the Oak type-test setup by renaming types.test-d.ts to
types.test.ts, adding `@ts-check` to the renamed test file, and removing
--no-check from the test:types command in deno.json so Deno type-checks the
existing assertions and executable test content.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c30a1191-d603-4d1a-83f0-291865a93402
⛔ Files ignored due to path filters (3)
bun.lockis excluded by!**/*.lockdeno.lockis excluded by!**/*.lockpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (14)
packages/core/test/identity.test.tspackages/core/test/instance.test-d.tspackages/elysia/test/types.test-d.tspackages/express/test/types.test-d.tspackages/hono/test/types.test-d.tspackages/next/src/@types/api.tspackages/next/test/types.test-d.tspackages/oak/deno.jsonpackages/oak/package.jsonpackages/oak/src/createAuth.tspackages/oak/test/types.test-d.tspackages/oak/tsconfig.jsonpackages/react-router/src/lib/api.tspackages/react-router/test/types.test-d.ts
💤 Files with no reviewable changes (2)
- packages/oak/package.json
- packages/core/test/identity.test.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- packages/react-router/test/types.test-d.ts
- packages/oak/src/createAuth.ts
- packages/hono/test/types.test-d.ts
- packages/react-router/src/lib/api.ts
- packages/express/test/types.test-d.ts
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@packages/core/src/`@types/utility.ts:
- Around line 127-134: Update the AuthInstance conditional types in InferUser,
including the nested core branch, to match and infer both AuthInstance generic
parameters (DefaultUser and SignUpSchema). Preserve the existing identity merge
and User fallback behavior so non-Zod auth instances infer their user type
correctly and InferSession receives the expected result.
In `@packages/next/src/pages/handler.ts`:
- Around line 36-38: The toHandler signature currently requires an AuthInstance
even though the documented API passes auth.handlers directly, leaving the
destructured handlers undefined. Update toHandler to accept and normalize either
an AuthInstance or a handlers object while preserving the existing route-handler
behavior, and add a regression test covering toHandler(auth.handlers).
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 53ca7526-708a-443d-9fd2-d8054d0b842c
📒 Files selected for processing (22)
.oxfmtrc.jsonapps/tanstack-start/src/routeTree.gen.tspackages/core/src/@types/utility.tspackages/core/test/instance.test-d.tspackages/elysia/src/@types/index.tspackages/elysia/src/createAuth.tspackages/elysia/src/lib/with-auth.tspackages/express/src/@types/index.tspackages/express/src/createAuth.tspackages/express/test/types.test-d.tspackages/hono/src/@types/index.tspackages/hono/src/createAuth.tspackages/next/src/@types/index.tspackages/next/src/createAuth.tspackages/next/src/pages/createAuth.tspackages/next/src/pages/handler.tspackages/next/test/app-router/types.test-d.tspackages/next/test/pages-router/types.test-d.tspackages/oak/src/types/index.tspackages/react-router/src/@types/index.tspackages/react-router/test/types.test-d.tspackages/react/package.json
🚧 Files skipped from review as they are similar to previous changes (6)
- packages/express/test/types.test-d.ts
- packages/hono/src/@types/index.ts
- packages/react/package.json
- packages/core/test/instance.test-d.ts
- packages/react-router/test/types.test-d.ts
- packages/next/src/createAuth.ts
Description
This pull request improves and fixes type inference across the Aura Auth framework integrations by correctly propagating the types defined through the
createAuth()server-side auth instance.The
createAuth()function accepts generic types for configuration options such asidentity.schemaandsignUp.schema. Previously, these types were not propagated correctly through the framework-specific integrations, causing utility types such asInferUser,InferSession, andInferSignUpto produce incorrect or incomplete results.This PR addresses these inference issues and ensures that the configured schemas are correctly reflected throughout the authentication instance and its framework integrations.
As a result, sign-up payloads, users, and sessions are now inferred more accurately from the schemas configured in
createAuth().Key Changes
HonoInstanceExpressInstanceElysiaInstanceNextPagesInstanceNextAppInstanceOakInstanceReactRouterInstanceInferUsertype inference in the core package and framework integrations.InferSessiontype inference in the core package and framework integrations.InferSignUpinference for framework integrations.identity.schematypes across Auth Instances.signUp.schematypes across Auth Instances.Note
The initial approach was to solve the inference issues entirely through the core utility types. However, the framework integrations have different Auth Instance shapes and additional framework-specific APIs, so the core-only approach was not sufficient.
As a temporary solution, dedicated Auth Instance types and
InferSignUpimplementations were introduced for each framework integration. This provides correct inference while keeping the framework-specific APIs accurately represented in their respective packages.@coderabbitai ignore