Google Auth Not working in Production
I have my user dashboard at a site, There the Google login works both in Productiona and Development. I also made another app with the 1st one as its base for auth by setting
baseURL
for better auth client to the auth server url. All this setup was working fine locally.
But after deployment the login does not work in 2nd app. The Error is related to CORS as I have verofied that and made sure to set it properly.
I have also added Correct Authentications URLS in the google cloud console (Only one redirect URL although, of the 1st auth server).
The google login page opens but when it returns us to the page it is without proper cookies set for auth. Hence NO CHANGE !!!
Login Code
5 Replies
do we need to set
callbackUR
to something else instead of window.location.href
.
/
:- works fine for the main user dashboard app
but when I used it with the 2nd app it redirected me back to the main app.
window.location.href
works atleast in dev modeWhen does Auth Work
If I have my auth server at for
https://users.netlify.app (https://users.xyx.com)
App
https://app.netlify.app (https://app.xyx.com)
So the Auth does work on netlify's domain.
It stops working if we set
Subdomain Cookie
sharing.Netlify
Start building the best web experiences in record time
So my simple question is can we use the auth backend for multiple frontend clints
I use
window.location.origin
as well for separate frontend and backend.
For CORs issues, it's probably related to your trustedOrigin
configuration in the auth
instance. Are you able to share this?
Docs here:
- https://www.better-auth.com/docs/concepts/cookies#cross-subdomain-cookies
The other thing to note is there may be CORs set on the backend server itself, separate from better-auth. For example, in hono
, you need to also configure:
- https://www.better-auth.com/docs/integrations/hono#cors
Finally, if you're using Safari, you may want to check on another browser first (e.g. Chrome/Firefox) to see if the issue can be reproduced.
Can't really say much else without more details into your configurations.I yeah I was able to setup it up in production.
Thank you
✅
I had to set up cors in sveltekit hooks separately. I think it could also have been done in hono.
The problem also occurred because of usage of .netlify.app domain. After proper sub domain cookie setup in worked