Skip to content

feat(auth): infer AuthUser and AuthSession from auth.ts - #622

Merged
Brooooooklyn merged 2 commits into
voidzero-dev:mainfrom
0froq:cursor/infer-auth-user-session-types-ed4f
Oct 29, 2026
Merged

Brooooooklyn merged 2 commits into
voidzero-dev:mainfrom
0froq:cursor/infer-auth-user-session-types-ed4f

Conversation

@0froq

@0froq 0froq commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #567

Summary

AuthUser and AuthSession were always Better Auth's base shapes. Fields from plugins and user.additionalFields exist at runtime but were missing from c.get('user'), getUser(), requireAuth(), and the session helpers.

Changes

  • Make AuthUser and AuthSession mergeable interfaces
  • Generate .void/auth.d.ts from the app auth.ts (same pattern as .void/env.d.ts)
  • Wire generation into prepare and the routing plugin; remove the file when auth is off
  • List auth.d.ts in .void/tsconfig.json only after the file exists
  • Note inferred fields in the auth API docs

Testing

  • Unit tests for codegen and for when auth.d.ts is listed in tsconfig
  • prepareProject write/delete lifecycle test
  • Integration tsc with admin() and additionalFields on c.get, getUser, getSession, and requireAuth

🐸

@cpojer
cpojer requested a review from Brooooooklyn October 27, 2026 15:40
0froq and others added 2 commits October 29, 2026 14:54
Fixes voidzero-dev#567

## Summary

`AuthUser` and `AuthSession` were always Better Auth's base shapes. Fields from plugins and `user.additionalFields` exist at runtime but were missing from `c.get('user')`, `getUser()`, `requireAuth()`, and the session helpers.

## Changes

- Make `AuthUser` and `AuthSession` mergeable interfaces
- Generate `.void/auth.d.ts` from the app `auth.ts` (same pattern as `.void/env.d.ts`)
- Wire generation into prepare and the routing plugin; remove the file when auth is off
- List `auth.d.ts` in `.void/tsconfig.json` only after the file exists
- Note inferred fields in the auth API docs

## Testing

- Unit tests for codegen and for when `auth.d.ts` is listed in tsconfig
- `prepareProject` write/delete lifecycle test
- Integration `tsc` with `admin()` and `additionalFields` on `c.get`, `getUser`, `getSession`, and `requireAuth`
- Fill a `VoidAuthTypes` registry from `.void/auth.d.ts` instead of
  augmenting `AuthUser`/`AuthSession` interfaces. They stay type aliases, so
  they remain assignable to `Record<string, unknown>` and a function config
  that returns different shapes per branch gives a valid union.
- Reach `better-auth` through `void/auth`'s `InferAuthSession`, so apps that
  only depend on `void` (pnpm strict) keep the inferred fields.
- Fall back to the base shapes for an untyped `any` auth config.
- Only add or drop `auth.d.ts` in the existing `.void/tsconfig.json` from the
  dev plugin, instead of recomputing the routes/db entries.
- Test field types, a negative case, a branching config, a JS config and the
  dev plugin path; document the circular-reference trap inside `auth.ts`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn
Brooooooklyn force-pushed the cursor/infer-auth-user-session-types-ed4f branch from 9b454fe to ecc7399 Compare October 29, 2026 07:36
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T08:03:28.483014Z
We couldn’t complete this review. Comment @codex review to try again.
ecc7399 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn
Brooooooklyn merged commit deaacb3 into voidzero-dev:main Oct 29, 2026
18 checks passed
@0froq

0froq commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

❤️

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.

Infer AuthUser / AuthSession from auth.ts: plugin and additionalFields columns are missing from c.get('user'), getUser() and requireAuth()

2 participants