Repository navigation
feat(auth): infer AuthUser and AuthSession from auth.ts - #622
Brooooooklyn merged 2 commits into
Conversation
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>
9b454fe to
ecc7399
Compare
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
❤️ |
Fixes #567
Summary
AuthUserandAuthSessionwere always Better Auth's base shapes. Fields from plugins anduser.additionalFieldsexist at runtime but were missing fromc.get('user'),getUser(),requireAuth(), and the session helpers.Changes
AuthUserandAuthSessionmergeable interfaces.void/auth.d.tsfrom the appauth.ts(same pattern as.void/env.d.ts)auth.d.tsin.void/tsconfig.jsononly after the file existsTesting
auth.d.tsis listed in tsconfigprepareProjectwrite/delete lifecycle testtscwithadmin()andadditionalFieldsonc.get,getUser,getSession, andrequireAuth🐸