Common authentication issues and solutions.
Symptoms:
- After Google OAuth, redirected to
http://localhost:8080/dashboard - Should redirect to
http://localhost:5173/dashboard
Solution:
// apps/web/src/providers.tsx
import { APP_URLS } from "@/config/urls";
<AuthUIProvider
baseURL={APP_URLS.frontend} // ← Must be frontend URL
// ...
>Check:
- Is
baseURLset inAuthUIProvider? - Is
VITE_FRONTEND_URLin.env? - Are OAuth credentials correct in backend
.env?
Symptoms:
Access to fetch at 'http://localhost:8080/api/auth/...' from origin
'http://localhost:5173' has been blocked by CORS policy
Solution:
Add frontend URL to ALLOWED_ORIGINS:
# Backend .env
ALLOWED_ORIGINS=http://localhost:5173,http://localhost:3000Check:
// packages/auth/src/auth.ts
const verificationUrl = buildEmailUrlWithFrontendCallback(
url,
AUTH_REDIRECTS.afterEmailVerification, // ← Uses config
);Ensure:
FRONTEND_URLis set in backend.envAUTH_REDIRECTS.afterEmailVerificationpoints to correct path
Check:
- Cookie domain settings (production):
// packages/auth/src/auth.ts
advanced: {
defaultCookieAttributes: {
domain: ".example.com", // ← Must match your domain
},
}- Secure cookies (production):
advanced: {
useSecureCookies: true, // ← Must be true for HTTPS
}Check:
- File name is exactly
.env(not.env.localunless configured) - Variables prefixed with
VITE_for frontend - Restart dev server after changing
.env
Frontend (.env):
VITE_FRONTEND_URL=http://localhost:5173 # ← Must have VITE_ prefix
VITE_API_BASE_URL=http://localhost:8080Backend (.env):
BETTER_AUTH_URL=http://localhost:8080 # ← No prefix needed
FRONTEND_URL=http://localhost:5173Solution:
# Clear cache and rebuild
bun run build
# Or for specific app
cd apps/web && bun run buildWhen debugging auth issues, check:
- Frontend
.envhasVITE_FRONTEND_URLandVITE_API_BASE_URL - Backend
.envhasBETTER_AUTH_URLandFRONTEND_URL -
AuthUIProviderhasbaseURL={APP_URLS.frontend} - OAuth credentials are correct (if using social login)
-
ALLOWED_ORIGINSincludes your frontend URL - Dev server restarted after
.envchanges - No hardcoded URLs in code (use configs)
If you're still stuck:
- Check Better Auth Docs
- Review Better Auth GitHub Issues
- Check browser console for errors
- Check backend logs for errors