expoClient type error in monorepo when used outside of expo app
I have a turborepo with package folder named
authauth which has better-auth setup to import into my expo and next.js apps.// mobile-auth-client.ts
import { createAuthClient } from "better-auth/react";
import { expoClient } from "@better-auth/expo/client";
import { phoneNumberClient, usernameClient } from "better-auth/client/plugins";
import * as SecureStore from "expo-secure-store";
import type { BetterAuthClientPlugin } from "better-auth";
interface MobileAuthClientConfig {
baseURL: string;
storagePrefix?: string;
scheme?: string;
}
/**
* Temp compatibility wrapper aligns `expoClient` with the
* `BetterAuthClientPlugin` signature expected
* (adds the unused `options` parameter to `getActions`).
*/
function expoClientCompat(options: Parameters<typeof expoClient>[0]): BetterAuthClientPlugin {
const plugin = expoClient(options);
return {
...plugin,
getActions($fetch, $store, _options) {
// `expoClient`'s getActions ignores the 3rd param; passing only the required ones.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (plugin as unknown as { getActions: (f: any, s: any) => Record<string, unknown> }).getActions(
$fetch,
$store,
);
},
} satisfies BetterAuthClientPlugin;
}
export function createMobileAuthClient({
baseURL,
scheme = "betterpuck",
storagePrefix = "betterpuck",
}: MobileAuthClientConfig): ReturnType<typeof createAuthClient> {
const sanitizedBaseURL = baseURL.endsWith("/")
? baseURL.slice(0, -1)
: baseURL;
return createAuthClient({
baseURL: sanitizedBaseURL,
plugins: [
// Expo integration with secure storage
expoClientCompat({
scheme,
storagePrefix,
storage: SecureStore,
}),
// Phone number authentication
phoneNumberClient(),
// Username authentication
usernameClient(),
],
});
}
export type MobileAuthClient = ReturnType<typeof createMobileAuthClient>;// mobile-auth-client.ts
import { createAuthClient } from "better-auth/react";
import { expoClient } from "@better-auth/expo/client";
import { phoneNumberClient, usernameClient } from "better-auth/client/plugins";
import * as SecureStore from "expo-secure-store";
import type { BetterAuthClientPlugin } from "better-auth";
interface MobileAuthClientConfig {
baseURL: string;
storagePrefix?: string;
scheme?: string;
}
/**
* Temp compatibility wrapper aligns `expoClient` with the
* `BetterAuthClientPlugin` signature expected
* (adds the unused `options` parameter to `getActions`).
*/
function expoClientCompat(options: Parameters<typeof expoClient>[0]): BetterAuthClientPlugin {
const plugin = expoClient(options);
return {
...plugin,
getActions($fetch, $store, _options) {
// `expoClient`'s getActions ignores the 3rd param; passing only the required ones.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (plugin as unknown as { getActions: (f: any, s: any) => Record<string, unknown> }).getActions(
$fetch,
$store,
);
},
} satisfies BetterAuthClientPlugin;
}
export function createMobileAuthClient({
baseURL,
scheme = "betterpuck",
storagePrefix = "betterpuck",
}: MobileAuthClientConfig): ReturnType<typeof createAuthClient> {
const sanitizedBaseURL = baseURL.endsWith("/")
? baseURL.slice(0, -1)
: baseURL;
return createAuthClient({
baseURL: sanitizedBaseURL,
plugins: [
// Expo integration with secure storage
expoClientCompat({
scheme,
storagePrefix,
storage: SecureStore,
}),
// Phone number authentication
phoneNumberClient(),
// Username authentication
usernameClient(),
],
});
}
export type MobileAuthClient = ReturnType<typeof createMobileAuthClient>;

