Skip to content

fix(core): fix type inference across auth actions#190

Merged
halvaradop merged 3 commits into
masterfrom
fix/type-infer-across-auth
Jun 17, 2026
Merged

fix(core): fix type inference across auth actions#190
halvaradop merged 3 commits into
masterfrom
fix/type-infer-across-auth

Conversation

@halvaradop

@halvaradop halvaradop commented Jun 17, 2026

Copy link
Copy Markdown
Member

Description

This pull request fixes type inference issues affecting authentication actions such as updateSession and signUp.

The issue caused incorrect type inference in both createAuth() and createAuthClient(), resulting in improperly typed payloads and action parameters in certain configurations.

The root cause was incorrect type inference from the identity.schema and signUp.schema configuration options. These schemas are used to validate incoming payloads and should also drive the inferred types exposed by the authentication APIs. However, the inferred types were not being propagated correctly, leading to inconsistencies between the configured schemas and the generated API types.

@vercel

vercel Bot commented Jun 17, 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 Jun 17, 2026 10:42pm

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

More reviews will be available in 35 minutes and 52 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

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

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 05135dff-0c5a-4788-9adb-258aee43a767

📥 Commits

Reviewing files that changed from the base of the PR and between 9fd5ce3 and dba230f.

📒 Files selected for processing (4)
  • packages/core/CHANGELOG.md
  • packages/core/src/@types/utility.ts
  • packages/core/src/actions/signUp/signUp.ts
  • packages/core/test/client/client.test-d.ts
📝 Walkthrough

Walkthrough

Introduces four new type utilities (EditableToSchema, ReturnUpdateSessionShape, InferSignUp, RemoveIndexSignature) to utility.ts, strengthens generics on getFullSchema, signUpAction, and updateSessionAction, wires explicit type parameters through createAuth, removes stale @ts-ignore suppressions in client.ts, and adds a 366-line type-declaration test suite.

Changes

Type inference for signUp and updateSession

Layer / File(s) Summary
New schema conversion and sign-up inference type utilities
packages/core/src/@types/utility.ts, packages/core/src/api/createApi.ts
EditableToSchema<T>, ReturnUpdateSessionShape<T>, InferSignUp<Config>, and RemoveIndexSignature<T> are added to utility.ts. RemoveIndexSignature is removed from its inline definition in createApi.ts and replaced with an import from the shared types module.
Strengthen getFullSchema generics and return type
packages/core/src/validator/registry.ts
getFullSchema signature changes from (schema: Schema): any to <Identity extends Identities, Schema = EditableToSchema<Identity>>(schema: Schema): ReturnUpdateSessionShape<Schema>. TypeBox and Zod return branches are cast accordingly.
Propagate identity generics into signUpAction and updateSessionAction
packages/core/src/actions/signUp/signUp.ts, packages/core/src/actions/updateSession/updateSession.ts
signUpAction becomes generic over Identity and SignUpSchema instead of any. updateSessionAction's config is generic over Identity extends Identities and calls getFullSchema<Identity>. Session body construction is simplified to pass ctx.body as any directly.
Wire typed generics in createAuth and clean up @ts-ignore in client
packages/core/src/createAuth.ts, packages/core/src/client/client.ts
createAuth instantiates signUpAction<Identity, SignUpSchema>(...) explicitly. Three @ts-ignore comments are removed from signInCredentials, signUp, and signOut in client.ts; one remaining suppression in updateSession is repositioned.
Type-declaration tests for createAuthClient inference
packages/core/test/client/client.test-d.ts
New test file with expectTypeOf assertions for default method signatures and identity/sign-up schema inference across Zod, Valibot, Arktype, and TypeBox.
Changelog
packages/core/CHANGELOG.md
Unreleased section records the signUp.schema type inference fix and standardized AuraAuthError error structure.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • aura-stack-ts/auth#161: Modifies packages/core/src/@types/utility.ts to extend core type utilities with ArkType mappings, directly at the same type layer this PR extends with InferSignUp and EditableToSchema.
  • aura-stack-ts/auth#183: Extends InferSignUp/RemoveIndexSignature utilities and the typed signUpAction/createAuthAPI.signUp surface that this PR further refines.
  • aura-stack-ts/auth#162: Introduces and expands getFullSchema and the schema registry typing that this PR strengthens with identity-driven generics and ReturnUpdateSessionShape.

Suggested labels

refactor

🐇 New types emerge from the warren,
InferSignUp sniffs out each schema pattern,
@ts-ignores hop away, one by one,
Generics bloom where any once spun,
Type safety at last — the burrow is done! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the pull request: fixing type inference issues across authentication actions and related utilities.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/type-infer-across-auth

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 and usage tips.

@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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/src/validator/registry.ts (1)

123-157: ⚠️ Potential issue | 🟠 Major

Add .optional() to user in all getFullSchema runtime builders to match return type.

ReturnUpdateSessionShape declares user? as optional for all four schema types (Zod, Valibot, ArkType, TypeBox), but each runtime builder currently constructs user: schema as required. This allows optional-user payloads to type-check while failing validation at runtime.

Proposed fix
 if (isValibotSchema(schema)) {
     return valibot.object({
-        user: schema,
+        user: valibot.optional(schema as valibot.BaseSchema<any, any, any>),
         expires: valibot.optional(
             valibot.pipe(
                 valibot.string(),
                 valibot.transform((input) => new Date(input)),
                 valibot.date()
             )
         ),
     })
 }
 if (isArkType(schema)) {
     return type({
-        user: schema,
+        user: schema.optional(),
         expires: type("string")
             .pipe((input) => new Date(input))
             .optional(),
     })
 }
 if (IsObject(schema)) {
     return Typebox.Object({
-        user: schema,
+        user: Typebox.Optional(schema),
         expires: Typebox.Optional(Typebox.String()),
     }) as unknown as ReturnUpdateSessionShape<Schema>
 }
 if (isZodSchema(schema)) {
     return z.object({
-        user: schema,
+        user: schema.optional(),
         expires: z.coerce.date().optional(),
     }) as unknown as ReturnUpdateSessionShape<Schema>
 }
🤖 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/core/src/validator/registry.ts` around lines 123 - 157, The user
field in all four runtime schema builders (isValibotSchema, isArkType, IsObject
for TypeBox, and isZodSchema) is currently defined as required, but the return
type ReturnUpdateSessionShape declares user as optional. Add the appropriate
optional wrapper to the user field in each builder to match the return type:
wrap the user property with valibot.optional() in the Valibot builder,
.optional() in the ArkType builder, Typebox.Optional() in the TypeBox builder,
and z.optional() in the Zod builder.
🧹 Nitpick comments (3)
packages/core/src/actions/signUp/signUp.ts (1)

31-32: ⚡ Quick win

Replace bare @ts-ignore with a scoped @ts-expect-error (or remove it).

This suppression is too broad and can hide unrelated typing regressions in this block. Prefer @ts-expect-error with a short reason so it fails closed when the underlying typing issue is fixed.

Suggested change
-            // `@ts-ignore` - Type excessively expensive to compute.
+            // `@ts-expect-error` - Deep generic inference with router body type is currently too expensive.
             const payload = ctx.body as any
🤖 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/core/src/actions/signUp/signUp.ts` around lines 31 - 32, Replace the
bare `@ts-ignore` comment on the payload variable declaration with
`@ts-expect-error` and include a specific reason for the suppression (in this
case, explaining that the typing calculation is too expensive). The
`@ts-expect-error` directive is more scoped than `@ts-ignore` and will fail to
compile if the underlying typing issue is resolved, preventing accidental
regressions. Update the comment from `@ts-ignore` - Type excessively expensive to
compute to `@ts-expect-error` Type excessively expensive to compute or similar
format that clearly documents why the type assertion is needed.
packages/core/src/client/client.ts (1)

174-176: ⚡ Quick win

Use @ts-expect-error instead of unscoped @ts-ignore in signUp.

This is currently unbounded suppression. Switching to @ts-expect-error (with reason) preserves intent and prevents silently hiding future typing regressions.

🤖 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/core/src/client/client.ts` around lines 174 - 176, Replace the `//
`@ts-ignore`` comment on the line before the `client.post("/signUp", ...)` call
with `// `@ts-expect-error`` followed by a brief reason explaining why the
TypeScript error is expected at that location. This change from unbounded
suppression to scoped error expectation prevents masking future typing issues
and maintains clarity about intentional type mismatches.
packages/core/src/validator/registry.ts (1)

120-122: ⚡ Quick win

Constrain Schema to SchemaTypes to preserve the API contract.

The current signature allows Schema to be inferred as non-schema types; those calls only fail at runtime. Constraining Schema keeps this safeguard at compile time.

Proposed refactor
-export const getFullSchema = <Identity extends Identities, Schema = EditableToSchema<Identity>>(
+export const getFullSchema = <Identity extends Identities, Schema extends SchemaTypes = EditableToSchema<Identity>>(
     schema: Schema
 ): ReturnUpdateSessionShape<Schema> => {
🤖 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/core/src/validator/registry.ts` around lines 120 - 122, The
`getFullSchema` generic function has an unconstrained `Schema` type parameter
that allows non-schema types to be passed, causing type errors only at runtime.
Add a constraint to the `Schema` generic parameter in the `getFullSchema`
function signature by extending it to `SchemaTypes`. This constraint should be
applied to the `Schema` generic parameter (the one with default value
`EditableToSchema<Identity>`) to ensure type safety at compile time and preserve
the API contract.
🤖 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/CHANGELOG.md`:
- Around line 21-25: Update the PR references in the CHANGELOG.md Unreleased
section from `#189` to `#190` in both the Fixed and Changed entries. The two entries
about type inference for authentication actions with createAuth() and
createAuthClient(), and error handling standardization with AuraAuthError,
currently link to the wrong PR number. Change all occurrences of [`#189`] to
[`#190`] in these two bullet points to ensure accurate changelog traceability.

In `@packages/core/src/`@types/utility.ts:
- Around line 95-98: The ReturnUpdateSessionShape type has a type-runtime
mismatch for the expires field. Currently, the expires field is typed as
ZodOptional<ZodString>, but the runtime builder (getFullSchema) actually creates
z.coerce.date().optional(), which coerces the string to a Date. To fix this,
change the expires field declaration from ZodOptional<ZodString> to
ZodOptional<ZodTypeAny> to accurately reflect the actual schema produced at
runtime and match the behavior of other schema validators like Valibot, ArkType,
and Typebox.

In `@packages/core/src/actions/updateSession/updateSession.ts`:
- Around line 8-11: Make the `updateSessionAction` function itself generic by
adding an `Identity extends Identities` type parameter to match the pattern
already successfully implemented in `signUpAction`. This will allow the concrete
`Identity` type to be preserved and inferred at the call site in
`createAuthInstance`, enabling proper identity-driven type inference for
update-session payloads. Update the function signature of `updateSessionAction`
to accept the generic `Identity` parameter and pass it through to the `config`
function so the type information flows correctly through the entire call chain.

In `@packages/core/test/client/client.test-d.ts`:
- Around line 328-333: The test name on line 328 contains "arktype" but the test
is actually using a TypeBox schema as shown by the typebox.Type usage. Change
the test description string from "with custom arktype signUp schema" to "with
custom typebox signUp schema" to accurately reflect what the test is validating.

---

Outside diff comments:
In `@packages/core/src/validator/registry.ts`:
- Around line 123-157: The user field in all four runtime schema builders
(isValibotSchema, isArkType, IsObject for TypeBox, and isZodSchema) is currently
defined as required, but the return type ReturnUpdateSessionShape declares user
as optional. Add the appropriate optional wrapper to the user field in each
builder to match the return type: wrap the user property with valibot.optional()
in the Valibot builder, .optional() in the ArkType builder, Typebox.Optional()
in the TypeBox builder, and z.optional() in the Zod builder.

---

Nitpick comments:
In `@packages/core/src/actions/signUp/signUp.ts`:
- Around line 31-32: Replace the bare `@ts-ignore` comment on the payload variable
declaration with `@ts-expect-error` and include a specific reason for the
suppression (in this case, explaining that the typing calculation is too
expensive). The `@ts-expect-error` directive is more scoped than `@ts-ignore` and
will fail to compile if the underlying typing issue is resolved, preventing
accidental regressions. Update the comment from `@ts-ignore` - Type excessively
expensive to compute to `@ts-expect-error` Type excessively expensive to compute
or similar format that clearly documents why the type assertion is needed.

In `@packages/core/src/client/client.ts`:
- Around line 174-176: Replace the `// `@ts-ignore`` comment on the line before
the `client.post("/signUp", ...)` call with `// `@ts-expect-error`` followed by a
brief reason explaining why the TypeScript error is expected at that location.
This change from unbounded suppression to scoped error expectation prevents
masking future typing issues and maintains clarity about intentional type
mismatches.

In `@packages/core/src/validator/registry.ts`:
- Around line 120-122: The `getFullSchema` generic function has an unconstrained
`Schema` type parameter that allows non-schema types to be passed, causing type
errors only at runtime. Add a constraint to the `Schema` generic parameter in
the `getFullSchema` function signature by extending it to `SchemaTypes`. This
constraint should be applied to the `Schema` generic parameter (the one with
default value `EditableToSchema<Identity>`) to ensure type safety at compile
time and preserve the API contract.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 034f6a8c-af5b-4fc6-8383-b7fdd68802c0

📥 Commits

Reviewing files that changed from the base of the PR and between b99786d and 9fd5ce3.

📒 Files selected for processing (9)
  • packages/core/CHANGELOG.md
  • packages/core/src/@types/utility.ts
  • packages/core/src/actions/signUp/signUp.ts
  • packages/core/src/actions/updateSession/updateSession.ts
  • packages/core/src/api/createApi.ts
  • packages/core/src/client/client.ts
  • packages/core/src/createAuth.ts
  • packages/core/src/validator/registry.ts
  • packages/core/test/client/client.test-d.ts

Comment thread packages/core/CHANGELOG.md Outdated
Comment thread packages/core/src/@types/utility.ts
Comment thread packages/core/src/actions/updateSession/updateSession.ts
Comment thread packages/core/test/client/client.test-d.ts Outdated
@halvaradop halvaradop merged commit e1e3db9 into master Jun 17, 2026
5 of 6 checks passed
@halvaradop halvaradop deleted the fix/type-infer-across-auth branch June 17, 2026 22:42
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