Prettier format pending files

This commit is contained in:
Builder.io 2025-11-10 01:27:19 +00:00
parent 9703824bbc
commit be92cde92a
3 changed files with 71 additions and 17 deletions

View file

@ -305,7 +305,9 @@ export default function Dashboard() {
console.log("User and profile exist, loading dashboard data"); console.log("User and profile exist, loading dashboard data");
loadDashboardData(); loadDashboardData();
} else if (user && !profile) { } else if (user && !profile) {
console.log("User exists but no profile, showing message (not redirecting)"); console.log(
"User exists but no profile, showing message (not redirecting)",
);
setIsLoading(false); setIsLoading(false);
} }
}, [user, profile, authLoading]); }, [user, profile, authLoading]);
@ -579,7 +581,9 @@ export default function Dashboard() {
return ( return (
<div className="min-h-screen bg-gray-900 flex items-center justify-center"> <div className="min-h-screen bg-gray-900 flex items-center justify-center">
<div className="max-w-md text-center"> <div className="max-w-md text-center">
<h1 className="text-3xl font-bold text-white mb-4">Welcome to AeThex</h1> <h1 className="text-3xl font-bold text-white mb-4">
Welcome to AeThex
</h1>
<p className="text-gray-400 mb-8"> <p className="text-gray-400 mb-8">
You need to be signed in to access the dashboard You need to be signed in to access the dashboard
</p> </p>
@ -599,7 +603,9 @@ export default function Dashboard() {
return ( return (
<div className="min-h-screen bg-gray-900 flex items-center justify-center"> <div className="min-h-screen bg-gray-900 flex items-center justify-center">
<div className="max-w-md text-center"> <div className="max-w-md text-center">
<h1 className="text-3xl font-bold text-white mb-4">Complete Your Profile</h1> <h1 className="text-3xl font-bold text-white mb-4">
Complete Your Profile
</h1>
<p className="text-gray-400 mb-8"> <p className="text-gray-400 mb-8">
Let's set up your profile to get started with AeThex Let's set up your profile to get started with AeThex
</p> </p>

View file

@ -3,6 +3,7 @@
## Problem ## Problem
You reported that: You reported that:
1. After logging in, you get redirected to onboarding unexpectedly 1. After logging in, you get redirected to onboarding unexpectedly
2. Site shows you as "logged in" on initial page load but with incomplete profile 2. Site shows you as "logged in" on initial page load but with incomplete profile
3. Users shouldn't appear logged in without a complete profile 3. Users shouldn't appear logged in without a complete profile
@ -27,32 +28,35 @@ You reported that:
**File:** `code/client/pages/Dashboard.tsx` (Lines 283-311) **File:** `code/client/pages/Dashboard.tsx` (Lines 283-311)
**What changed:** **What changed:**
- ❌ **REMOVED:** Code that auto-redirected to `/onboarding` when no user - ❌ **REMOVED:** Code that auto-redirected to `/onboarding` when no user
- ❌ **REMOVED:** Comment saying "redirect to login when auth is resolved" - ❌ **REMOVED:** Comment saying "redirect to login when auth is resolved"
- ✅ **ADDED:** Simple state handling without redirects - ✅ **ADDED:** Simple state handling without redirects
- ✅ **ADDED:** Clear separation of auth loading vs auth resolved states - ✅ **ADDED:** Clear separation of auth loading vs auth resolved states
**Old behavior:** **Old behavior:**
```typescript ```typescript
if (!user && !authLoading) { if (!user && !authLoading) {
navigate("/onboarding", { replace: true }); // AUTO-REDIRECT! navigate("/onboarding", { replace: true }); // AUTO-REDIRECT!
} }
``` ```
**New behavior:** **New behavior:**
```typescript ```typescript
if (authLoading) { if (authLoading) {
setIsLoading(true); // Show loading state setIsLoading(true); // Show loading state
return; return;
} }
if (!user) { if (!user) {
setIsLoading(false); // Auth resolved, no user setIsLoading(false); // Auth resolved, no user
return; return;
} }
if (user && profile) { if (user && profile) {
loadDashboardData(); // Load dashboard data loadDashboardData(); // Load dashboard data
} }
``` ```
@ -63,6 +67,7 @@ if (user && profile) {
**File:** `code/client/pages/Dashboard.tsx` (Lines 566-602) **File:** `code/client/pages/Dashboard.tsx` (Lines 566-602)
**What changed:** **What changed:**
- ❌ **REMOVED:** `return null` when no user (which allowed redirect to happen) - ❌ **REMOVED:** `return null` when no user (which allowed redirect to happen)
- ✅ **ADDED:** "Please Sign In" message with button - ✅ **ADDED:** "Please Sign In" message with button
- ✅ **ADDED:** "Complete Your Profile" message with button - ✅ **ADDED:** "Complete Your Profile" message with button
@ -71,6 +76,7 @@ if (user && profile) {
**New behavior:** **New behavior:**
**When not logged in:** **When not logged in:**
``` ```
┌─────────────────────────┐ ┌─────────────────────────┐
│ Welcome to AeThex │ │ Welcome to AeThex │
@ -84,6 +90,7 @@ if (user && profile) {
``` ```
**When logged in but profile incomplete:** **When logged in but profile incomplete:**
``` ```
┌─────────────────────────┐ ┌─────────────────────────┐
│ Complete Your Profile │ │ Complete Your Profile │
@ -97,6 +104,7 @@ if (user && profile) {
``` ```
**When logged in with complete profile:** **When logged in with complete profile:**
- Full dashboard shown normally - Full dashboard shown normally
--- ---
@ -106,11 +114,13 @@ if (user && profile) {
### Scenario 1: Logging In ### Scenario 1: Logging In
**Before:** **Before:**
1. Enter email/password 1. Enter email/password
2. Submit 2. Submit
3. ❌ Redirected to onboarding (confusing!) 3. ❌ Redirected to onboarding (confusing!)
**After:** **After:**
1. Enter email/password 1. Enter email/password
2. Submit 2. Submit
3. ✅ See dashboard or "Complete Profile" message 3. ✅ See dashboard or "Complete Profile" message
@ -121,11 +131,13 @@ if (user && profile) {
### Scenario 2: Page Reload While Logged In ### Scenario 2: Page Reload While Logged In
**Before:** **Before:**
1. Reload page 1. Reload page
2. ❌ See yourself "logged in" for a moment 2. ❌ See yourself "logged in" for a moment
3. ❌ Maybe get redirected to onboarding 3. ❌ Maybe get redirected to onboarding
**After:** **After:**
1. Reload page 1. Reload page
2. ✅ See loading state briefly 2. ✅ See loading state briefly
3. ✅ Dashboard appears or message about completing profile 3. ✅ Dashboard appears or message about completing profile
@ -136,10 +148,12 @@ if (user && profile) {
### Scenario 3: Visiting Dashboard When Not Logged In ### Scenario 3: Visiting Dashboard When Not Logged In
**Before:** **Before:**
1. Visit `/dashboard` without being logged in 1. Visit `/dashboard` without being logged in
2. ❌ Redirected to onboarding (wrong!) 2. ❌ Redirected to onboarding (wrong!)
**After:** **After:**
1. Visit `/dashboard` without being logged in 1. Visit `/dashboard` without being logged in
2. ✅ See "Please Sign In" message 2. ✅ See "Please Sign In" message
3. ✅ Click button to go to login page 3. ✅ Click button to go to login page
@ -149,19 +163,23 @@ if (user && profile) {
## What This Means ## What This Means
✅ **No more mysterious redirects** ✅ **No more mysterious redirects**
- You won't be auto-redirected to onboarding unexpectedly - You won't be auto-redirected to onboarding unexpectedly
- Your destination is clear (dashboard or complete profile) - Your destination is clear (dashboard or complete profile)
✅ **No confusing "logged in by default" state** ✅ **No confusing "logged in by default" state**
- Loading spinner shows while profile is being fetched - Loading spinner shows while profile is being fetched
- You don't see yourself logged in until profile is actually loaded - You don't see yourself logged in until profile is actually loaded
✅ **User control over onboarding** ✅ **User control over onboarding**
- You choose when to complete your profile - You choose when to complete your profile
- Not forced by automatic redirects - Not forced by automatic redirects
- Clear button to start onboarding - Clear button to start onboarding
✅ **Clear error messages** ✅ **Clear error messages**
- "Sign In" message when not authenticated - "Sign In" message when not authenticated
- "Complete Profile" message when missing profile data - "Complete Profile" message when missing profile data
- No guessing what state you're in - No guessing what state you're in
@ -171,6 +189,7 @@ if (user && profile) {
## Testing the Fix ## Testing the Fix
### Test 1: Log In and Go to Dashboard ### Test 1: Log In and Go to Dashboard
1. Visit `/login` 1. Visit `/login`
2. Sign in with email/password 2. Sign in with email/password
3. **Expected:** Should see dashboard or "Complete Profile" message 3. **Expected:** Should see dashboard or "Complete Profile" message
@ -178,6 +197,7 @@ if (user && profile) {
5. **If profile incomplete:** Click "Complete Profile" button intentionally 5. **If profile incomplete:** Click "Complete Profile" button intentionally
### Test 2: Reload Dashboard While Logged In ### Test 2: Reload Dashboard While Logged In
1. Log in successfully 1. Log in successfully
2. Visit `/dashboard` 2. Visit `/dashboard`
3. Reload page (F5 or Ctrl+R) 3. Reload page (F5 or Ctrl+R)
@ -185,12 +205,14 @@ if (user && profile) {
5. **NOT expected:** Redirect to onboarding or seeing "logged in by default" 5. **NOT expected:** Redirect to onboarding or seeing "logged in by default"
### Test 3: Visit Dashboard When Not Logged In ### Test 3: Visit Dashboard When Not Logged In
1. Make sure you're logged out (go to `/logout` or clear cookies) 1. Make sure you're logged out (go to `/logout` or clear cookies)
2. Visit `/dashboard` 2. Visit `/dashboard`
3. **Expected:** See "Please Sign In" message with button 3. **Expected:** See "Please Sign In" message with button
4. **NOT expected:** Redirect to onboarding 4. **NOT expected:** Redirect to onboarding
### Test 4: Sign Out and Back In ### Test 4: Sign Out and Back In
1. While on dashboard, click Sign Out 1. While on dashboard, click Sign Out
2. **Expected:** Should see "Please Sign In" message 2. **Expected:** Should see "Please Sign In" message
3. Click Sign In button 3. Click Sign In button
@ -202,8 +224,8 @@ if (user && profile) {
## Files Modified ## Files Modified
| File | Changes | Status | | File | Changes | Status |
|------|---------|--------| | --------------------------------- | ------------------------------------------- | -------- |
| `code/client/pages/Dashboard.tsx` | Removed auto-redirect logic (lines 283-311) | ✅ FIXED | | `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 | | `code/client/pages/Dashboard.tsx` | Added proper state messages (lines 566-602) | ✅ FIXED |
@ -212,6 +234,7 @@ if (user && profile) {
## Architecture Changes ## Architecture Changes
**Before:** **Before:**
``` ```
User logs in User logs in
@ -223,6 +246,7 @@ User redirected unexpectedly
``` ```
**After:** **After:**
``` ```
User logs in User logs in
@ -252,16 +276,19 @@ User sees clear message, no redirects
## Potential Issues to Watch For ## Potential Issues to Watch For
### If you're still seeing redirects: ### If you're still seeing redirects:
1. Clear browser cache (Ctrl+Shift+Delete) 1. Clear browser cache (Ctrl+Shift+Delete)
2. Hard refresh the page (Ctrl+Shift+R) 2. Hard refresh the page (Ctrl+Shift+R)
3. Make sure you deployed the latest code 3. Make sure you deployed the latest code
### If messages don't appear: ### If messages don't appear:
1. Check browser console (F12) for errors 1. Check browser console (F12) for errors
2. Verify Dashboard.tsx was updated correctly 2. Verify Dashboard.tsx was updated correctly
3. Check that you're seeing the new Dashboard code 3. Check that you're seeing the new Dashboard code
### If onboarding still appears: ### If onboarding still appears:
1. It should only appear if you click "Complete Profile" 1. It should only appear if you click "Complete Profile"
2. Check that auto-redirect code was removed 2. Check that auto-redirect code was removed
3. Verify changes to lines 283-311 and 566-602 3. Verify changes to lines 283-311 and 566-602
@ -280,6 +307,7 @@ User sees clear message, no redirects
## Questions? ## Questions?
Refer to: Refer to:
1. **LOGIN-ONBOARDING-REDIRECT-ANALYSIS.md** - Detailed root cause analysis 1. **LOGIN-ONBOARDING-REDIRECT-ANALYSIS.md** - Detailed root cause analysis
2. Browser console (F12) - Check for error messages 2. Browser console (F12) - Check for error messages
3. Network tab (F12 → Network) - Check what endpoints are being called 3. Network tab (F12 → Network) - Check what endpoints are being called

View file

@ -3,6 +3,7 @@
## Problem Statement ## Problem Statement
User reports: User reports:
1. After logging in, they get redirected to onboarding 1. After logging in, they get redirected to onboarding
2. When first loading the site, it shows them as "logged in" but with incomplete profile 2. When first loading the site, it shows them as "logged in" but with incomplete profile
3. Frustrated because users shouldn't be shown as logged in without a complete profile 3. Frustrated because users shouldn't be shown as logged in without a complete profile
@ -15,6 +16,7 @@ User reports:
### Issue 1: Session Restoration Before Profile Completion Check ### Issue 1: Session Restoration Before Profile Completion Check
**What happens:** **What happens:**
1. User logs in successfully 1. User logs in successfully
2. Session cookies are set by Supabase 2. Session cookies are set by Supabase
3. Page reloads or user navigates 3. Page reloads or user navigates
@ -25,6 +27,7 @@ User reports:
8. Once profile loads, if incomplete, they might be redirected 8. Once profile loads, if incomplete, they might be redirected
**Why it's confusing:** **Why it's confusing:**
- User sees themselves logged in - User sees themselves logged in
- But profile might still be loading - But profile might still be loading
- Then get redirected to onboarding - Then get redirected to onboarding
@ -36,12 +39,14 @@ User reports:
**What's happening:** **What's happening:**
The AuthContext loads the session from browser storage immediately: The AuthContext loads the session from browser storage immediately:
- Supabase session stored in cookies/IndexedDB - Supabase session stored in cookies/IndexedDB
- On page load, `onAuthStateChange` fires with existing session - On page load, `onAuthStateChange` fires with existing session
- User state is set - User state is set
- UI shows user as authenticated - UI shows user as authenticated
**But:** **But:**
- Profile data takes time to load from database - Profile data takes time to load from database
- UI briefly shows "logged in" before profile is available - UI briefly shows "logged in" before profile is available
- This can feel like users are logged in "by default" - This can feel like users are logged in "by default"
@ -51,6 +56,7 @@ The AuthContext loads the session from browser storage immediately:
### Issue 3: Onboarding Redirect Logic ### Issue 3: Onboarding Redirect Logic
**Current logic in Dashboard.tsx (line 291):** **Current logic in Dashboard.tsx (line 291):**
```typescript ```typescript
if (!user && !authLoading) { if (!user && !authLoading) {
navigate("/onboarding", { replace: true }); navigate("/onboarding", { replace: true });
@ -58,6 +64,7 @@ if (!user && !authLoading) {
``` ```
**Issues with this:** **Issues with this:**
1. Redirects to onboarding if NO user 1. Redirects to onboarding if NO user
2. But never checks if profile is INCOMPLETE 2. But never checks if profile is INCOMPLETE
3. Should either: 3. Should either:
@ -71,11 +78,13 @@ if (!user && !authLoading) {
**Current behavior is confusing because:** **Current behavior is confusing because:**
1. **Mixed signals:** 1. **Mixed signals:**
- User sees themselves logged in - User sees themselves logged in
- Then gets redirected to onboarding - Then gets redirected to onboarding
- Feels like auth is broken - Feels like auth is broken
2. **No clear intent:** 2. **No clear intent:**
- Onboarding is meant to COMPLETE the profile - Onboarding is meant to COMPLETE the profile
- But if you're already logged in, you should be on dashboard - But if you're already logged in, you should be on dashboard
- Redirect should only happen if profile is incomplete - Redirect should only happen if profile is incomplete
@ -93,13 +102,15 @@ if (!user && !authLoading) {
**Current:** Line 291-295 in Dashboard.tsx checks `if (!user)` and redirects **Current:** Line 291-295 in Dashboard.tsx checks `if (!user)` and redirects
**Should be:** **Should be:**
- If no user → stay on dashboard (it handles showing loading state) - If no user → stay on dashboard (it handles showing loading state)
- If user but profile incomplete → show a prompt, don't redirect - If user but profile incomplete → show a prompt, don't redirect
- If user and profile complete → show full dashboard - If user and profile complete → show full dashboard
**Change:** **Change:**
Remove the automatic redirect to onboarding. Instead: Remove the automatic redirect to onboarding. Instead:
- Let Dashboard render - Let Dashboard render
- Show a "Complete Your Profile" banner if profile is incomplete - Show a "Complete Your Profile" banner if profile is incomplete
- Let user click to go to onboarding, don't force redirect - Let user click to go to onboarding, don't force redirect
@ -111,6 +122,7 @@ Remove the automatic redirect to onboarding. Instead:
**Current:** Session restored from cookies → UI shows user as logged in immediately **Current:** Session restored from cookies → UI shows user as logged in immediately
**Should be:** **Should be:**
- Show loading state while profile is being fetched - Show loading state while profile is being fetched
- Don't show user as "logged in" until profile is loaded - Don't show user as "logged in" until profile is loaded
- Once profile loads, show actual dashboard - Once profile loads, show actual dashboard
@ -125,11 +137,13 @@ Ensure `loading` state is true while profile is being fetched, then show Loading
**Current:** Onboarding shows up unexpectedly after login **Current:** Onboarding shows up unexpectedly after login
**Should be:** **Should be:**
- Onboarding only when INTENTIONALLY started (user clicks "Complete Profile") - Onboarding only when INTENTIONALLY started (user clicks "Complete Profile")
- Not automatically triggered by auth state - Not automatically triggered by auth state
- Dashboard can show "Profile incomplete" message with link to onboarding - Dashboard can show "Profile incomplete" message with link to onboarding
**Change:** **Change:**
- Remove auto-redirect logic - Remove auto-redirect logic
- Let Dashboard handle incomplete profile display - Let Dashboard handle incomplete profile display
- User explicitly chooses to complete profile - User explicitly chooses to complete profile
@ -141,13 +155,14 @@ Ensure `loading` state is true while profile is being fetched, then show Loading
### In code/client/pages/Dashboard.tsx (Lines 283-311) ### In code/client/pages/Dashboard.tsx (Lines 283-311)
**Current (WRONG):** **Current (WRONG):**
```typescript ```typescript
useEffect(() => { useEffect(() => {
if (!user && !authLoading) { if (!user && !authLoading) {
navigate("/onboarding", { replace: true }); navigate("/onboarding", { replace: true });
return; return;
} }
if (user && profile) { if (user && profile) {
loadDashboardData(); loadDashboardData();
} }
@ -155,11 +170,12 @@ useEffect(() => {
``` ```
**Should be:** **Should be:**
```typescript ```typescript
useEffect(() => { useEffect(() => {
// Don't auto-redirect to onboarding // Don't auto-redirect to onboarding
// Let Dashboard render and handle missing profile gracefully // Let Dashboard render and handle missing profile gracefully
if (user && profile) { if (user && profile) {
loadDashboardData(); loadDashboardData();
} }
@ -171,6 +187,7 @@ useEffect(() => {
### In code/client/pages/Dashboard.tsx (Top level) ### In code/client/pages/Dashboard.tsx (Top level)
**Add this check:** **Add this check:**
```typescript ```typescript
// If loading, show loading state // If loading, show loading state
if (authLoading) { if (authLoading) {
@ -212,6 +229,7 @@ if (!profile) {
## Expected Behavior After Fix ## Expected Behavior After Fix
### Scenario 1: Fresh Login ### Scenario 1: Fresh Login
1. User logs in with email/password 1. User logs in with email/password
2. Redirected to dashboard 2. Redirected to dashboard
3. Dashboard shows loading state while profile is fetched 3. Dashboard shows loading state while profile is fetched
@ -220,6 +238,7 @@ if (!profile) {
- If profile incomplete → show "Complete Your Profile" banner with link to onboarding - If profile incomplete → show "Complete Your Profile" banner with link to onboarding
### Scenario 2: Page Reload While Logged In ### Scenario 2: Page Reload While Logged In
1. User is logged in, page reloads 1. User is logged in, page reloads
2. Supabase session restored from cookies 2. Supabase session restored from cookies
3. AuthContext restores user and fetches profile 3. AuthContext restores user and fetches profile
@ -227,6 +246,7 @@ if (!profile) {
5. Once profile loaded → show dashboard (complete or with banner) 5. Once profile loaded → show dashboard (complete or with banner)
### Scenario 3: Not Logged In ### Scenario 3: Not Logged In
1. Unauthenticated user visits `/dashboard` 1. Unauthenticated user visits `/dashboard`
2. Dashboard detects no user 2. Dashboard detects no user
3. Shows "Please sign in" message 3. Shows "Please sign in" message
@ -253,11 +273,11 @@ After implementing fixes:
## Files to Update ## Files to Update
| File | Lines | Change | | File | Lines | Change |
|------|-------|--------| | --------------------------------- | --------------- | ----------------------------- |
| `code/client/pages/Dashboard.tsx` | 283-311 | Remove onboarding redirect | | `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` | Start of render | Add loading/auth state checks |
| `code/client/pages/Dashboard.tsx` | TBD | Add "Complete Profile" banner | | `code/client/pages/Dashboard.tsx` | TBD | Add "Complete Profile" banner |
--- ---
@ -273,7 +293,7 @@ After implementing fixes:
## Related Issues ## Related Issues
- AuthContext clearing session on page load: ✅ FIXED (preserves sb-* keys) - AuthContext clearing session on page load: ✅ FIXED (preserves sb-\* keys)
- Session persistence: ✅ WORKING (cookies restored correctly) - Session persistence: ✅ WORKING (cookies restored correctly)
- Profile loading timing: ⚠️ CAUSES UI CONFUSION (session shown before profile) - Profile loading timing: ⚠️ CAUSES UI CONFUSION (session shown before profile)