Skip to content

Commit

Permalink
fix: SessionManager missing session error
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Nov 15, 2023
1 parent 83cdfef commit 4985c69
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ internal class LogoutUseCaseImpl @Suppress("LongParameterList") constructor(
endCallUseCase(it.conversationId)
}

logoutRepository.logout()
if(reason != LogoutReason.SESSION_EXPIRED) {
logoutRepository.logout()
}

sessionRepository.logout(userId = userId, reason)
logoutRepository.onLogout(reason)
userSessionWorkScheduler.cancelScheduledSendingOfPendingMessages()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,14 @@ class SessionManagerImpl internal constructor(

private var serverConfig: ServerConfigDTO? = null

override suspend fun session(): SessionDTO = withContext(coroutineContext) {
override suspend fun session(): SessionDTO? = withContext(coroutineContext) {
wrapStorageRequest { tokenStorage.getToken(userId.toDao()) }
.map { sessionMapper.fromEntityToSessionDTO(it) }
.fold(
.nullableFold(
{
error(
"""SESSION MANAGER:
|"error": "missing user session",
|"cause": "$it" """.trimMargin()
)
logout(LogoutReason.SESSION_EXPIRED)
null
}, { session ->
kaliumLogger.i("_TOKEN_ FOUND SESSION = $session")
session
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import com.wire.kalium.network.api.v2.authenticated.networkContainer.Authenticat
import com.wire.kalium.network.api.v3.authenticated.networkContainer.AuthenticatedNetworkContainerV3
import com.wire.kalium.network.api.v4.authenticated.networkContainer.AuthenticatedNetworkContainerV4
import com.wire.kalium.network.api.v5.authenticated.networkContainer.AuthenticatedNetworkContainerV5
import com.wire.kalium.network.kaliumLogger
import com.wire.kalium.network.session.CertificatePinning
import com.wire.kalium.network.session.SessionManager
import com.wire.kalium.network.tools.ServerConfigDTO
Expand Down Expand Up @@ -202,8 +201,9 @@ internal class AuthenticatedHttpClientProviderImpl(
}

private val loadToken: suspend () -> BearerTokens? = {
val session = sessionManager.session() ?: error("missing user session")
BearerTokens(accessToken = session.accessToken, refreshToken = session.refreshToken)
sessionManager.session()?.let {session ->
BearerTokens(accessToken = session.accessToken, refreshToken = session.refreshToken)
}
}

private val refreshToken: suspend RefreshTokensParams.() -> BearerTokens = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object CustomErrors {
NetworkResponse.Error(
KaliumException.ServerError(
ErrorResponse(
500,
-1,
"no cookie was found",
NetworkErrorLabel.KaliumCustom.MISSING_REFRESH_TOKEN
)
Expand All @@ -38,7 +38,7 @@ object CustomErrors {
NetworkResponse.Error(
KaliumException.ServerError(
ErrorResponse(
500,
-2,
"no nonce found",
NetworkErrorLabel.KaliumCustom.MISSING_NONCE
)
Expand Down

0 comments on commit 4985c69

Please sign in to comment.