-
- Notifications
You must be signed in to change notification settings - Fork 1.9k
perf: improve type Auth #4930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: improve type Auth #4930
Conversation
| @himself65 is attempting to deploy a commit to the better-auth Team on Vercel. A member of the Team first needs to authorize it. |
better-auth
@better-auth/cli
@better-auth/core
@better-auth/expo
@better-auth/sso
@better-auth/stripe
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 2 files
350ccfd | So, I still had the same issues with this version, but then codex figured it out... somehow. Not sure if it will crash during runtime, but it did resolve the types cleanly WHILE exactOptionalPropertyTypes is true here is a PR/branch/commit with the fix: artimath/tanstack-effect-cloudflare-template#1 here is the code that changed it, adding $InferAuth to the createAuthClient options: import { adminClient, emailOTPClient, inferAdditionalFields, magicLinkClient, multiSessionClient, organizationClient, passkeyClient, twoFactorClient, } from "better-auth/client/plugins"; import { InferAuth } from "better-auth/client"; import { createAuthClient } from "better-auth/react"; import { env } from "@/lib/env.client"; import { ac, admin as adminRole, superadmin as superAdminRole, user as userRole } from "./permissions"; import type { auth } from "@/lib/auth/auth"; export const authClient = createAuthClient({ baseURL: env.VITE_SERVER_URL, plugins: [ inferAdditionalFields<typeof auth>(), twoFactorClient(), passkeyClient(), adminClient({ ac, roles: { user: userRole, admin: adminRole, superadmin: superAdminRole, }, }), organizationClient(), emailOTPClient(), magicLinkClient(), multiSessionClient(), ], $InferAuth: InferAuth<typeof auth>(), <--- magic fix? }); export type AuthClient = typeof authClient; export type Session = AuthClient["$Infer"]["Session"]; export type SessionUser = Session["user"]; export type Organization = AuthClient["$Infer"]["Organization"]; export type ActiveOrganization = AuthClient["$Infer"]["ActiveOrganization"];maybe it's a mirage, but on the off-chance it isn't, i want to share it since i saw a lot of people running into it @himself65 thank you for creating this and tending to it |
Move it on top of
Authto reduce some deeper type inference.Reduce perf from ~9.5s to ~8.7s
Summary by cubic
Made Auth generic and plugin-aware to provide precise typings for api, options, $Infer, and merged $ERROR_CODES. Added type tests to validate default Auth and plugin error code merging.