Skip to content

Commit 01468d9

Browse files
committed
Show correct error screen scanning a QR that is valid but unsupported
Uses the new .UnsupportedQrCodeType enum errors code from the SDK in matrix-org/matrix-rust-sdk#6285. Specifically this means that if a QR from a new version of MSC4108 is encountered then it shows it as "wrong QR" rather than "the other device isn't signed in".
1 parent a4e5445 commit 01468d9

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

ElementX/Sources/Services/Authentication/AuthenticationService.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,21 @@ class AuthenticationService: AuthenticationServiceProtocol {
179179
return progressSubject.asCurrentValuePublisher()
180180
}
181181

182-
// At some stage the SDK will have a `qrCodeData.intent` which we should check before continuing here.
183-
// Note the equivalent check will also happen for linking a device by QR in the LinkNewDeviceService.
182+
// n.b. We rely on the SDK checking that the intent of the QR is suitable for us to login with.
184183

185-
guard let scannedServerName = qrData.serverName() else {
184+
// Future versions of the QR should always give us the baseUrl
185+
guard let scannedServerNameOrBaseUrl = qrData.baseUrl() ?? qrData.serverName() else {
186+
// With the older version of QR we treat the presence of serverName as meaning that the other device
187+
// is not signed in.
186188
MXLog.error("The QR code is from a device that is not yet signed in.")
187189
progressSubject.send(completion: .failure(.qrCodeError(.deviceNotSignedIn)))
188190
return progressSubject.asCurrentValuePublisher()
189191
}
190192

191-
if !appSettings.allowOtherAccountProviders, !appSettings.accountProviders.contains(scannedServerName) {
192-
MXLog.error("The scanned device's server is not allowed: \(scannedServerName)")
193-
progressSubject.send(completion: .failure(.qrCodeError(.providerNotAllowed(scannedProvider: scannedServerName, allowedProviders: appSettings.accountProviders))))
193+
// TODO: do we need to extract the serverName from the baseUrl?
194+
if !appSettings.allowOtherAccountProviders, !appSettings.accountProviders.contains(scannedServerNameOrBaseUrl) {
195+
MXLog.error("The scanned device's server is not allowed: \(scannedServerNameOrBaseUrl)")
196+
progressSubject.send(completion: .failure(.qrCodeError(.providerNotAllowed(scannedProvider: scannedServerNameOrBaseUrl, allowedProviders: appSettings.accountProviders))))
194197
return progressSubject.asCurrentValuePublisher()
195198
}
196199

@@ -201,7 +204,7 @@ class AuthenticationService: AuthenticationServiceProtocol {
201204

202205
Task {
203206
do {
204-
let client = try await makeClient(homeserverAddress: scannedServerName)
207+
let client = try await makeClient(homeserverAddress: scannedServerNameOrBaseUrl)
205208
let qrCodeHandler = client.newLoginWithQrCodeHandler(oidcConfiguration: appSettings.oidcConfiguration.rustValue)
206209
try await qrCodeHandler.scan(qrCodeData: qrData, progressListener: listener)
207210

@@ -281,6 +284,8 @@ private extension HumanQrLoginError {
281284
.qrCodeError(.slidingSyncNotAvailable)
282285
case .OtherDeviceNotSignedIn:
283286
.qrCodeError(.deviceNotSignedIn)
287+
case .UnsupportedQrCodeType:
288+
.qrCodeError(.invalidQRCode)
284289
case .Unknown, .OidcMetadataInvalid, .CheckCodeAlreadySent, .CheckCodeCannotBeSent:
285290
.qrCodeError(.unknown)
286291
}

ElementX/Sources/Services/Authentication/LinkNewDeviceService.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ private extension QRCodeLoginError {
201201
.cancelled
202202
case .OtherDeviceAlreadySignedIn:
203203
.deviceAlreadySignedIn
204+
case .UnsupportedQrCodeType:
205+
.invalidQRCode
204206
case .Unknown, .MissingSecretsBackup, .DeviceIdAlreadyInUse:
205207
.unknown
206208
}

0 commit comments

Comments
 (0)