Do not restore session with invalid token.

This commit is contained in:
Benoit Marty
2023-10-09 20:36:49 +02:00
committed by Benoit Marty
parent 5faf706264
commit 529872a4f2
2 changed files with 10 additions and 1 deletions

View File

@@ -25,6 +25,11 @@ import kotlinx.coroutines.flow.StateFlow
interface MatrixAuthenticationService {
fun loggedInStateFlow(): Flow<LoggedInState>
suspend fun getLatestSessionId(): SessionId?
/**
* Restore a session from a [sessionId].
* Do not restore anything it the access token is not valid anymore.
*/
suspend fun restoreSession(sessionId: SessionId): Result<MatrixClient>
fun getHomeserverDetails(): StateFlow<MatrixHomeServerDetails?>
suspend fun setHomeserver(homeserver: String): Result<Unit>

View File

@@ -76,7 +76,11 @@ class RustMatrixAuthenticationService @Inject constructor(
runCatching {
val sessionData = sessionStore.getSession(sessionId.value)
if (sessionData != null) {
rustMatrixClientFactory.create(sessionData)
if (sessionData.isTokenValid) {
rustMatrixClientFactory.create(sessionData)
} else {
error("Token is not valid")
}
} else {
error("No session to restore with id $sessionId")
}