Login/Onboarding Redirect Issues - Root Cause Analysis
Problem Statement
User reports:
After logging in, they get redirected to onboarding
When first loading the site, it shows them as "logged in" but with incomplete profile
Frustrated because users shouldn't be shown as logged in without a complete profile
Confused by unnecessary onboarding redirects
Root Causes Identified
Issue 1: Session Restoration Before Profile Completion Check
What happens:
User logs in successfully
Session cookies are set by Supabase
Page reloads or user navigates
AuthContext initializes and restores session from cookies
User appears "logged in" immediately
BUT: Profile is still being fetched from database
UI shows user as logged in while profile data loads
Once profile loads, if incomplete, they might be redirected
Why it's confusing:
User sees themselves logged in
But profile might still be loading
Then get redirected to onboarding
Feels like a bug rather than normal flow
Issue 2: "Logged In By Default" Appearance
What's happening: The AuthContext loads the session from browser storage immediately:
Supabase session stored in cookies/IndexedDB
On page load,
onAuthStateChangefires with existing sessionUser state is set
UI shows user as authenticated
But:
Profile data takes time to load from database
UI briefly shows "logged in" before profile is available
This can feel like users are logged in "by default"
Issue 3: Onboarding Redirect Logic
Current logic in Dashboard.tsx (line 291):
Issues with this:
Redirects to onboarding if NO user
But never checks if profile is INCOMPLETE
Should either:
Redirect to onboarding if profile NOT complete, OR
Not redirect at all if profile is incomplete
Why This Matters
Current behavior is confusing because:
Mixed signals:
User sees themselves logged in
Then gets redirected to onboarding
Feels like auth is broken
No clear intent:
Onboarding is meant to COMPLETE the profile
But if you're already logged in, you should be on dashboard
Redirect should only happen if profile is incomplete
Session uncertainty:
Page shows user as authenticated
But redirects as if they're not
Unclear what state the app is in
Solution
Fix 1: Don't Redirect to Onboarding from Dashboard
Current: Line 291-295 in Dashboard.tsx checks if (!user) and redirects
Should be:
If no user → stay on dashboard (it handles showing loading state)
If user but profile incomplete → show a prompt, don't redirect
If user and profile complete → show full dashboard
Change: Remove the automatic redirect to onboarding. Instead:
Let Dashboard render
Show a "Complete Your Profile" banner if profile is incomplete
Let user click to go to onboarding, don't force redirect
Fix 2: Clear Session Restoration UI
Current: Session restored from cookies → UI shows user as logged in immediately
Should be:
Show loading state while profile is being fetched
Don't show user as "logged in" until profile is loaded
Once profile loads, show actual dashboard
Change: Ensure loading state is true while profile is being fetched, then show LoadingScreen instead of Dashboard
Fix 3: Clarify Onboarding Intent
Current: Onboarding shows up unexpectedly after login
Should be:
Onboarding only when INTENTIONALLY started (user clicks "Complete Profile")
Not automatically triggered by auth state
Dashboard can show "Profile incomplete" message with link to onboarding
Change:
Remove auto-redirect logic
Let Dashboard handle incomplete profile display
User explicitly chooses to complete profile
Specific Code Changes Needed
In code/client/pages/Dashboard.tsx (Lines 283-311)
Current (WRONG):
Should be:
In code/client/pages/Dashboard.tsx (Top level)
Add this check:
Expected Behavior After Fix
Scenario 1: Fresh Login
User logs in with email/password
Redirected to dashboard
Dashboard shows loading state while profile is fetched
Once profile loads:
If profile complete → show full dashboard
If profile incomplete → show "Complete Your Profile" banner with link to onboarding
Scenario 2: Page Reload While Logged In
User is logged in, page reloads
Supabase session restored from cookies
AuthContext restores user and fetches profile
Dashboard shows loading state
Once profile loaded → show dashboard (complete or with banner)
Scenario 3: Not Logged In
Unauthenticated user visits
/dashboardDashboard detects no user
Shows "Please sign in" message
User clicks "Sign In" to go to login page
Testing Checklist
After implementing fixes:
Files to Update
code/client/pages/Dashboard.tsx
283-311
Remove onboarding redirect
code/client/pages/Dashboard.tsx
Start of render
Add loading/auth state checks
code/client/pages/Dashboard.tsx
TBD
Add "Complete Profile" banner
Why This Makes More Sense
Clear intention: Onboarding is optional, not forced
Better UX: No surprising redirects
Session clarity: You're logged in OR you're not (not both at same time)
User control: Users intentionally complete profile, not redirected
Consistency: Dashboard behavior is predictable
Related Issues
AuthContext clearing session on page load: ✅ FIXED (preserves sb-* keys)
Session persistence: ✅ WORKING (cookies restored correctly)
Profile loading timing: ⚠️ CAUSES UI CONFUSION (session shown before profile)
The core issue isn't authentication—it's the redirect logic and UI inconsistency.
Last updated
