8.4 KiB
Login/Onboarding Redirect Fixes - Summary of Changes Applied
Problem
You reported that:
- After logging in, you get redirected to onboarding unexpectedly
- Site shows you as "logged in" on initial page load but with incomplete profile
- Users shouldn't appear logged in without a complete profile
- Frustrated by mysterious redirects and confusing auth state
Root Causes Found
-
Session restored before profile loads - Supabase restores your session from cookies immediately, showing you as "logged in" even while profile is still fetching from database
-
Automatic redirect to onboarding - Dashboard component had code that auto-redirected to onboarding if user state was empty, causing unexpected navigation
-
Unclear intent - No clear indication to user: Are you logged in? Is profile loading? Should you complete it? Users saw mixed signals.
Fixes Applied
Fix 1: Remove Automatic Onboarding Redirect
File: code/client/pages/Dashboard.tsx (Lines 283-311)
What changed:
- ❌ REMOVED: Code that auto-redirected to
/onboardingwhen no user - ❌ REMOVED: Comment saying "redirect to login when auth is resolved"
- ✅ ADDED: Simple state handling without redirects
- ✅ ADDED: Clear separation of auth loading vs auth resolved states
Old behavior:
if (!user && !authLoading) {
navigate("/onboarding", { replace: true }); // AUTO-REDIRECT!
}
New behavior:
if (authLoading) {
setIsLoading(true); // Show loading state
return;
}
if (!user) {
setIsLoading(false); // Auth resolved, no user
return;
}
if (user && profile) {
loadDashboardData(); // Load dashboard data
}
Fix 2: Show User-Friendly Messages Instead of Redirecting
File: code/client/pages/Dashboard.tsx (Lines 566-602)
What changed:
- ❌ REMOVED:
return nullwhen no user (which allowed redirect to happen) - ✅ ADDED: "Please Sign In" message with button
- ✅ ADDED: "Complete Your Profile" message with button
- ✅ ADDED: User controls when to complete profile (not forced redirect)
New behavior:
When not logged in:
┌─────────────────────────┐
│ Welcome to AeThex │
├─────────────────────────┤
│ You need to be signed │
│ in to access the │
│ dashboard │
│ │
│ [ Sign In ] │
└─────────────────────────┘
When logged in but profile incomplete:
┌─────────────────────────┐
│ Complete Your Profile │
├─────────────────────────┤
│ Let's set up your │
│ profile to get started │
│ with AeThex │
│ │
│ [ Complete Profile ] │
└─────────────────────────┘
When logged in with complete profile:
- Full dashboard shown normally
Expected Behavior After Fix
Scenario 1: Logging In
Before:
- Enter email/password
- Submit
- ❌ Redirected to onboarding (confusing!)
After:
- Enter email/password
- Submit
- ✅ See dashboard or "Complete Profile" message
- ✅ You choose when to complete profile (not forced)
Scenario 2: Page Reload While Logged In
Before:
- Reload page
- ❌ See yourself "logged in" for a moment
- ❌ Maybe get redirected to onboarding
After:
- Reload page
- ✅ See loading state briefly
- ✅ Dashboard appears or message about completing profile
- ✅ No unexpected redirects
Scenario 3: Visiting Dashboard When Not Logged In
Before:
- Visit
/dashboardwithout being logged in - ❌ Redirected to onboarding (wrong!)
After:
- Visit
/dashboardwithout being logged in - ✅ See "Please Sign In" message
- ✅ Click button to go to login page
What This Means
✅ No more mysterious redirects
- You won't be auto-redirected to onboarding unexpectedly
- Your destination is clear (dashboard or complete profile)
✅ No confusing "logged in by default" state
- Loading spinner shows while profile is being fetched
- You don't see yourself logged in until profile is actually loaded
✅ User control over onboarding
- You choose when to complete your profile
- Not forced by automatic redirects
- Clear button to start onboarding
✅ Clear error messages
- "Sign In" message when not authenticated
- "Complete Profile" message when missing profile data
- No guessing what state you're in
Testing the Fix
Test 1: Log In and Go to Dashboard
- Visit
/login - Sign in with email/password
- Expected: Should see dashboard or "Complete Profile" message
- NOT expected: Redirect to onboarding
- If profile incomplete: Click "Complete Profile" button intentionally
Test 2: Reload Dashboard While Logged In
- Log in successfully
- Visit
/dashboard - Reload page (F5 or Ctrl+R)
- Expected: See loading state, then dashboard
- NOT expected: Redirect to onboarding or seeing "logged in by default"
Test 3: Visit Dashboard When Not Logged In
- Make sure you're logged out (go to
/logoutor clear cookies) - Visit
/dashboard - Expected: See "Please Sign In" message with button
- NOT expected: Redirect to onboarding
Test 4: Sign Out and Back In
- While on dashboard, click Sign Out
- Expected: Should see "Please Sign In" message
- Click Sign In button
- Expected: Redirected to login page
- Sign in
- Expected: Back to dashboard or "Complete Profile" message
Files Modified
| File | Changes | Status |
|---|---|---|
code/client/pages/Dashboard.tsx |
Removed auto-redirect logic (lines 283-311) | ✅ FIXED |
code/client/pages/Dashboard.tsx |
Added proper state messages (lines 566-602) | ✅ FIXED |
Architecture Changes
Before:
User logs in
↓
Session restored from cookies
↓
Dashboard auto-redirects to onboarding if !user
↓
User redirected unexpectedly
After:
User logs in
↓
Session restored from cookies
↓
Dashboard checks state:
- Loading? → Show spinner
- Not logged in? → Show "Sign In" message
- No profile? → Show "Complete Profile" message
- Has profile? → Show dashboard
↓
User sees clear message, no redirects
Why This Is Better
- Predictable behavior - No mysterious redirects
- Clear intent - UI explicitly tells you what's happening
- User control - You choose to complete profile, not forced
- Better UX - No more "logged in by default" confusion
- Matches expectations - Dashboard behaves like a normal dashboard
Potential Issues to Watch For
If you're still seeing redirects:
- Clear browser cache (Ctrl+Shift+Delete)
- Hard refresh the page (Ctrl+Shift+R)
- Make sure you deployed the latest code
If messages don't appear:
- Check browser console (F12) for errors
- Verify Dashboard.tsx was updated correctly
- Check that you're seeing the new Dashboard code
If onboarding still appears:
- It should only appear if you click "Complete Profile"
- Check that auto-redirect code was removed
- Verify changes to lines 283-311 and 566-602
Related Fixes
- Session preservation: ✅ FIXED (cookies preserved on page load)
- Discord linking: ✅ FIXED (redirects to connections tab)
- Auth state handling: ✅ IMPROVED (clearer messages)
- Onboarding redirect: ✅ FIXED (no more auto-redirects)
Questions?
Refer to:
- LOGIN-ONBOARDING-REDIRECT-ANALYSIS.md - Detailed root cause analysis
- Browser console (F12) - Check for error messages
- Network tab (F12 → Network) - Check what endpoints are being called
Summary
The core issue was: Dashboard had code that automatically redirected users to onboarding when their user state was empty or loading. This caused unexpected redirects that felt like bugs.
The fix: Removed auto-redirect logic and added clear messages instead. Users now see what's happening and control their own flow (choosing when to complete profile).
Result: No more mysterious redirects, clearer auth state, better UX overall.