I’m having trouble getting Google OAuth to work with better-auth in my monorepo (Turborepo) setup
Here’s what’s happening:
---
My questions:
- Email/password login works fine (session cookie is set, user is authenticated).
- Google login fails after redirecting back from Google.
- The backend logs show:
- My frontend is on
, backend is onlocalhost:3000localhost:5050. - The Google Cloud Console redirect URI is set to
http://localhost:3000/api/auth/callback/google. - The backend
redirectURIis also set tohttp://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.
- 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.
---
My questions:
- What is the correct way to handle the OAuth "state" in a monorepo with separate frontend/backend ports?
- Is there a recommended way to proxy or align ports for local development with better-auth?
- Are there any special settings needed for cookies or CORS to ensure the state is preserved?
- Is it okay to use
disableRedirect: trueand manually redirect, or does that affect the state/cookie handling?