[GH-ISSUE #2031] Type error with @better-auth/expo in 1.2.5 #9014

Closed
opened 2026-04-13 04:16:37 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @zwily on GitHub (Mar 27, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2031

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Using @better-auth/expo in an expo app, I started getting this new type error with 1.2.5 (1.2.4 works):

import { expoClient } from "@better-auth/expo/client";
import { createAuthClient } from "better-auth/react";
import * as SecureStorage from "expo-secure-store";

export const authClient = createAuthClient({
  baseURL: process.env.EXPO_PUBLIC_URL,
  disableDefaultFetchPlugins: true,
  disableCache: true,
  plugins: [
    expoClient({
      scheme: "myapp",
      storagePrefix: "myapp",
      storage: SecureStorage,
    }),
  ],
  storage: SecureStorage,
});

The error is on the expoClient call:

Type '{ id: "expo"; getActions(_: BetterFetch, $store: Store): { getCookie: () => string; }; fetchPlugins: { id: string; name: string; hooks: { onSuccess(context: SuccessContext<any>): Promise<...>; }; init(url: string, options: { ...; } | undefined): Promise<...>; }[]; }' is not assignable to type 'BetterAuthClientPlugin'.
  Types of property 'fetchPlugins' are incompatible.
    Type '{ id: string; name: string; hooks: { onSuccess(context: SuccessContext<any>): Promise<void>; }; init(url: string, options: { cache?: RequestCache | undefined; ... 33 more ...; disableValidation?: boolean | undefined; } | undefined): Promise<...>; }[]' is not assignable to type 'BetterFetchPlugin[]'.
      Type '{ id: string; name: string; hooks: { onSuccess(context: SuccessContext<any>): Promise<void>; }; init(url: string, options: { cache?: RequestCache | undefined; ... 33 more ...; disableValidation?: boolean | undefined; } | undefined): Promise<...>; }' is not assignable to type 'BetterFetchPlugin'.
        Types of property 'init' are incompatible.
          Type '(url: string, options: { cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | { ...; })) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; } | undefined) => Promise<...>' is not assignable to type '(url: string, options?: { cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | CommonHeaders)) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; } | undefined) => Promise<...> | { ...; }'.
            Types of parameters 'options' and 'options' are incompatible.
              Type '{ cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | CommonHeaders)) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; } | undefined' is not assignable to type '{ cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | { ...; })) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; } | undefined'.
                Type '{ cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | CommonHeaders)) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; }' is not assignable to type '{ cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | { ...; })) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; }'.
                  Types of property 'auth' are incompatible.
                    Type 'Auth | undefined' is not assignable to type '{ type: "Bearer"; token: string | (() => string | undefined) | undefined; } | { type: "Basic"; username: string | (() => string | undefined) | undefined; password: string | (() => string | undefined) | undefined; } | { ...; } | undefined'.
                      Type 'Bearer' is not assignable to type '{ type: "Bearer"; token: string | (() => string | undefined) | undefined; } | { type: "Basic"; username: string | (() => string | undefined) | undefined; password: string | (() => string | undefined) | undefined; } | { ...; } | undefined'.
                        Type 'Bearer' is not assignable to type '{ type: "Bearer"; token: string | (() => string | undefined) | undefined; }'.
                          Types of property 'token' are incompatible.
                            Type 'typeOrTypeReturning<string | Promise<string | undefined> | undefined>' is not assignable to type 'string | (() => string | undefined) | undefined'.
                              Type 'Promise<string | undefined>' is not assignable to type 'string | (() => string | undefined) | undefined'.ts(2322)

Current vs. Expected behavior

Expected behavior: No type error.
Current behavior: Type error from above.

What version of Better Auth are you using?

1.2.5

Provide environment information

- OS: Mac OS 15.3.2

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

Types

Auth config (if applicable)

(This is only occurring on the expo client.)

Additional context

No response

Originally created by @zwily on GitHub (Mar 27, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2031 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Using @better-auth/expo in an expo app, I started getting this new type error with 1.2.5 (1.2.4 works): ``` import { expoClient } from "@better-auth/expo/client"; import { createAuthClient } from "better-auth/react"; import * as SecureStorage from "expo-secure-store"; export const authClient = createAuthClient({ baseURL: process.env.EXPO_PUBLIC_URL, disableDefaultFetchPlugins: true, disableCache: true, plugins: [ expoClient({ scheme: "myapp", storagePrefix: "myapp", storage: SecureStorage, }), ], storage: SecureStorage, }); ``` The error is on the `expoClient` call: ``` Type '{ id: "expo"; getActions(_: BetterFetch, $store: Store): { getCookie: () => string; }; fetchPlugins: { id: string; name: string; hooks: { onSuccess(context: SuccessContext<any>): Promise<...>; }; init(url: string, options: { ...; } | undefined): Promise<...>; }[]; }' is not assignable to type 'BetterAuthClientPlugin'. Types of property 'fetchPlugins' are incompatible. Type '{ id: string; name: string; hooks: { onSuccess(context: SuccessContext<any>): Promise<void>; }; init(url: string, options: { cache?: RequestCache | undefined; ... 33 more ...; disableValidation?: boolean | undefined; } | undefined): Promise<...>; }[]' is not assignable to type 'BetterFetchPlugin[]'. Type '{ id: string; name: string; hooks: { onSuccess(context: SuccessContext<any>): Promise<void>; }; init(url: string, options: { cache?: RequestCache | undefined; ... 33 more ...; disableValidation?: boolean | undefined; } | undefined): Promise<...>; }' is not assignable to type 'BetterFetchPlugin'. Types of property 'init' are incompatible. Type '(url: string, options: { cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | { ...; })) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; } | undefined) => Promise<...>' is not assignable to type '(url: string, options?: { cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | CommonHeaders)) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; } | undefined) => Promise<...> | { ...; }'. Types of parameters 'options' and 'options' are incompatible. Type '{ cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | CommonHeaders)) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; } | undefined' is not assignable to type '{ cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | { ...; })) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; } | undefined'. Type '{ cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | CommonHeaders)) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; }' is not assignable to type '{ cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | { ...; })) | undefined; ... 31 more ...; disableValidation?: boolean | undefined; }'. Types of property 'auth' are incompatible. Type 'Auth | undefined' is not assignable to type '{ type: "Bearer"; token: string | (() => string | undefined) | undefined; } | { type: "Basic"; username: string | (() => string | undefined) | undefined; password: string | (() => string | undefined) | undefined; } | { ...; } | undefined'. Type 'Bearer' is not assignable to type '{ type: "Bearer"; token: string | (() => string | undefined) | undefined; } | { type: "Basic"; username: string | (() => string | undefined) | undefined; password: string | (() => string | undefined) | undefined; } | { ...; } | undefined'. Type 'Bearer' is not assignable to type '{ type: "Bearer"; token: string | (() => string | undefined) | undefined; }'. Types of property 'token' are incompatible. Type 'typeOrTypeReturning<string | Promise<string | undefined> | undefined>' is not assignable to type 'string | (() => string | undefined) | undefined'. Type 'Promise<string | undefined>' is not assignable to type 'string | (() => string | undefined) | undefined'.ts(2322) ``` ### Current vs. Expected behavior Expected behavior: No type error. Current behavior: Type error from above. ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash - OS: Mac OS 15.3.2 ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript (This is only occurring on the expo client.) ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 04:16:37 -05:00
Author
Owner

@Bekacru commented on GitHub (Mar 28, 2025):

Have you upgraded both better-auth and @better-auth/expo?

<!-- gh-comment-id:2760576168 --> @Bekacru commented on GitHub (Mar 28, 2025): Have you upgraded both `better-auth` and `@better-auth/expo`?
Author
Owner

@jmaestree commented on GitHub (Mar 28, 2025):

Have you upgraded both better-auth and @better-auth/expo?

I had the same issue after upgrading both packages to 1.2.5.

Bypassed it by adding the expected types with as BetterAuthClientPlugin:

export const authClient = createAuthClient({
  baseURL: getBaseUrl(),
  disableDefaultFetchPlugins: false,
  plugins: [
    inferAdditionalFields<Auth>(),
    expoClient({
      scheme: Constants.expoConfig?.scheme as string,
      storagePrefix: "myapp",
      storage: SecureStore,
    }) as BetterAuthClientPlugin,
  ],
});
<!-- gh-comment-id:2762293306 --> @jmaestree commented on GitHub (Mar 28, 2025): > Have you upgraded both `better-auth` and `@better-auth/expo`? I had the same issue after upgrading both packages to `1.2.5`. Bypassed it by adding the expected types with `as BetterAuthClientPlugin`: ```tsx export const authClient = createAuthClient({ baseURL: getBaseUrl(), disableDefaultFetchPlugins: false, plugins: [ inferAdditionalFields<Auth>(), expoClient({ scheme: Constants.expoConfig?.scheme as string, storagePrefix: "myapp", storage: SecureStore, }) as BetterAuthClientPlugin, ], }); ```
Author
Owner

@zwily commented on GitHub (Mar 28, 2025):

Have you upgraded both better-auth and @better-auth/expo?

Yes, both at 1.2.5.

<!-- gh-comment-id:2762566680 --> @zwily commented on GitHub (Mar 28, 2025): > Have you upgraded both `better-auth` and `@better-auth/expo`? Yes, both at 1.2.5.
Author
Owner

@zwily commented on GitHub (Mar 28, 2025):

Have you upgraded both better-auth and @better-auth/expo?

I had the same issue after upgrading both packages to 1.2.5.

Bypassed it by adding the expected types with as BetterAuthClientPlugin:

export const authClient = createAuthClient({
baseURL: getBaseUrl(),
disableDefaultFetchPlugins: false,
plugins: [
inferAdditionalFields(),
expoClient({
scheme: Constants.expoConfig?.scheme as string,
storagePrefix: "myapp",
storage: SecureStore,
}) as BetterAuthClientPlugin,
],
});

I tried that too but it didn’t work because the resulting client then didn’t have the expo methods on it (like getCookie())

<!-- gh-comment-id:2762570275 --> @zwily commented on GitHub (Mar 28, 2025): > > Have you upgraded both `better-auth` and `@better-auth/expo`? > > I had the same issue after upgrading both packages to `1.2.5`. > > Bypassed it by adding the expected types with `as BetterAuthClientPlugin`: > > export const authClient = createAuthClient({ > baseURL: getBaseUrl(), > disableDefaultFetchPlugins: false, > plugins: [ > inferAdditionalFields<Auth>(), > expoClient({ > scheme: Constants.expoConfig?.scheme as string, > storagePrefix: "myapp", > storage: SecureStore, > }) as BetterAuthClientPlugin, > ], > }); I tried that too but it didn’t work because the resulting client then didn’t have the expo methods on it (like getCookie())
Author
Owner

@sameerxanand commented on GitHub (Mar 30, 2025):

I'm also seeing this issue, both packages on 1.2.5

<!-- gh-comment-id:2764345764 --> @sameerxanand commented on GitHub (Mar 30, 2025): I'm also seeing this issue, both packages on 1.2.5
Author
Owner

@jmaestree commented on GitHub (Mar 30, 2025):

The issue seems to come from the v1.1.18 of the @better-fetch/fetch package.

On the package.json from @better-auth/expo there is this dependency:

Image

When I update @better-auth/expo to v1.2.5, it automatically bumps @better-fetch/fetch to v1.1.18, and that version is the one that introduces (at least) the types errors.

🧑‍🔧 Workaround

Force in your dependencies the @better-fetch/fetch version to v1.1.17 (that one still works):

"@better-fetch/fetch": "1.1.17",

This should solve the getCookie issue @zwily

<!-- gh-comment-id:2764510786 --> @jmaestree commented on GitHub (Mar 30, 2025): The issue seems to come from the `v1.1.18` of the `@better-fetch/fetch` package. On the package.json from `@better-auth/expo` there is this dependency: ![Image](https://github.com/user-attachments/assets/3a44538e-4a5c-4527-974c-751c6e9eb2e1) When I update `@better-auth/expo` to `v1.2.5`, it automatically bumps `@better-fetch/fetch` to `v1.1.18`, and that version is the one that introduces (at least) the types errors. ## 🧑‍🔧 Workaround Force in your dependencies the `@better-fetch/fetch` version to `v1.1.17` (that one still works): > "@better-fetch/fetch": "1.1.17", This should solve the `getCookie` issue @zwily
Author
Owner

@juan-altatech commented on GitHub (Mar 31, 2025):

https://github.com/better-auth/better-auth/issues/1855

<!-- gh-comment-id:2764967459 --> @juan-altatech commented on GitHub (Mar 31, 2025): https://github.com/better-auth/better-auth/issues/1855
Author
Owner

@Nikola-Milovic commented on GitHub (Apr 23, 2025):

It's still happening even on 1.2.7 @goknsh , see https://github.com/better-auth/better-auth/issues/1974

<!-- gh-comment-id:2823531393 --> @Nikola-Milovic commented on GitHub (Apr 23, 2025): It's still happening even on `1.2.7` @goknsh , see https://github.com/better-auth/better-auth/issues/1974
Author
Owner

@terijaki commented on GitHub (Apr 23, 2025):

It's still happening even on 1.2.7 @goknsh , see #1974

Make sure you remove the workaround form jamestree above.

You need to remove as BetterAuthClientPlugin from your authClient configuration. ☝️
In your linked issue you only shared your server configuration [hono], not your client config [expo] (which is where the type issue comes from).

<!-- gh-comment-id:2823562279 --> @terijaki commented on GitHub (Apr 23, 2025): > It's still happening even on `1.2.7` [@goknsh](https://github.com/goknsh) , see [#1974](https://github.com/better-auth/better-auth/issues/1974) Make sure you **remove** the workaround form jamestree above. You need to remove ` as BetterAuthClientPlugin` from your authClient configuration. ☝️ In your linked issue you only shared your server configuration [hono], not your client config [expo] (which is where the type issue comes from).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9014