wacrm/src
Arnas Donauskas 7d7deb5e0b
fix: dashboard stuck on infinite 'Loading...' spinner
Three bugs in src/hooks/use-auth.ts that caused the dashboard layout's
auth loading state to never resolve:

1. fetchProfile queried profiles.id = userId, but profiles.id is the
   profile's own UUID. The correct column is profiles.user_id (FK to
   auth.users.id). This meant no profile was ever found and — combined
   with .single() throwing on 0 rows — could propagate errors.

2. No try/catch/finally around supabase.auth.getUser(). If getUser()
   threw (e.g. during auth lock contention), setLoading(false) never
   ran and the spinner showed forever with no visible error.

3. useEffect had supabase and fetchProfile in its deps. Since
   createClient() previously returned a new instance each call,
   both deps changed every render and the effect re-ran forever,
   subscribing to onAuthStateChange repeatedly and racing getUser()
   calls against the auth lock.

Changes:
- fetchProfile now uses .eq("user_id", userId) and .maybeSingle() so
  a missing profile returns { data: null } instead of throwing.
- init() wrapped in try/catch/finally — setLoading(false) ALWAYS runs.
- 10-second safety timer clears the loading state if anything hangs.
- useEffect runs once on mount (createClient is a singleton; deps
  intentionally empty).
- Logs Supabase error fields explicitly (message/details/hint/code)
  instead of the raw object which serializes as {}.
- AuthSessionMissingError (normal for logged-out users) is suppressed
  from error logs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 19:52:04 +03:00
..
app Initial scaffold: WhatsApp CRM with Next.js + Supabase 2026-04-16 18:17:31 +03:00
components Initial scaffold: WhatsApp CRM with Next.js + Supabase 2026-04-16 18:17:31 +03:00
hooks fix: dashboard stuck on infinite 'Loading...' spinner 2026-04-16 19:52:04 +03:00
lib Initial scaffold: WhatsApp CRM with Next.js + Supabase 2026-04-16 18:17:31 +03:00
types Initial scaffold: WhatsApp CRM with Next.js + Supabase 2026-04-16 18:17:31 +03:00
middleware.ts Initial scaffold: WhatsApp CRM with Next.js + Supabase 2026-04-16 18:17:31 +03:00