Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion NSE/Sources/NotificationServiceExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions NSE/Sources/Other/NSEUserSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.")
Expand Down
Loading