@@ -7,6 +7,7 @@ import androidx.compose.runtime.collectAsState
77import androidx.compose.runtime.getValue
88import androidx.compose.runtime.mutableStateOf
99import androidx.compose.runtime.remember
10+ import androidx.compose.runtime.rememberCoroutineScope
1011import androidx.compose.runtime.setValue
1112import androidx.compose.ui.platform.LocalContext
1213import cafe.adriel.voyager.core.screen.Screen
@@ -21,11 +22,13 @@ import com.getcode.navigation.screens.LoginGraph
2122import com.getcode.navigation.screens.LoginScreen
2223import com.getcode.util.DeeplinkHandler
2324import com.getcode.util.getActivity
25+ import kotlinx.coroutines.delay
2426import kotlinx.coroutines.flow.filter
2527import kotlinx.coroutines.flow.filterNotNull
2628import kotlinx.coroutines.flow.launchIn
2729import kotlinx.coroutines.flow.mapNotNull
2830import kotlinx.coroutines.flow.onEach
31+ import kotlinx.coroutines.launch
2932import timber.log.Timber
3033
3134const val AUTH_NAV = " Authentication Navigation"
@@ -47,6 +50,7 @@ fun AuthCheck(
4750 }
4851
4952 LaunchedEffect (isAuthenticated) {
53+ Timber .tag(AUTH_NAV ).d(" authenticated=$isAuthenticated " )
5054 isAuthenticated?.let { authenticated ->
5155 // Allow the seed input screen to complete and avoid
5256 // premature navigation
@@ -72,7 +76,9 @@ fun AuthCheck(
7276
7377 val context = LocalContext .current
7478 deeplinkHandler ? : return
79+
7580 LaunchedEffect (deeplinkHandler) {
81+ val scope = this
7682 deeplinkHandler.intent
7783 .filterNotNull()
7884 .onEach {
@@ -96,7 +102,20 @@ fun AuthCheck(
96102 deeplinkRouted = true
97103 context.getActivity()?.intent = null
98104 deeplinkHandler.debounceIntent = null
99- showLogoutMessage(context, entropy, onSwitchAccounts)
105+ showLogoutMessage(
106+ context = context,
107+ entropyB64 = entropy,
108+ onSwitchAccounts = {
109+ scope.launch {
110+ delay(300 )
111+ onSwitchAccounts(it)
112+ deeplinkRouted = false
113+ }
114+ },
115+ onCancel = {
116+ deeplinkRouted = false
117+ }
118+ )
100119 return @mapNotNull null
101120 }
102121 }
@@ -117,7 +136,8 @@ fun AuthCheck(
117136private fun showLogoutMessage (
118137 context : Context ,
119138 entropyB64 : String ,
120- onSwitchAccounts : (String ) -> Unit
139+ onSwitchAccounts : (String ) -> Unit ,
140+ onCancel : () -> Unit ,
121141) {
122142 BottomBarManager .showMessage(
123143 BottomBarManager .BottomBarMessage (
@@ -129,7 +149,7 @@ private fun showLogoutMessage(
129149 onPositive = {
130150 onSwitchAccounts(entropyB64)
131151 },
132- onNegative = { }
152+ onNegative = { onCancel() }
133153 )
134154 )
135155}
0 commit comments