I’m having trouble getting Google OAuth to work with better-auth in my monorepo (Turborepo) setup

Here’s what’s happening: - Email/password login works fine (session cookie is set, user is authenticated). - Google login fails after redirecting back from Google.
- The backend logs show:
ERROR [Better Auth]: State not found undefined

ERROR [Better Auth]: State not found undefined

- My frontend is on localhost:3000, backend is on localhost:5050. - The Google Cloud Console redirect URI is set to http://localhost:3000/api/auth/callback/google. - The backend redirectURI is also set to http://localhost:3000/api/auth/callback/google. - The frontend uses authClient.signIn.social({ provider: "google", callbackURL: "http://localhost:3000/infrahub", disableRedirect: true }) and then manually redirects to the returned URL. What I’ve tried: - Aligning all ports and domains (tried both 3000 and 5050). - Clearing cookies and restarting everything. - Setting cookie options in the backend to { domain: undefined, sameSite: "lax", secure: false } for local dev. - Ensuring the login flow starts and ends on the same port. Still, I get the "State not found" error after Google redirects back. --- My questions: 1. What is the correct way to handle the OAuth "state" in a monorepo with separate frontend/backend ports? 2. Is there a recommended way to proxy or align ports for local development with better-auth? 3. Are there any special settings needed for cookies or CORS to ensure the state is preserved? 4. Is it okay to use disableRedirect: true and manually redirect, or does that affect the state/cookie handling? Any advice or working local dev setups would be greatly appreciated!
2 Replies
sebastian
sebastian4mo ago
if you have separate backend it should be pointed to the 5050, (if here's your api handler).
Kinshuk
KinshukOP4mo ago
yes we did that, but it still didn't solve the issue

Did you find this page helpful?