Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2k
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hello! Im having issues with better auth and expo integration. I keep getting Im using android simulator on MacOs. here is my server/lib/auth.ts: import{betterAuth}from"better-auth";import{drizzleAdapter}from"better-auth/adapters/drizzle";import{db}from"@/db";// your drizzle instanceimport{expo}from"@better-auth/expo";exportconstauth=betterAuth({plugins:[expo()],database:drizzleAdapter(db,{provider:"pg",}),trustedOrigins:["myapp://","http://10.0.2.2:8787","http://localhost:8787"],emailAndPassword:{enabled:true,},}); Here is my server/.env: Here is my client/auth-client.ts: import{createAuthClient}from'better-auth/react'import{expoClient}from'@better-auth/expo/client'import*asSecureStorefrom'expo-secure-store'import{API_BASE_URL}from'@/src/api/config'exportconstauthClient=createAuthClient({baseURL:"http://10.0.2.2:8787",plugins:[expoClient({scheme:'client',storagePrefix:'client',storage:SecureStore,}),],}) client/config.ts: import{Platform}from"react-native";constnormalizeBaseUrl=(url:string)=>url.trim().replace(/\/+$/,'');constfallbackBaseUrl=Platform.select({android:"http://10.0.2.2:8787",// your local Hono portios:"http://localhost:8787",default:"http://localhost:8787",})!;constenvBaseUrl=process.env.EXPO_PUBLIC_API_BASE_URL??process.env.API_BASE_URL??fallbackBaseUrl;exportconstAPI_BASE_URL=normalizeBaseUrl(envBaseUrl);console.log("API_BASE_URL:",API_BASE_URL); When i try to signIn or signUp my server hits me with this error: here is my client error: {"expo": {"name":"client","slug":"client","version":"1.0.0","orientation":"portrait","icon":"./assets/images/icon.png","scheme":"client",}} |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 2 comments 6 replies
-
Hi@nicholsss! I'mDosu and I’m helping the better-auth team. Your 403 MISSING_OR_NULL_ORIGIN error is caused by a mismatch between the scheme your Expo client is using and what your Better Auth server expects for origin validation. The Expo client sends an expo-origin header (and now, thanks to a recent Better Auth update, this is used to populate the Origin header if it's missing), and the server checks if this value matches any entry in your trustedOrigins array. If they don't match exactly, you get a 403 error (source,source). In your setup, your Expo client is configured with scheme: 'client' (so it sends expo-origin: client://), but your server's trustedOrigins includes "myapp://", not "client://". To fix this, make sure the scheme in all three places matches:
So, update your server config to: trustedOrigins:["client://","http://10.0.2.2:8787","http://localhost:8787"], If you want to quickly unblock yourself in development, you can also add advanced: { disableOriginCheck: true } to your betterAuth config, but only do this in dev since it disables CSRF protection (source). If you still have issues, log the Origin and expo-origin headers on the server to see what values are actually being sent and matched. Let me know if this resolves it! To reply, just mention@dosu. How did I do?Good |Irrelevant |Incorrect |Verbose |Hallucination |Report 🐛 |Other |
BetaWas this translation helpful?Give feedback.
All reactions
-
Your Expo client is sending the correct To fix your 403 error, make sure you are using the latest versions of both import{betterAuth}from"better-auth";import{drizzleAdapter}from"better-auth/adapters/drizzle";import{db}from"@/db";import{expo}from"@better-auth/expo";exportconstauth=betterAuth({plugins:[expo()// No need for extra options unless you want to disable the override],database:drizzleAdapter(db,{provider:"pg"}),trustedOrigins:["myapp://","http://10.0.2.2:8787","http://localhost:8787"],emailAndPassword:{enabled:true},debug:true,allowDangerousConnections:process.env.NODE_ENV!=='production',}); If you are still seeing the error, check your installed package versions and upgrade both Let me know if updating resolves it! To reply, just mention@dosu. How did I do?Good |Irrelevant |Incorrect |Verbose |Hallucination |Report 🐛 |Other |
BetaWas this translation helpful?Give feedback.
All reactions
-
@dosu I added and it started to work. ...advanced:{disableOriginCheck:true,}, Is this valid option even in production, as react native expo app does not send origin, but ExpoOrigin. |
BetaWas this translation helpful?Give feedback.
All reactions
-
No, using advanced: { disableOriginCheck: true } is not safe or recommended in production. This option disables CSRF protection and exposes your app to security risks, so it should only be used in isolated development environments reference reference. For production, Better Auth (v1.3.31+) now automatically maps expo-origin to Origin unless you explicitly disable it with disableOriginOverride. This means you can keep CSRF protection enabled, and as long as your trustedOrigins includes your app scheme (like "myapp://"), Expo/React Native clients will work securely reference reference. So: remove disableOriginCheck, make sure you're on the latest better-auth and @better-auth/expo, and keep your trustedOrigins up to date with your app's scheme. This is the secure and recommended setup for production. To reply, just mention@dosu. How did I do?Good |Irrelevant |Incorrect |Verbose |Hallucination |Report 🐛 |Other |
BetaWas this translation helpful?Give feedback.
All reactions
-
I have the same problem with version Better Auth (v1.3.34) |
BetaWas this translation helpful?Give feedback.
All reactions
👍 3
-
BetaWas this translation helpful?Give feedback.
All reactions
-
I had this issue too...after some research. this fixed the issue for me. btw im using hono as my backend |
BetaWas this translation helpful?Give feedback.