Skip to content

Commit e39c51c

Browse files
committed
fix(auth): skip network retries during offline cold launch
Check connectivity before retrying getUserFlags(), updateUserProfile(), and savePrefs() in login(). When offline during a soft login (app restart), flags resolve to null immediately and the existing local fallback sets AuthState.Ready from cached DataStore — eliminating the ~6s spinner caused by 3 failed retries with 2s delays. Interactive logins still always attempt the network fetch. Data refreshes on reconnect via RealSessionController. Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 68dfd3b commit e39c51c

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

  • apps/flipcash/shared/authentication/src/main/kotlin/com/flipcash/app/auth

apps/flipcash/shared/authentication/src/main/kotlin/com/flipcash/app/auth/AuthManager.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.getcode.opencode.model.core.ID
2222
import com.getcode.utils.TraceManager
2323
import com.getcode.utils.TraceType
2424
import com.flipcash.libs.coroutines.DispatcherProvider
25+
import com.getcode.utils.network.NetworkConnectivityListener
2526
import com.getcode.utils.network.retryable
2627
import com.getcode.utils.trace
2728
import kotlinx.coroutines.CoroutineScope
@@ -49,6 +50,7 @@ class AuthManager @Inject constructor(
4950
private val appSettings: AppSettingsCoordinator,
5051
private val userFlags: UserFlagsCoordinator,
5152
private val contactCoordinator: ContactCoordinator,
53+
private val networkObserver: NetworkConnectivityListener,
5254
private val dispatchers: DispatcherProvider,
5355
// private val analytics: AnalyticsService,
5456
) : CoroutineScope by CoroutineScope(dispatchers.IO) {
@@ -192,8 +194,12 @@ class AuthManager @Inject constructor(
192194

193195
coroutineScope {
194196
launch {
195-
val flags = retryable(maxRetries = 3) {
196-
accountController.getUserFlags().getOrNull()
197+
val flags = if (!isSoftLogin || networkObserver.isConnected) {
198+
retryable(maxRetries = 3) {
199+
accountController.getUserFlags().getOrNull()
200+
}
201+
} else {
202+
null
197203
}
198204

199205
val seenAccessKey = credentialManager.hasSeenAccessKey()
@@ -228,9 +234,13 @@ class AuthManager @Inject constructor(
228234
}
229235
}
230236

231-
profileController.updateUserProfile()
237+
if (networkObserver.isConnected) {
238+
profileController.updateUserProfile()
239+
}
240+
}
241+
if (networkObserver.isConnected) {
242+
launch { savePrefs() }
232243
}
233-
launch { savePrefs() }
234244
}
235245
}.onFailure {
236246
logout()

0 commit comments

Comments
 (0)