Make sure we don't reuse an old NSEUserSession after logging out and back in. (#3273)

This commit is contained in:
Doug 2024-09-12 10:24:05 +01:00 committed by GitHub
parent 022cc59d56
commit d24214c674
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -72,7 +72,9 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
MXLog.info("\(tag) Payload came: \(request.content.userInfo)")
Self.serialQueue.sync {
if Self.userSession == nil {
// If the session directories have changed, the user has logged out and back in (even if they entered the same user ID).
// We can't do this comparison with the access token of the existing session here due to token refresh when using OIDC.
if Self.userSession == nil || Self.userSession?.sessionDirectories != credentials.restorationToken.sessionDirectories {
// This function might be run concurrently and from different processes
// It's imperative that we create **at most** one UserSession/Client per process
Task.synchronous { [appHooks] in

View File

@ -9,6 +9,8 @@ import Foundation
import MatrixRustSDK
final class NSEUserSession {
let sessionDirectories: SessionDirectories
private let baseClient: Client
private let notificationClient: NotificationClient
private let userID: String
@ -18,6 +20,8 @@ final class NSEUserSession {
private let delegateHandle: TaskHandle?
init(credentials: KeychainCredentials, clientSessionDelegate: ClientSessionDelegate, appHooks: AppHooks) async throws {
sessionDirectories = credentials.restorationToken.sessionDirectories
userID = credentials.userID
if credentials.restorationToken.passphrase != nil {
MXLog.info("Restoring client with encrypted store.")