fix: redirect logged-in users to home screen on app launch#180
fix: redirect logged-in users to home screen on app launch#180hasanravda wants to merge 4 commits intoAOSSIE-Org:mainfrom
Conversation
…d onboarding status
…us in splash screen
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughSplash screen navigation was changed to check Supabase for a current session, query onboarding status via AuthProvider, and then navigate to the correct next screen (Home, PersonalDetails, AssessmentsList, ConsultationRequest) or fallback to AuthScreen with error feedback. Changes
Sequence Diagram(s)sequenceDiagram
participant Splash as SplashScreen
participant Supa as Supabase (auth)
participant AuthP as AuthProvider
participant Nav as Navigator
participant Snack as SnackbarService
Splash->>Supa: check currentSession
alt session exists
Splash->>AuthP: fetchOnboardingStatus(userId)
AuthP-->>Splash: onboardingStatus (home/personal/assess/consult) or error
alt status resolved
Splash->>AuthP: resetNavigationStatus()
Splash->>Nav: pushReplacement(selected Screen)
else error/unknown
Splash->>Snack: show error message
Splash->>Nav: pushReplacement(AuthScreen)
end
else no session
Splash->>Nav: pushReplacement(AuthScreen)
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@patient/lib/presentation/splash_screen.dart`:
- Around line 53-58: When handling the error/unknown branch (the block using
status.isError, SnackbarService.showError and setting nextScreen = const
AuthScreen()), clear the current Supabase session before navigating back to
AuthScreen by calling your auth client's sign-out/clear-session method (e.g.,
invoke signOut() on the Supabase auth client or your AuthRepository.signOut()).
Ensure this sign-out call happens before assigning nextScreen = const
AuthScreen() so the next launch doesn't see a stale session.
- Around line 37-38: Wrap the await
context.read<AuthProvider>().checkIfPatientExists() call in a try/catch so any
thrown exceptions are handled the same way as failed results: catch all errors,
ensure you still check mounted before routing, and set the provider/navigation
fallback to AuthNavigationStatus.error (or call the same fallback path used for
unsuccessful results) instead of letting the exception bubble and leave the app
stuck on Splash; reference checkIfPatientExists(), AuthProvider, mounted and
AuthNavigationStatus.error when making the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 58e02ed9-01ac-4b8f-9af9-de8cffd2b12d
📒 Files selected for processing (1)
patient/lib/presentation/splash_screen.dart
There was a problem hiding this comment.
♻️ Duplicate comments (1)
patient/lib/presentation/splash_screen.dart (1)
39-44:⚠️ Potential issue | 🟠 MajorClear the Supabase session before redirecting to
AuthScreen.Both fallback paths inside the
session != nullbranch route back toAuthScreen, but they leavecurrentSessionintact. That leaves the app on a sign-in screen while Supabase still considers the user authenticated, and the next launch can re-enter the same failing splash flow.Suggested fix
try { await context.read<AuthProvider>().checkIfPatientExists(); } catch (_) { + await Supabase.instance.client.auth.signOut(); + if (!mounted) return; SnackbarService.showError('Something went wrong. Please sign in again.'); Navigator.of(context).pushReplacement( MaterialPageRoute(builder: (_) => const AuthScreen()), ); return; @@ } else { // error or unknown — fall back to sign-in with feedback + await Supabase.instance.client.auth.signOut(); + if (!mounted) return; if (status.isError) { SnackbarService.showError('Something went wrong. Please sign in again.'); } nextScreen = const AuthScreen(); }In supabase_flutter 2.8.4, does `Supabase.instance.client.auth.signOut()` clear the persisted local session so `Supabase.instance.client.auth.currentSession` is null on the next app launch?Also applies to: 62-67
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@patient/lib/presentation/splash_screen.dart` around lines 39 - 44, The fallback/catch flows in splash_screen.dart navigate to AuthScreen but do not clear the Supabase session, leaving Supabase.instance.client.auth.currentSession populated; update the flows that call SnackbarService.showError(...) and Navigator.of(context).pushReplacement(... -> const AuthScreen()) to first await Supabase.instance.client.auth.signOut() (handle errors safely and check mounted before navigating) so the persisted session is cleared before pushing AuthScreen; apply the same change to both the catch block (where the catch currently uses SnackbarService.showError and Navigator) and the other fallback path around the 62-67 region to ensure currentSession is null on next launch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@patient/lib/presentation/splash_screen.dart`:
- Around line 39-44: The fallback/catch flows in splash_screen.dart navigate to
AuthScreen but do not clear the Supabase session, leaving
Supabase.instance.client.auth.currentSession populated; update the flows that
call SnackbarService.showError(...) and
Navigator.of(context).pushReplacement(... -> const AuthScreen()) to first await
Supabase.instance.client.auth.signOut() (handle errors safely and check mounted
before navigating) so the persisted session is cleared before pushing
AuthScreen; apply the same change to both the catch block (where the catch
currently uses SnackbarService.showError and Navigator) and the other fallback
path around the 62-67 region to ensure currentSession is null on next launch.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a53033b9-8267-4eea-ad32-d3dfc863ea4c
📒 Files selected for processing (1)
patient/lib/presentation/splash_screen.dart
|
Can you review this @jddeep @SharkyBytes ? |
Closes #179
📝 Description
Every time the Patient app was launched, users were shown the Login screen - even if they had already signed in. This happened because
SplashScreenalways navigated toAuthScreenunconditionally after the 3-second splash delay, without ever checking whether a valid Supabase session already existed.This fix makes the splash screen session-aware. On launch, it now checks for an active session and routes the user directly to the right screen based on their onboarding progress - skipping the login flow entirely for returning users.
🔧 Changes Made
patient/lib/presentation/splash_screen.dartSupabase.instance.client.auth.currentSessionafter the splash delaycheckIfPatientExists()and route directly to the correct screen (HomeScreen,PersonalDetailsScreen,AssessmentsListScreen, orConsultationRequestScreen)status.isError→ show error snackbar before falling back toAuthScreenAuthScreenas before (no change for logged-out users)📷 Screenshots or Visual Changes (if applicable)
NeuroTrack.Splash.Auth.issue.mp4
✅ Checklist
Summary by CodeRabbit