Skip to content

Conversation

@KyleTryon
Copy link
Contributor

Summary

Add detailed logging for cross-domain authentication debugging to help diagnose staging login redirect issues.

Changes

Frontend Logging

  • auth-client.ts: Log Better Auth client configuration (baseURL, environment)
  • useAuth.ts:
    • Log login flow steps (type detection, API result, navigation)
    • Log post-login navigation (session fetch, cookies, router invalidation)
  • __root.tsx: Log root beforeLoad session fetch results

Backend Logging

  • better-auth.ts: Log Better Auth configuration (cookie domain, CORS origins, cross-subdomain settings)
  • app.ts:
    • Log CORS middleware configuration
    • Log incoming auth requests (method, path, origin)
    • Log Set-Cookie headers in auth responses

Why This Helps

When testing on staging, you'll see in the browser console:

  • What baseURL the auth client is using
  • Login flow progression
  • Session fetch results
  • Cookie state
  • Navigation attempts

And in Cloudflare Workers logs:

  • Better Auth configuration (especially COOKIE_DOMAIN)
  • CORS origin configuration
  • Auth requests and their origins
  • Cookie headers being set

This will immediately show if:

  1. Frontend is pointing to the wrong API URL
  2. Cookies are being set with the wrong domain
  3. CORS is blocking requests
  4. Session fetch is failing after login

Testing

Deploy to staging and check:

  1. Browser DevTools Console for [Auth] and [Root] logs
  2. Cloudflare Workers logs for 🔧 and [Auth] logs

KyleTryon and others added 5 commits January 11, 2026 14:10
Add detailed logging for cross-domain authentication debugging:

Frontend:
- Log auth client configuration (baseURL, environment)
- Log login flow steps (type detection, result, navigation)
- Log session fetch in root beforeLoad
- Log navigation steps after auth (session state, cookies, router)

Backend:
- Log Better Auth configuration (cookie domain, CORS origins)
- Log CORS middleware configuration
- Log incoming auth requests (method, path, origin)
- Log Set-Cookie headers in auth responses

This will help diagnose staging login redirect issues where
frontend and API are on different subdomains.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fixes authentication on staging where frontend (staging.tuvix.app) and
API (tuvix-api-staging.cf-93e.workers.dev) are on different domains.

Changes:
- Client: Add credentials: 'include' to Better Auth client for cross-origin cookies
- Server: Set sameSite=none, secure=true, partitioned=true for cross-domain auth
- Secrets: Remove COOKIE_DOMAIN from staging (only for subdomains, not cross-domain)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Staging uses subdomains (staging.tuvix.app and api-staging.tuvix.app),
not completely different domains. Requires cross-subdomain cookies.

Changes:
- Reverted cross-origin cookie attributes (sameSite=none, etc.)
- Set COOKIE_DOMAIN=.tuvix.app for subdomain cookie sharing
- Keep credentials: 'include' on client (needed for CORS with credentials)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@KyleTryon KyleTryon merged commit 4e49a8f into main Jan 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants