Expo Better Auth breaking with any client plugin "better-auth/client/plugins"

I narrowed down the issue to "better-auth/client/plugins", using any client plugin on expo breaks the app and figured out "jose" was the issue Here's a very basic repo with better auth which has the issue: https://github.com/abhay-ramesh/authTest ❗Someone help me out Thank You
import { expoClient } from "@better-auth/expo/client";
import { usernameClient } from "better-auth/client/plugins";
import { createAuthClient } from "better-auth/react";
import * as SecureStore from "expo-secure-store";

export const authClient = createAuthClient({
baseURL: "http://localhost:8081" /* base url of your Better Auth backend. */,
plugins: [
expoClient({
scheme: "myapp",
storagePrefix: "myapp",
storage: SecureStore,
}),
usernameClient(), // This causes the issue
],
});
import { expoClient } from "@better-auth/expo/client";
import { usernameClient } from "better-auth/client/plugins";
import { createAuthClient } from "better-auth/react";
import * as SecureStore from "expo-secure-store";

export const authClient = createAuthClient({
baseURL: "http://localhost:8081" /* base url of your Better Auth backend. */,
plugins: [
expoClient({
scheme: "myapp",
storagePrefix: "myapp",
storage: SecureStore,
}),
usernameClient(), // This causes the issue
],
});
GitHub
GitHub - abhay-ramesh/authTest
Contribute to abhay-ramesh/authTest development by creating an account on GitHub.
No description
62 Replies
Abhay Ramesh
Abhay RameshOP8mo ago
Hey got it narrowed down to v1.1.19, any version before it works, havent tried the beta-versions
Shubham-Sinha
Shubham-Sinha8mo ago
@admin 1.1.19 breaks in expo. issue with crypto module
No description
bekacru
bekacru8mo ago
Hey guys, please try 1.1.20-beta.2 and report back
Abhay Ramesh
Abhay RameshOP8mo ago
Got a different error with 1.1.20-beta.2
Cannot read property 'subtle' of undefined
Cannot read property 'subtle' of undefined
No description
bekacru
bekacru8mo ago
is the auth import, the server auth instance?
Abhay Ramesh
Abhay RameshOP8mo ago
Yes ig btw its this file
import { expo } from "@better-auth/expo";
import { db } from "@workspace/database"; // your drizzle instance
import { resend } from "@workspace/email";
import { keys } from "@workspace/email/keys";
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { emailOTP, openAPI, username } from "better-auth/plugins";
import * as dotenv from "dotenv";

// Load environment variables
dotenv.config();

export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg", // or "mysql", "sqlite"
}),
user: {
additionalFields: {
role: {
type: "string",
required: true,
defaultValue: "participant",
input: false, // don't allow user to set role
},
},
},
plugins: [
username(),
expo(),
openAPI(),
emailOTP({
async sendVerificationOTP(data, request) {
try {
const { email, otp } = data;

await resend.emails.send({
from: keys().RESEND_FROM,
to: email,
subject: "Your Verification Code",
html: `
<div>hi</div>
`,
});
} catch (error) {
console.error("Failed to send email:", error);
throw new Error("Failed to send verification email");
}
},
}),
],
trustedOrigins: ["myapp://", "http://localhost:3000"],
});
import { expo } from "@better-auth/expo";
import { db } from "@workspace/database"; // your drizzle instance
import { resend } from "@workspace/email";
import { keys } from "@workspace/email/keys";
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { emailOTP, openAPI, username } from "better-auth/plugins";
import * as dotenv from "dotenv";

// Load environment variables
dotenv.config();

export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg", // or "mysql", "sqlite"
}),
user: {
additionalFields: {
role: {
type: "string",
required: true,
defaultValue: "participant",
input: false, // don't allow user to set role
},
},
},
plugins: [
username(),
expo(),
openAPI(),
emailOTP({
async sendVerificationOTP(data, request) {
try {
const { email, otp } = data;

await resend.emails.send({
from: keys().RESEND_FROM,
to: email,
subject: "Your Verification Code",
html: `
<div>hi</div>
`,
});
} catch (error) {
console.error("Failed to send email:", error);
throw new Error("Failed to send verification email");
}
},
}),
],
trustedOrigins: ["myapp://", "http://localhost:3000"],
});
Abhay Ramesh
Abhay RameshOP8mo ago
ok the prev screenshot is of a different repo, i created a repo just to test the bug you can use it to test it and even there had the same issue: https://github.com/abhay-ramesh/authTest its a very plain repo with expo and better-auth btw 1.1.20-beta.2 not working their either
GitHub
GitHub - abhay-ramesh/authTest
Contribute to abhay-ramesh/authTest development by creating an account on GitHub.
No description
Abhay Ramesh
Abhay RameshOP8mo ago
ill try to test from v1.1.18 till v1.1.19 we might be able to narrow down to figure out which release caused it v1.1.18 works v1.1.19-beta.1 works v1.1.19-beta.2 doesn't work v1.1.19-beta.3 doesn't work v1.1.19 doesn't work
Abhay Ramesh
Abhay RameshOP8mo ago
GitHub
feat(one-tap): improve Google One Tap integration with JWT verific...
…ion and improved prompt handling (#1452) * fix(auth): use options.baseURL instead of ctx.baseURL on trusted origins * feat(one-tap): improve Google One Tap integration with JWT verification a...
Abhay Ramesh
Abhay RameshOP8mo ago
packages/better-auth/src/plugins/one-tap/index.ts Usage of "jose" might be the issue "Maybe" ok i manually removed oneTap from /node_modules/better-auth/dist/client/plugins.js and it worked
bekacru
bekacru8mo ago
but jose is imported in the server instance. you sholdn't import the server in your react native code. if you need the type you should make sure to import it as a type
import type { auth } from "your-config"
import type { auth } from "your-config"
Abhay Ramesh
Abhay RameshOP8mo ago
even if im not importing import { auth } from "my-config" have the issue
bekacru
bekacru8mo ago
should be fixed on 1.1.20-beta.3
Abhay Ramesh
Abhay RameshOP8mo ago
Hey thanks alot for the help, really love better-auth nice work
Brunowilliang
Brunowilliang4mo ago
this error also occurs with the Polar client integration.
{ polarClient } from '@polar-sh/better-auth';
{ polarClient } from '@polar-sh/better-auth';
edwardrenton
edwardrenton4w ago
How did you fix this? I am getting the same on 1.3.7
No description
edwardrenton
edwardrenton4w ago
Falling back to 1.3.6 works
HoshangDEV
HoshangDEV3w ago
with 1.3.9 in production when I trigger any function of authClient, the app will crash https://github.com/better-auth/better-auth/issues/4471#issuecomment-3285078594
GitHub
React Native build issue on v1.3.8 · Issue #4471 · better-auth/be...
Is this suited for github? Yes, this is suited for github To Reproduce Create a new expo app, install better-auth@1.3.8 and @better-auth/expo@1.3.8, setup according to docs, import a plugin from be...
SKetU
SKetU3w ago
Do you use expo crypto in your app normally?
HoshangDEV
HoshangDEV3w ago
I use expo crypto only to fix this error Cannot read property 'subtle' of undefined, and i get that error when ever I use a better-auth plugin from client side
SKetU
SKetU3w ago
did you install that package? I am using plugins as well but no issue at all
HoshangDEV
HoshangDEV3w ago
for sure "expo-crypto": "^15.0.7", I just built another APK with 1.3.6, and it's not sending any request to backend what plugin did you use?
SKetU
SKetU3w ago
nothing much just email otp and expo client for now
SKetU
SKetU3w ago
GitHub
React Native build issue on v1.3.8 · Issue #4471 · better-auth/be...
Is this suited for github? Yes, this is suited for github To Reproduce Create a new expo app, install better-auth@1.3.8 and @better-auth/expo@1.3.8, setup according to docs, import a plugin from be...
SKetU
SKetU3w ago
why don't you try this one?
HoshangDEV
HoshangDEV3w ago
I did, I'm in that discussion 😅
SKetU
SKetU3w ago
oh sorry my bad strange both works for me
HoshangDEV
HoshangDEV3w ago
which version of better-auth did you use? and also you created that too? crypto-polyfill.js
import * as ExpoeCrypto from 'expo-crypto';

if (typeof global.crypto === 'undefined') {
global.crypto = {};
}

global.crypto.getRandomValues = ExpoeCrypto.getRandomValues;
global.crypto.randomUUID = ExpoeCrypto.randomUUID;

if (typeof globalThis !== 'undefined') {
globalThis.crypto = global.crypto;
}
import * as ExpoeCrypto from 'expo-crypto';

if (typeof global.crypto === 'undefined') {
global.crypto = {};
}

global.crypto.getRandomValues = ExpoeCrypto.getRandomValues;
global.crypto.randomUUID = ExpoeCrypto.randomUUID;

if (typeof globalThis !== 'undefined') {
globalThis.crypto = global.crypto;
}
HoshangDEV
HoshangDEV3w ago
If you have some time, I appreciate if you take a look at my code.: https://github.com/HoshangDEV/expo-better-auth
GitHub
GitHub - HoshangDEV/expo-better-auth
Contribute to HoshangDEV/expo-better-auth development by creating an account on GitHub.
SKetU
SKetU3w ago
I might be wrong but I think the app is crashing maybe it can't find the file in path ? instead of '@' I used just '../', sounds shit but idk try
HoshangDEV
HoshangDEV3w ago
I'm gonna try this...
SKetU
SKetU3w ago
btw did you tried devclient before compiling ?
HoshangDEV
HoshangDEV3w ago
if you mean if I have tested it locally using npm start with Expo Go, yes.
SKetU
SKetU3w ago
did that crash ?
HoshangDEV
HoshangDEV3w ago
no, locally everything works fine.
SKetU
SKetU3w ago
well for testing keep using expo go till some proper solutions are out
HoshangDEV
HoshangDEV3w ago
I just tested that, and when I open the app it will crash immediately, I used 1.3.9 for that one. I'm gonna try 1.3.6 now ...
SKetU
SKetU3w ago
1.3.6 doesn't even need any custom polyfill
HoshangDEV
HoshangDEV3w ago
before, I built one with 1.3.6 but I hard coded the baseUrl because I want to test the build with local backend, and I was getting throw errors, right now I'm rebuilding it again but with hosted backend. It's really a headache finally, it did work.
SKetU
SKetU3w ago
1.3.6 just works normally no custom setup needed
HoshangDEV
HoshangDEV3w ago
too late, I tasted all the pain and headache 😭😂, thank you thou, I appreciate your help.
SKetU
SKetU3w ago
well my plan was to make everything working with latest version
HoshangDEV
HoshangDEV3w ago
the latest version works for you? by both you meant which one?
SKetU
SKetU3w ago
With custom polyfils
SKetU
SKetU3w ago
GitHub
React Native build issue on v1.3.8 · Issue #4471 · better-auth/be...
Is this suited for github? Yes, this is suited for github To Reproduce Create a new expo app, install better-auth@1.3.8 and @better-auth/expo@1.3.8, setup according to docs, import a plugin from be...
HoshangDEV
HoshangDEV3w ago
@SKetU Tried "better-auth": "1.3.10-beta.4" and "@better-auth/expo": "1.3.10-beta.4" , everything works fine!
SKetU
SKetU3w ago
Without any polyfils?
HoshangDEV
HoshangDEV3w ago
I included it, now let me try without any polyfils... I built one without polyfils, and when I open it, it gonna crash immediately, so it's not working without polyfils.
SKetU
SKetU3w ago
Seems like now everyone can use polyfils with new beta
HoshangDEV
HoshangDEV3w ago
GitHub
React Native build issue on v1.3.8 · Issue #4471 · better-auth/be...
Is this suited for github? Yes, this is suited for github To Reproduce Create a new expo app, install better-auth@1.3.8 and @better-auth/expo@1.3.8, setup according to docs, import a plugin from be...
SKetU
SKetU3w ago
try the new beta 7 without polyfils
Abdulrahman Matouk
How i can fix it? I am getting the same error on 1.3.9
No description
HoshangDEV
HoshangDEV3w ago
it's working without polyfils on android try 1.3.6
SKetU
SKetU3w ago
I mean 1.3.10 beta 7
HoshangDEV
HoshangDEV3w ago
yeah, I mean this one too, it's working fine, but haven't tried it yet in an iOS production build
HoshangDEV
HoshangDEV3w ago
did you try with iOS?
SKetU
SKetU3w ago
Sadly I don't own I phone or mac
HoshangDEV
HoshangDEV3w ago
1.3.10 works fine on iOS ✅
SKetU
SKetU3w ago
damn nice, congratulations
HoshangDEV
HoshangDEV3w ago
yeah, thanks

Did you find this page helpful?