Have I been pwned plugin messes with typescript #1102

Closed
opened 2026-03-13 08:22:38 -05:00 by GiteaMirror · 10 comments
Owner

Originally created by @NeoPrint3D on GitHub (Apr 23, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

export const auth = betterAuth({
  database: drizzleAdapter(
    drizzle("postgres://john:doe@localhost:5432/postgres"),
    {
      provider: "pg",
      usePlural: true,
      schema,
    }
  ),

  plugins: [haveIBeenPwned()],
});

Current vs. Expected behavior

Current behavior

 error TS2742: The inferred type of 'createAuthClient' cannot be named without a reference to '../../node_modules/better-auth/dist/shared/better-auth.qzSbzJNO'. This is likely not portable. A type annotation is necessary.

18 export const createAuthClient = (env: AppEnv) => {
                ~~~~~~~~~~~~~~~~

Expected behavior

tsc

[4:00:03 PM] Found 0 errors. Watching for file changes.

What version of Better Auth are you using?

1.2.7

Provide environment information

- Windows 11

Which area(s) are affected? (Select all that apply)

Types

Auth config (if applicable)

export const auth = betterAuth({
  database: drizzleAdapter(
    drizzle("postgres://john:doe@localhost:5432/postgres"),
    {
      provider: "pg",
      usePlural: true,
      schema,
    }
  ),

  plugins: [haveIBeenPwned()],
});

Additional context

I have thoroughly tested what was causing the type inference issue, and only when the haveIBeenPwned plugin was added, it caused the typescript issue

Originally created by @NeoPrint3D on GitHub (Apr 23, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ```ts export const auth = betterAuth({ database: drizzleAdapter( drizzle("postgres://john:doe@localhost:5432/postgres"), { provider: "pg", usePlural: true, schema, } ), plugins: [haveIBeenPwned()], }); ``` ### Current vs. Expected behavior Current behavior ```bash error TS2742: The inferred type of 'createAuthClient' cannot be named without a reference to '../../node_modules/better-auth/dist/shared/better-auth.qzSbzJNO'. This is likely not portable. A type annotation is necessary. 18 export const createAuthClient = (env: AppEnv) => { ~~~~~~~~~~~~~~~~ ``` Expected behavior ```bash tsc [4:00:03 PM] Found 0 errors. Watching for file changes. ``` ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash - Windows 11 ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: drizzleAdapter( drizzle("postgres://john:doe@localhost:5432/postgres"), { provider: "pg", usePlural: true, schema, } ), plugins: [haveIBeenPwned()], }); ``` ### Additional context I have thoroughly tested what was causing the type inference issue, and only when the haveIBeenPwned plugin was added, it caused the typescript issue
Author
Owner

@ping-maxwell commented on GitHub (Apr 24, 2025):

@NeoPrint3D Can I see your tsconfig?

@ping-maxwell commented on GitHub (Apr 24, 2025): @NeoPrint3D Can I see your tsconfig?
Author
Owner

@NeoPrint3D commented on GitHub (Apr 24, 2025):

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "strict": true,
    "skipLibCheck": true,
    "lib": ["ESNext"],
    "types": ["@cloudflare/workers-types/2023-07-01"],
    "paths": {
      "@/*": ["./src/*"]
    },
    "jsx": "react-jsx",
    "jsxImportSource": "react"
  }
}

It is really weird because only the haveIBeenPwned plugin causes the error

@NeoPrint3D commented on GitHub (Apr 24, 2025): ```json { "compilerOptions": { "target": "ESNext", "module": "ESNext", "moduleResolution": "Bundler", "strict": true, "skipLibCheck": true, "lib": ["ESNext"], "types": ["@cloudflare/workers-types/2023-07-01"], "paths": { "@/*": ["./src/*"] }, "jsx": "react-jsx", "jsxImportSource": "react" } } ``` It is really weird because only the haveIBeenPwned plugin causes the error
Author
Owner

@ping-maxwell commented on GitHub (Apr 25, 2025):

Can I see your auth-client? @NeoPrint3D

@ping-maxwell commented on GitHub (Apr 25, 2025): Can I see your auth-client? @NeoPrint3D
Author
Owner

@NeoPrint3D commented on GitHub (Apr 25, 2025):

I don't know how the authClient would affect anything the typescript issues are only on the server

import { createAuthClient } from "better-auth/react";
import { organizationClient, adminClient } from "better-auth/client/plugins";
import { toast } from "sonner";
import { navigate } from "astro:transitions/client";
export const authClient = createAuthClient({
  baseURL: `${import.meta.env.PUBLIC_API_URL}/v1/auth`,
  plugins: [organizationClient(), adminClient()],
});

export const handleSignOut = async () => {
  await authClient.signOut({
    fetchOptions: {
      onSuccess: async () => {
        toast.success("Signed out successfully!");
        await navigate("/login");
      },
    },
  });
};
@NeoPrint3D commented on GitHub (Apr 25, 2025): I don't know how the authClient would affect anything the typescript issues are only on the server ```ts import { createAuthClient } from "better-auth/react"; import { organizationClient, adminClient } from "better-auth/client/plugins"; import { toast } from "sonner"; import { navigate } from "astro:transitions/client"; export const authClient = createAuthClient({ baseURL: `${import.meta.env.PUBLIC_API_URL}/v1/auth`, plugins: [organizationClient(), adminClient()], }); export const handleSignOut = async () => { await authClient.signOut({ fetchOptions: { onSuccess: async () => { toast.success("Signed out successfully!"); await navigate("/login"); }, }, }); }; ```
Author
Owner

@ping-maxwell commented on GitHub (Apr 25, 2025):

I don't know how the authClient would affect anything the typescript issues are only on the server

It's just that I'm looking at your typescript error and it mentions createAuthClient.

@ping-maxwell commented on GitHub (Apr 25, 2025): > I don't know how the authClient would affect anything the typescript issues are only on the server It's just that I'm looking at your typescript error and it mentions `createAuthClient`.
Author
Owner

@NeoPrint3D commented on GitHub (Apr 25, 2025):

Oh gotcha

@NeoPrint3D commented on GitHub (Apr 25, 2025): Oh gotcha
Author
Owner

@NeoPrint3D commented on GitHub (Apr 25, 2025):

createAuthClient is actually serverside and is used so that I can pass env through the cloudflare runtime

@NeoPrint3D commented on GitHub (Apr 25, 2025): createAuthClient is actually serverside and is used so that I can pass env through the cloudflare runtime
Author
Owner

@hexcowboy commented on GitHub (Apr 25, 2025):

Also seeing this error with haveIBeenPwned plugin.

import "server-only";

import { betterAuth } from "better-auth";
import { haveIBeenPwned } from "better-auth/plugins";

// The inferred type of 'auth' cannot be named without a reference to '@/node_modules/better-auth/dist/shared/better-auth.qzSbzJNO'. This is likely not portable. A type annotation is necessary.ts(2742)
export const auth = betterAuth({
  plugins: [
    haveIBeenPwned(),
  ],
});
{
  "$schema": "https://json.schemastore.org/tsconfig",
  "display": "Default",
  "compilerOptions": {
    "declaration": true,
    "declarationMap": true,
    "esModuleInterop": true,
    "incremental": false,
    "isolatedModules": true,
    "lib": ["es2022", "DOM", "DOM.Iterable"],
    "moduleDetection": "force",
    "noUncheckedIndexedAccess": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true,
    "target": "ES2022",

    "plugins": [{ "name": "next" }],
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "allowJs": true,
    "jsx": "preserve",
    "noEmit": true
  }
}
@hexcowboy commented on GitHub (Apr 25, 2025): Also seeing this error with `haveIBeenPwned` plugin. ```ts import "server-only"; import { betterAuth } from "better-auth"; import { haveIBeenPwned } from "better-auth/plugins"; // The inferred type of 'auth' cannot be named without a reference to '@/node_modules/better-auth/dist/shared/better-auth.qzSbzJNO'. This is likely not portable. A type annotation is necessary.ts(2742) export const auth = betterAuth({ plugins: [ haveIBeenPwned(), ], }); ``` ```json { "$schema": "https://json.schemastore.org/tsconfig", "display": "Default", "compilerOptions": { "declaration": true, "declarationMap": true, "esModuleInterop": true, "incremental": false, "isolatedModules": true, "lib": ["es2022", "DOM", "DOM.Iterable"], "moduleDetection": "force", "noUncheckedIndexedAccess": true, "resolveJsonModule": true, "skipLibCheck": true, "strict": true, "target": "ES2022", "plugins": [{ "name": "next" }], "module": "ESNext", "moduleResolution": "Bundler", "allowJs": true, "jsx": "preserve", "noEmit": true } } ```
Author
Owner

@ping-maxwell commented on GitHub (Apr 26, 2025):

createAuthClient is actually serverside and is used so that I can pass env through the cloudflare runtime

Could I see that file?

@ping-maxwell commented on GitHub (Apr 26, 2025): > createAuthClient is actually serverside and is used so that I can pass env through the cloudflare runtime Could I see that file?
Author
Owner

@NeoPrint3D commented on GitHub (Apr 26, 2025):

I have creaetd a pull request to fix the issue https://github.com/better-auth/better-auth/pull/2449

It was because the original plugin was importing the types from ../../types instead of ../../types/plugins, which all of the other plugins that did not cause this error did

@NeoPrint3D commented on GitHub (Apr 26, 2025): I have creaetd a pull request to fix the issue https://github.com/better-auth/better-auth/pull/2449 It was because the original plugin was importing the types from ../../types instead of ../../types/plugins, which all of the other plugins that did not cause this error did
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1102