[PR #7784] [CLOSED] experimental: enhanced endpoint type #7552

Closed
opened 2026-03-13 13:41:12 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7784
Author: @himself65
Created: 2/4/2026
Status: Closed

Base: canaryHead: himself65/2026/02/03/experimental-endpoint-type


📝 Commits (2)

📊 Changes

2 files changed (+79 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/api/routes/account.ts (+6 -2)
📝 packages/core/src/api/index.ts (+73 -0)

📄 Description

this is not the final code

What we get from this enhanced type

  1. ZodType is removed from our dist. So we don't have an external deps issue
  2. Improve type performance on the user side. Remove some unused types. We used a giant object as input, but after this, we only have the necessary types like Path, Query in the generic type. This will help the type checker.

Before:

better_call115.StrictEndpoint<"/delete-user/callback", {
      method: "GET";
      query: zod88.ZodObject<{
        token: zod88.ZodString;
        callbackURL: zod88.ZodOptional<zod88.ZodString>;
      }, zod_v4_core16.$strip>;
      use: ((inputContext: better_call115.MiddlewareInputContext<better_call115.MiddlewareOptions>) => Promise<void>)[];
      metadata: {
        openapi: {
          description: string;
          responses: {
            "200": {
              description: string;
              content: {
                "application/json": {
                  schema: {
                    type: "object";
                    properties: {
                      success: {
                        type: string;
                        description: string;
                      };
                      message: {
                        type: string;
                        enum: string[];
                        description: string;
                      };
                    };
                    required: string[];
                  };
                };
              };
            };
          };
        };
      };
    }, {
      success: boolean;
      message: string;
    }>

After:

_better_auth_core_api0.AuthEndpointV2<"/list-accounts", "GET", _standard_schema_spec0.StandardSchemaV1<unknown, unknown>, _standard_schema_spec0.StandardSchemaV1<unknown, unknown>, [(inputContext: better_call115.MiddlewareInputContext<better_call115.MiddlewareOptions>) => Promise<{
      session: {
        session: Record<string, any> & {
          id: string;
          createdAt: Date;
          updatedAt: Date;
          userId: string;
          expiresAt: Date;
          token: string;
          ipAddress?: string | null | undefined;
          userAgent?: string | null | undefined;
        };
        user: Record<string, any> & {
          id: string;
          createdAt: Date;
          updatedAt: Date;
          email: string;
          emailVerified: boolean;
          name: string;
          image?: string | null | undefined;
        };
      };
    }>]>;

Summary by cubic

Introduced AuthEndpointV2 with simplified, dependency-free typings to improve type-checking performance and remove Zod from exported types. Migrated listUserAccounts to the new endpoint type and added an optional sortBy query.

  • New Features

    • Added createAuthEndpointV2 with slimmer generics (Path, Method, Query, Body, Middleware).
    • Uses StandardSchemaV1 for query/body, removing Zod from the public type surface.
    • Infers middleware return types into the endpoint context for better type safety.
    • listUserAccounts accepts an optional sortBy query parameter.
  • Refactors

    • Updated listUserAccounts to use createAuthEndpointV2.

Written for commit cf9f7650e0. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7784 **Author:** [@himself65](https://github.com/himself65) **Created:** 2/4/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `himself65/2026/02/03/experimental-endpoint-type` --- ### 📝 Commits (2) - [`bc3c8ad`](https://github.com/better-auth/better-auth/commit/bc3c8ade65f48cd373e24cec59ebdae3ece6091a) experimental: enhanced endpoint type - [`cf9f765`](https://github.com/better-auth/better-auth/commit/cf9f7650e03e02092fe944e7b636a6c6380b2b13) fix: no infer ### 📊 Changes **2 files changed** (+79 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/account.ts` (+6 -2) 📝 `packages/core/src/api/index.ts` (+73 -0) </details> ### 📄 Description > this is not the final code What we get from this enhanced type 1. ZodType is removed from our dist. So we don't have an external deps issue 2. Improve type performance on the user side. Remove some unused types. We used a giant object as input, but after this, we only have the necessary types like `Path`, `Query` in the generic type. This will help the type checker. Before: ```ts better_call115.StrictEndpoint<"/delete-user/callback", { method: "GET"; query: zod88.ZodObject<{ token: zod88.ZodString; callbackURL: zod88.ZodOptional<zod88.ZodString>; }, zod_v4_core16.$strip>; use: ((inputContext: better_call115.MiddlewareInputContext<better_call115.MiddlewareOptions>) => Promise<void>)[]; metadata: { openapi: { description: string; responses: { "200": { description: string; content: { "application/json": { schema: { type: "object"; properties: { success: { type: string; description: string; }; message: { type: string; enum: string[]; description: string; }; }; required: string[]; }; }; }; }; }; }; }; }, { success: boolean; message: string; }> ``` After: ```ts _better_auth_core_api0.AuthEndpointV2<"/list-accounts", "GET", _standard_schema_spec0.StandardSchemaV1<unknown, unknown>, _standard_schema_spec0.StandardSchemaV1<unknown, unknown>, [(inputContext: better_call115.MiddlewareInputContext<better_call115.MiddlewareOptions>) => Promise<{ session: { session: Record<string, any> & { id: string; createdAt: Date; updatedAt: Date; userId: string; expiresAt: Date; token: string; ipAddress?: string | null | undefined; userAgent?: string | null | undefined; }; user: Record<string, any> & { id: string; createdAt: Date; updatedAt: Date; email: string; emailVerified: boolean; name: string; image?: string | null | undefined; }; }; }>]>; ``` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Introduced AuthEndpointV2 with simplified, dependency-free typings to improve type-checking performance and remove Zod from exported types. Migrated listUserAccounts to the new endpoint type and added an optional sortBy query. - **New Features** - Added createAuthEndpointV2 with slimmer generics (Path, Method, Query, Body, Middleware). - Uses StandardSchemaV1 for query/body, removing Zod from the public type surface. - Infers middleware return types into the endpoint context for better type safety. - listUserAccounts accepts an optional sortBy query parameter. - **Refactors** - Updated listUserAccounts to use createAuthEndpointV2. <sup>Written for commit cf9f7650e03e02092fe944e7b636a6c6380b2b13. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:41:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#7552