Skip to content

fix(types): improve integration type inference and coverage - #256

Merged
halvaradop merged 13 commits into
masterfrom
fix/improve-type-inference
Aug 10, 2026
Merged

halvaradop merged 13 commits into
masterfrom
fix/improve-type-inference

Conversation

@halvaradop

@halvaradop halvaradop commented Aug 10, 2026

Copy link
Copy Markdown
Member

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 as identity.schema and signUp.schema. Previously, these types were not propagated correctly through the framework-specific integrations, causing utility types such as InferUser, InferSession, and InferSignUp to 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

  • Added dedicated Auth Instance types for framework integrations:
    • HonoInstance
    • ExpressInstance
    • ElysiaInstance
    • NextPagesInstance
    • NextAppInstance
    • OakInstance
    • ReactRouterInstance
  • Fixed InferUser type inference in the core package and framework integrations.
  • Fixed InferSession type inference in the core package and framework integrations.
  • Reworked InferSignUp inference for framework integrations.
  • Improved propagation of identity.schema types across Auth Instances.
  • Improved propagation of signUp.schema types across Auth Instances.
  • Ensured sign-up payloads are inferred from the configured schema instead of falling back to generic types.

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 InferSignUp implementations were introduced for each framework integration. This provides correct inference while keeping the framework-specific APIs accurately represented in their respective packages.

@coderabbitai ignore

@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
auth Skipped Skipped Aug 10, 2026 8:49pm

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@halvaradop, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 55256e76-58ed-4897-b650-991be9063605

📥 Commits

Reviewing files that changed from the base of the PR and between 045a992 and 893df3c.

📒 Files selected for processing (7)
  • packages/device/vitest.config.ts
  • packages/express/vitest.config.ts
  • packages/hono/vitest.config.ts
  • packages/next/vitest.config.ts
  • packages/react-router/package.json
  • packages/react-router/vitest.config.ts
  • packages/react/vitest.config.ts
📝 Walkthrough

Walkthrough

The 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.

Changes

Core inference

Layer / File(s) Summary
Core inference contracts
packages/core/src/@types/utility.ts, packages/core/test/*
InferUser, InferSession, and InferSignUp now support nested framework configurations and prettified schema inference. Type tests cover custom identities and sign-up schemas.

Framework integrations

Layer / File(s) Summary
Elysia, Express, and Hono typing
packages/elysia/src/..., packages/express/src/..., packages/hono/src/..., packages/*/test/*
Framework instances, factories, middleware, handlers, and APIs now propagate user and sign-up schema generics.
Oak typing
packages/oak/src/..., packages/oak/test/*
Oak authentication types, handlers, middleware, and factories now preserve identity and sign-up schema types.
Next.js typing
packages/next/src/..., packages/next/test/*
Next.js app and pages instances now expose schema-aware handlers and typed session, refresh-user-info, and sign-up APIs.
React Router typing
packages/react-router/src/..., packages/react-router/test/*
React Router APIs now derive sign-up payloads from configured schemas and propagate those schemas through authentication instances.

Validation and support

Layer / File(s) Summary
Framework type-checking rollout
packages/*/package.json, packages/*/vitest.config.ts, packages/oak/deno.json, packages/oak/tsconfig.json
Package scripts and test configurations now run Vitest or Deno declaration-file type checks.
Generated route formatting
.oxfmtrc.json, apps/tanstack-start/src/routeTree.gen.ts
The generated TanStack route tree was reformatted, and the formatter now ignores the generated file.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested labels: enhancement, refactor

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the pull request's main changes: improved integration type inference and expanded type-test coverage.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/improve-type-inference

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1c76888 and 885f924.

📒 Files selected for processing (46)
  • packages/core/package.json
  • packages/core/src/@types/utility.ts
  • packages/core/test/identity.test.ts
  • packages/core/vitest.config.ts
  • packages/elysia/package.json
  • packages/elysia/src/@types/index.ts
  • packages/elysia/src/createAuth.ts
  • packages/elysia/test/types.test-d.ts
  • packages/elysia/vitest.config.ts
  • packages/express/package.json
  • packages/express/src/@types/index.ts
  • packages/express/src/createAuth.ts
  • packages/express/src/lib/with-auth.ts
  • packages/express/test/types.test-d.ts
  • packages/express/vitest.config.ts
  • packages/hono/package.json
  • packages/hono/src/@types/index.ts
  • packages/hono/src/createAuth.ts
  • packages/hono/src/lib/handler.ts
  • packages/hono/src/lib/with-auth.ts
  • packages/hono/test/types.test-d.ts
  • packages/hono/vitest.config.ts
  • packages/next/package.json
  • packages/next/src/@types/api.ts
  • packages/next/src/@types/index.ts
  • packages/next/src/createAuth.ts
  • packages/next/src/lib/api.ts
  • packages/next/test/types.test-d.ts
  • packages/next/vitest.config.ts
  • packages/oak/package.json
  • packages/oak/src/createAuth.ts
  • packages/oak/src/lib/handler.ts
  • packages/oak/src/lib/with-auth.ts
  • packages/oak/src/types/index.ts
  • packages/oak/test/types.test-d.ts
  • packages/oak/vitest.config.ts
  • packages/react-router/CHANGELOG.md
  • packages/react-router/package.json
  • packages/react-router/src/@types/api.ts
  • packages/react-router/src/@types/index.ts
  • packages/react-router/src/createAuth.ts
  • packages/react-router/src/lib/api.ts
  • packages/react-router/test/types.test-d.ts
  • packages/react-router/vitest.config.ts
  • packages/react/package.json
  • packages/react/vitest.config.ts

Comment thread packages/core/test/identity.test.ts Outdated
Comment thread packages/core/test/identity.test.ts Outdated
Comment thread packages/elysia/test/types.test-d.ts
Comment thread packages/hono/test/types.test-d.ts
Comment thread packages/next/src/lib/api.ts
Comment thread packages/next/test/app-router/types.test-d.ts
Comment thread packages/oak/test/types.test-d.ts Outdated
Comment thread packages/react-router/src/lib/api.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 885f924 and 6bf8ade.

⛔ Files ignored due to path filters (3)
  • bun.lock is excluded by !**/*.lock
  • deno.lock is excluded by !**/*.lock
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • packages/core/test/identity.test.ts
  • packages/core/test/instance.test-d.ts
  • packages/elysia/test/types.test-d.ts
  • packages/express/test/types.test-d.ts
  • packages/hono/test/types.test-d.ts
  • packages/next/src/@types/api.ts
  • packages/next/test/types.test-d.ts
  • packages/oak/deno.json
  • packages/oak/package.json
  • packages/oak/src/createAuth.ts
  • packages/oak/test/types.test-d.ts
  • packages/oak/tsconfig.json
  • packages/react-router/src/lib/api.ts
  • packages/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

Comment thread packages/core/test/instance.test-d.ts Outdated
Comment thread packages/core/test/instance.test-d.ts
Comment thread packages/oak/deno.json

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6bf8ade and 045a992.

📒 Files selected for processing (22)
  • .oxfmtrc.json
  • apps/tanstack-start/src/routeTree.gen.ts
  • packages/core/src/@types/utility.ts
  • packages/core/test/instance.test-d.ts
  • packages/elysia/src/@types/index.ts
  • packages/elysia/src/createAuth.ts
  • packages/elysia/src/lib/with-auth.ts
  • packages/express/src/@types/index.ts
  • packages/express/src/createAuth.ts
  • packages/express/test/types.test-d.ts
  • packages/hono/src/@types/index.ts
  • packages/hono/src/createAuth.ts
  • packages/next/src/@types/index.ts
  • packages/next/src/createAuth.ts
  • packages/next/src/pages/createAuth.ts
  • packages/next/src/pages/handler.ts
  • packages/next/test/app-router/types.test-d.ts
  • packages/next/test/pages-router/types.test-d.ts
  • packages/oak/src/types/index.ts
  • packages/react-router/src/@types/index.ts
  • packages/react-router/test/types.test-d.ts
  • packages/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

Comment thread packages/core/src/@types/utility.ts
Comment thread packages/next/src/pages/handler.ts
@halvaradop
halvaradop merged commit 7cbbef0 into master Aug 10, 2026
7 checks passed
@halvaradop
halvaradop deleted the fix/improve-type-inference branch August 10, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant