Skip to content

Commit 3fb4121

Browse files
0xdevcollinsclaude
andauthored
fix(auth): send absolute callbackURL on Google sign-up (#584)
The Google sign-up flow passed `callbackURL: process.env.NEXT_PUBLIC_APP_URL || '/'` to Better Auth. Better Auth treats a relative path as relative to the API host that processed the OAuth callback, not the frontend host. When `NEXT_PUBLIC_APP_URL` wasn't set (or was missing in the runtime env even though available at build time on Next.js), the fallback `'/'` sent users to the API host's root after OAuth completed. The session cookie WAS set on the shared `.boundlessfi.xyz` domain during the callback, but the user landed on a blank API page and thought sign-up had failed. Clearing browser cache (cookies survive — different section in Chrome) didn't drop the cookie, so the next visit to the frontend silently restored their session and they appeared "automatically logged in." Fix: always build an absolute `callbackURL` pointing at the frontend host. Same pattern LoginWrapper already uses — falls back to window.location.origin at runtime, then to the env var at build/SSR, then to the production canonical URL. All three are in the BE's `trustedOrigins` list so Better Auth won't reject the URL. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6ecdad4 commit 3fb4121

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

components/auth/SignupWrapper.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,25 @@ const SignupWrapper = ({
2727
setIsLoading(true);
2828
setLoadingState(true);
2929

30+
// Better Auth treats a relative `callbackURL` as relative to the API
31+
// host that handled the OAuth callback (e.g. api.boundlessfi.xyz),
32+
// not the frontend host. The previous default of '/' caused
33+
// successful sign-ups to land on the API host's root, so users saw
34+
// a blank/404 page and thought sign-up had failed — yet the session
35+
// cookie was already set, so a later cache clear silently logged
36+
// them in. Always send an absolute URL pointing at the frontend.
37+
const callbackURL =
38+
typeof window !== 'undefined'
39+
? window.location.origin
40+
: (
41+
process.env.NEXT_PUBLIC_APP_URL || 'https://boundlessfi.xyz'
42+
).replace(/\/$/, '');
43+
3044
try {
3145
await authClient.signIn.social(
3246
{
3347
provider: 'google',
34-
callbackURL: process.env.NEXT_PUBLIC_APP_URL || '/',
48+
callbackURL,
3549
},
3650
{
3751
onRequest: () => {

0 commit comments

Comments
 (0)