Skip to content

Commit

Permalink
chore: add waitUntilCompletes option to LogoutUseCase (#2185)
Browse files Browse the repository at this point in the history
  • Loading branch information
saleniuk authored Nov 3, 2023
1 parent 821e139 commit 76b3f95
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ import kotlinx.coroutines.launch
interface LogoutUseCase {
/**
* @param reason the reason for the logout performed
* @param waitUntilCompletes if true, the logout suspend fun will wait until all the logout operations are completed
* @see [LogoutReason]
*/
suspend operator fun invoke(reason: LogoutReason)
suspend operator fun invoke(reason: LogoutReason, waitUntilCompletes: Boolean = false)
}

internal class LogoutUseCaseImpl @Suppress("LongParameterList") constructor(
Expand All @@ -68,7 +69,7 @@ internal class LogoutUseCaseImpl @Suppress("LongParameterList") constructor(
// Perhaps [UserSessionScope] (or another specialised class) can observe
// the [LogoutRepository.observeLogout] and invalidating everything in [CoreLogic] level.

override suspend operator fun invoke(reason: LogoutReason) {
override suspend operator fun invoke(reason: LogoutReason, waitUntilCompletes: Boolean) {
globalCoroutineScope.launch {
deregisterTokenUseCase()

Expand All @@ -90,19 +91,21 @@ internal class LogoutUseCaseImpl @Suppress("LongParameterList") constructor(
wipeTokenAndMetadata()
}
}

LogoutReason.SESSION_EXPIRED -> {
if (kaliumConfigs.wipeOnCookieInvalid) {
wipeAllData()
} else {
clearCurrentClientIdAndFirebaseTokenFlag()
}
}

LogoutReason.SELF_SOFT_LOGOUT -> clearCurrentClientIdAndFirebaseTokenFlag()
}

userSessionScopeProvider.get(userId)?.cancel()
userSessionScopeProvider.delete(userId)
}
}.let { if (waitUntilCompletes) it.join() else it }
}

private suspend fun clearCurrentClientIdAndFirebaseTokenFlag() {
Expand Down

0 comments on commit 76b3f95

Please sign in to comment.