# Sign-In Redirect Fix - ChooseServiceScreen ## Issue After successful sign-in, users should be redirected to `ChooseServiceScreen` instead of other screens. ## Changes Made ### 1. Updated MAIN Graph Start Destination **File**: `MainNavGraph.kt` Changed the start destination of MAIN graph to `ChooseServiceScreen`: ```kotlin navigation( route = Graph.MAIN, startDestination = AppScreen.chooseService("1") // ✅ ChooseServiceScreen ) ``` ### 2. Simplified Sign-In Navigation **File**: `AuthNavGraph.kt` Simplified the `onSuccess` callback to navigate directly to `Graph.MAIN`, which automatically uses the start destination (`ChooseServiceScreen`): **Before**: ```kotlin onSuccess = { // Complex navigation with delays and multiple steps navController.navigate(Graph.MAIN) { ... } // Then navigate to ChooseServiceScreen after delay CoroutineScope(Dispatchers.Main).launch { delay(200) navController.navigate(AppScreen.chooseService("1")) { ... } } } ``` **After**: ```kotlin onSuccess = { // Simple navigation - MAIN graph starts at ChooseServiceScreen navController.navigate(Graph.MAIN) { popUpTo(Graph.AUTH) { inclusive = true } launchSingleTop = true } } ``` ### 3. Updated Sign-In Flow Comments **File**: `OTPScreen.kt` Updated comments to clarify that sign-in navigates to ChooseServiceScreen: ```kotlin if (isSignInFlow) { // For existing users (sign-in), navigate to ChooseServiceScreen android.util.Log.d("OTPScreen", "Existing user - navigating to ChooseServiceScreen") onSuccess() // This navigates to ChooseServiceScreen } ``` ## Navigation Flow ### Sign-In Flow: 1. User enters phone number → `SignInScreen` 2. User enters OTP → `OTPScreen` 3. OTP verified → `authManager.login()` succeeds 4. Tokens saved → `mainViewModel.refreshAuthStatus()` called 5. `onSuccess()` callback triggered 6. Navigate to `Graph.MAIN` → **ChooseServiceScreen** ✅ ### Sign-Up Flow: 1. User fills signup form → `SignUpScreen` 2. User enters OTP → `OTPScreen` 3. OTP verified → User created/updated 4. Signup API called → Profile updated 5. Navigate to `Graph.MAIN` → **ChooseServiceScreen** ✅ ### App Startup Flow: 1. App opens → `MainViewModel` checks tokens 2. If tokens valid → `authState = Authenticated` 3. `AppNavigation` sets `startDestination = Graph.MAIN` 4. `Graph.MAIN` starts at **ChooseServiceScreen** ✅ ## Route Structure ### MAIN Graph: - **Start Destination**: `choose_service/1` (ChooseServiceScreen) - **Other Routes**: - `buy_animals` (BuyScreen) - `create_profile/{name}` (CreateProfileScreen) - etc. ### AUTH Graph: - **Start Destination**: `landing` (LandingScreen) - **Other Routes**: - `sign_in` (SignInScreen) - `sign_up` (SignUpScreen) - `otp/{phoneNumber}/{name}` (OTPScreen) - etc. ## Testing ### ✅ Test Sign-In: 1. Open app → Landing screen 2. Click "Sign In" 3. Enter phone number 4. Enter OTP 5. After successful verification → Should navigate to **ChooseServiceScreen** ✅ ### ✅ Test Sign-Up: 1. Open app → Landing screen 2. Click "Sign Up" 3. Fill form and enter OTP 4. After successful signup → Should navigate to **ChooseServiceScreen** ✅ ### ✅ Test App Reopen (Logged In): 1. Sign in to app 2. Close app completely 3. Reopen app 4. Should open directly to **ChooseServiceScreen** ✅ ## Summary ✅ **Sign-in redirect fixed**: - After successful sign-in → Navigates to **ChooseServiceScreen** - After successful sign-up → Navigates to **ChooseServiceScreen** - App reopen (logged in) → Opens to **ChooseServiceScreen** ✅ **Navigation simplified**: - Removed complex navigation with delays - Uses graph start destination automatically - Cleaner, more maintainable code ✅ **Consistent routing**: - All authenticated users go to ChooseServiceScreen - All unauthenticated users go to LandingScreen - No navigation inconsistencies The sign-in flow now correctly redirects users to ChooseServiceScreen after successful authentication.