Skip to content

Commit 8c79793

Browse files
committed
fix(deeplink): allow login deeplinks again when logged out
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 0f2333b commit 8c79793

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

app/src/main/java/com/getcode/util/DeeplinkHandler.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import timber.log.Timber
1111
import javax.inject.Inject
1212
import javax.inject.Singleton
1313

14+
data class DeeplinkResult(
15+
val type: DeeplinkHandler.Type,
16+
val stack: List<Screen>,
17+
)
1418
/**
1519
* This class is used to manage intent state across navigation.
1620
*
@@ -45,21 +49,30 @@ class DeeplinkHandler @Inject constructor() {
4549
}
4650
}
4751

48-
fun handle(intent: Intent? = debounceIntent): Pair<Type, List<Screen>>? {
52+
fun handle(intent: Intent? = debounceIntent): DeeplinkResult? {
4953
val uri = intent?.data ?: return null
5054
return when (val type = uri.deeplinkType) {
5155
is Type.Login -> {
52-
type to listOf(LoginScreen(type.link))
56+
DeeplinkResult(
57+
type,
58+
listOf(LoginScreen(type.link)),
59+
)
5360
}
5461

5562
is Type.Cash -> {
5663
Timber.d("cash=${type.link}")
57-
type to listOf(HomeScreen(cashLink = type.link))
64+
DeeplinkResult(
65+
type,
66+
listOf(HomeScreen(cashLink = type.link)),
67+
)
5868
}
5969

6070
is Type.Sdk -> {
6171
Timber.d("sdk=${type.payload}")
62-
type to listOf(HomeScreen(requestPayload = type.payload))
72+
DeeplinkResult(
73+
type,
74+
listOf(HomeScreen(requestPayload = type.payload)),
75+
)
6376
}
6477

6578
is Type.Unknown -> null

app/src/main/java/com/getcode/view/components/AuthCheck.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.getcode.navigation.screens.HomeScreen
2020
import com.getcode.navigation.screens.LoginGraph
2121
import com.getcode.navigation.screens.LoginScreen
2222
import com.getcode.util.DeeplinkHandler
23+
import com.getcode.util.DeeplinkResult
2324
import com.getcode.util.getActivity
2425
import kotlinx.coroutines.CoroutineScope
2526
import kotlinx.coroutines.delay
@@ -38,7 +39,7 @@ import kotlinx.coroutines.launch
3839
import timber.log.Timber
3940

4041
private const val APP_STARTUP_TAG = "app-startup"
41-
private typealias DeeplinkFlowState = Pair<Pair<DeeplinkHandler.Type, List<Screen>>, SessionManager.SessionState>
42+
private typealias DeeplinkFlowState = Pair<DeeplinkResult, SessionManager.SessionState>
4243

4344
@Composable
4445
fun AuthCheck(
@@ -92,7 +93,12 @@ fun AuthCheck(
9293
.filter { (result, authState) ->
9394
startupLog("checking auth state=${authState.isAuthenticated}")
9495
// wait for authentication
95-
return@filter result != null && authState.isAuthenticated == true
96+
if (result == null) return@filter false
97+
if( authState.isAuthenticated == null) {
98+
startupLog("awaiting auth state confirmation")
99+
return@filter false
100+
}
101+
return@filter true
96102
}.mapNotNull { (result, state) ->
97103
result ?: return@mapNotNull null
98104
result to state
@@ -128,22 +134,23 @@ private fun Flow<DeeplinkFlowState>.mapSeedToHome(): Flow<DeeplinkFlowState> =
128134
startupLog("checking type")
129135
val (type, screens) = data
130136
if (type is DeeplinkHandler.Type.Login && auth.isAuthenticated == true) {
137+
startupLog("mapping entropy to home screen")
131138
// send the user to home screen
132139
val entropy = (screens.first() as? LoginScreen)?.seed
133-
val updatedData = type to listOf(HomeScreen(seed = entropy))
140+
val updatedData = data.copy(stack = listOf(HomeScreen(seed = entropy)))
134141
updatedData to auth
135142
} else {
136143
data to auth
137144
}
138145
}
139146

140147

141-
private fun Flow<Pair<DeeplinkHandler.Type, List<Screen>>>.showLogoutConfirmationIfNeeded(
148+
private fun Flow<DeeplinkResult>.showLogoutConfirmationIfNeeded(
142149
context: Context,
143150
scope: CoroutineScope,
144151
onSwitchAccounts: (String) -> Unit,
145152
onCancel: () -> Unit
146-
): Flow<Pair<DeeplinkHandler.Type, List<Screen>>> = onEach { (type, screens) ->
153+
): Flow<DeeplinkResult> = onEach { (type, screens) ->
147154
if (type is DeeplinkHandler.Type.Login) {
148155
val entropy = (screens.first() as? HomeScreen)?.seed
149156
startupLog("showing logout confirm")

0 commit comments

Comments
 (0)