Skip to content

Commit eac155f

Browse files
[Auth] More Swift 6 progress (#14867)
Co-authored-by: Morgan Chen <morganchen12@gmail.com>
1 parent 82e780c commit eac155f

File tree

5 files changed

+43
-26
lines changed

5 files changed

+43
-26
lines changed

FirebaseAuth/Sources/Swift/AuthProvider/PhoneAuthProvider.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
import FirebaseCore
1616
import Foundation
1717

18+
// TODO(Swift 6 Breaking): Make checked Sendable.
19+
1820
/// A concrete implementation of `AuthProvider` for phone auth providers.
1921
///
2022
/// This class is available on iOS only.
2123
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
22-
@objc(FIRPhoneAuthProvider) open class PhoneAuthProvider: NSObject {
24+
@objc(FIRPhoneAuthProvider) open class PhoneAuthProvider: NSObject, @unchecked Sendable {
2325
/// A string constant identifying the phone identity provider.
2426
@objc public static let id = "phone"
2527
private static let recaptchaVersion = "RECAPTCHA_ENTERPRISE"
@@ -56,7 +58,7 @@ import Foundation
5658
@objc(verifyPhoneNumber:UIDelegate:completion:)
5759
open func verifyPhoneNumber(_ phoneNumber: String,
5860
uiDelegate: AuthUIDelegate? = nil,
59-
completion: ((_: String?, _: Error?) -> Void)?) {
61+
completion: (@MainActor (String?, Error?) -> Void)?) {
6062
verifyPhoneNumber(phoneNumber,
6163
uiDelegate: uiDelegate,
6264
multiFactorSession: nil,
@@ -75,21 +77,17 @@ import Foundation
7577
open func verifyPhoneNumber(_ phoneNumber: String,
7678
uiDelegate: AuthUIDelegate? = nil,
7779
multiFactorSession: MultiFactorSession? = nil,
78-
completion: ((_: String?, _: Error?) -> Void)?) {
80+
completion: (@MainActor (String?, Error?) -> Void)?) {
7981
Task {
8082
do {
8183
let verificationID = try await verifyPhoneNumber(
8284
phoneNumber,
8385
uiDelegate: uiDelegate,
8486
multiFactorSession: multiFactorSession
8587
)
86-
await MainActor.run {
87-
completion?(verificationID, nil)
88-
}
88+
await completion?(verificationID, nil)
8989
} catch {
90-
await MainActor.run {
91-
completion?(nil, error)
92-
}
90+
await completion?(nil, error)
9391
}
9492
}
9593
}
@@ -135,7 +133,7 @@ import Foundation
135133
open func verifyPhoneNumber(with multiFactorInfo: PhoneMultiFactorInfo,
136134
uiDelegate: AuthUIDelegate? = nil,
137135
multiFactorSession: MultiFactorSession?,
138-
completion: ((_: String?, _: Error?) -> Void)?) {
136+
completion: ((String?, Error?) -> Void)?) {
139137
Task {
140138
do {
141139
let verificationID = try await verifyPhoneNumber(
@@ -641,7 +639,6 @@ import Foundation
641639
private let auth: Auth
642640
private let callbackScheme: String
643641
private let usingClientIDScheme: Bool
644-
private var recaptchaVerifier: AuthRecaptchaVerifier?
645642

646643
init(auth: Auth) {
647644
self.auth = auth
@@ -662,7 +659,6 @@ import Foundation
662659
return
663660
}
664661
callbackScheme = ""
665-
recaptchaVerifier = AuthRecaptchaVerifier.shared(auth: auth)
666662
}
667663

668664
private let kAuthTypeVerifyApp = "verifyApp"

FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorInfo.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414

1515
import Foundation
1616

17+
// TODO(Swift 6 Breaking): Make checked Sendable.
18+
1719
#if os(iOS)
1820
extension MultiFactorInfo: NSSecureCoding {}
1921

2022
/// Safe public structure used to represent a second factor entity from a client perspective.
2123
///
2224
/// This class is available on iOS only.
23-
@objc(FIRMultiFactorInfo) open class MultiFactorInfo: NSObject {
25+
@objc(FIRMultiFactorInfo) open class MultiFactorInfo: NSObject, @unchecked Sendable {
2426
/// The multi-factor enrollment ID.
2527
@objc(UID) public let uid: String
2628

FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,46 @@ import Foundation
2727
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
2828
@objc(FIRMultiFactorSession) open class MultiFactorSession: NSObject {
2929
/// The ID token for an enroll flow. This has to be retrieved after recent authentication.
30-
var idToken: String?
30+
let idToken: String?
3131

3232
/// The pending credential after an enrolled second factor user signs in successfully with the
3333
/// first factor.
34-
var mfaPendingCredential: String?
34+
let mfaPendingCredential: String?
35+
36+
/// Current user object.
37+
let currentUser: User?
3538

3639
/// Multi factor info for the current user.
3740
var multiFactorInfo: MultiFactorInfo?
3841

39-
/// Current user object.
40-
var currentUser: User?
41-
4242
class func session(for user: User?) -> MultiFactorSession {
4343
let currentUser = user ?? Auth.auth().currentUser
4444
guard let currentUser else {
4545
fatalError("Internal Auth Error: missing user for multifactor auth")
4646
}
47-
return .init(idToken: currentUser.tokenService.accessToken, currentUser: currentUser)
47+
return .init(
48+
idToken: currentUser.tokenService.accessToken,
49+
mfaPendingCredential: nil,
50+
multiFactorInfo: nil,
51+
currentUser: currentUser
52+
)
4853
}
4954

50-
init(idToken: String?, currentUser: User) {
51-
self.idToken = idToken
52-
self.currentUser = currentUser
55+
convenience init(mfaCredential: String?) {
56+
self.init(
57+
idToken: nil,
58+
mfaPendingCredential: mfaCredential,
59+
multiFactorInfo: nil,
60+
currentUser: nil
61+
)
5362
}
5463

55-
init(mfaCredential: String?) {
56-
mfaPendingCredential = mfaCredential
64+
private init(idToken: String?, mfaPendingCredential: String?, multiFactorInfo: MultiFactorInfo?,
65+
currentUser: User?) {
66+
self.idToken = idToken
67+
self.mfaPendingCredential = mfaPendingCredential
68+
self.multiFactorInfo = multiFactorInfo
69+
self.currentUser = currentUser
5770
}
5871
}
5972

FirebaseAuth/Sources/Swift/MultiFactor/Phone/PhoneMultiFactorInfo.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414

1515
import Foundation
1616

17+
// TODO(Swift 6 Breaking): Make checked Sendable.
18+
1719
#if os(iOS)
1820

1921
/// Extends the MultiFactorInfo class for phone number second factors.
2022
///
2123
/// The identifier of this second factor is "phone".
2224
///
2325
/// This class is available on iOS only.
24-
@objc(FIRPhoneMultiFactorInfo) open class PhoneMultiFactorInfo: MultiFactorInfo {
26+
@objc(FIRPhoneMultiFactorInfo) open class PhoneMultiFactorInfo: MultiFactorInfo,
27+
@unchecked Sendable {
2528
/// The string identifier for using phone as a second factor.
2629
@objc(FIRPhoneMultiFactorID) public static let PhoneMultiFactorID = "phone"
2730

FirebaseAuth/Sources/Swift/MultiFactor/TOTP/TOTPMultiFactorInfo.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@
1414

1515
import Foundation
1616

17+
// TODO(Swift 6 Breaking): Make checked Sendable. Also, does this need
18+
// to be public?
19+
1720
#if os(iOS)
1821

1922
/// Extends the MultiFactorInfo class for time based one-time password second factors.
2023
///
2124
/// The identifier of this second factor is "totp".
2225
///
2326
/// This class is available on iOS only.
24-
class TOTPMultiFactorInfo: MultiFactorInfo {
27+
class TOTPMultiFactorInfo: MultiFactorInfo, @unchecked Sendable {
2528
/// Initialize the AuthProtoMFAEnrollment instance with proto.
2629
/// - Parameter proto: AuthProtoMFAEnrollment proto object.
2730
init(proto: AuthProtoMFAEnrollment) {

0 commit comments

Comments
 (0)