Эх сурвалжийг харах

[Auth] First pass marking closures as Sendable

This reverts commit 709a685a99a942f00db7a9a057e1ba8dd95b4ce3.
Nick Cooke 1 жил өмнө
parent
commit
767d908aa0

+ 21 - 16
FirebaseAuth/Sources/Swift/Auth/Auth.swift

@@ -219,7 +219,8 @@ extension Auth: AuthInterop {
   ///   - user: The user object to be set as the current user of the calling Auth instance.
   ///   - completion: Optionally; a block invoked after the user of the calling Auth instance has
   ///             been updated or an error was encountered.
-  @objc open func updateCurrentUser(_ user: User?, completion: ((Error?) -> Void)? = nil) {
+  @objc open func updateCurrentUser(_ user: User?,
+                                    completion: (@Sendable (Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       guard let user else {
         let error = AuthErrorUtils.nullUserError(message: nil)
@@ -286,7 +287,7 @@ extension Auth: AuthInterop {
     )
   #endif // !FIREBASE_CI
   @objc open func fetchSignInMethods(forEmail email: String,
-                                     completion: (([String]?, Error?) -> Void)? = nil) {
+                                     completion: (@Sendable ([String]?, Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       let request = CreateAuthURIRequest(identifier: email,
                                          continueURI: "http://www.google.com/",
@@ -350,7 +351,7 @@ extension Auth: AuthInterop {
   /// or is canceled. Invoked asynchronously on the main thread in the future.
   @objc open func signIn(withEmail email: String,
                          password: String,
-                         completion: ((AuthDataResult?, Error?) -> Void)? = nil) {
+                         completion: (@Sendable (AuthDataResult?, Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       let decoratedCallback = self.signInFlowAuthDataResultCallback(byDecorating: completion)
       Task {
@@ -449,7 +450,7 @@ extension Auth: AuthInterop {
   /// or is canceled. Invoked asynchronously on the main thread in the future.
   @objc open func signIn(withEmail email: String,
                          link: String,
-                         completion: ((AuthDataResult?, Error?) -> Void)? = nil) {
+                         completion: (@Sendable (AuthDataResult?, Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       let decoratedCallback = self.signInFlowAuthDataResultCallback(byDecorating: completion)
       let credential = EmailAuthCredential(withEmail: email, link: link)
@@ -528,7 +529,7 @@ extension Auth: AuthInterop {
     @objc(signInWithProvider:UIDelegate:completion:)
     open func signIn(with provider: FederatedAuthProvider,
                      uiDelegate: AuthUIDelegate?,
-                     completion: ((AuthDataResult?, Error?) -> Void)?) {
+                     completion: (@Sendable (AuthDataResult?, Error?) -> Void)?) {
       kAuthGlobalWorkQueue.async {
         Task {
           let decoratedCallback = self.signInFlowAuthDataResultCallback(byDecorating: completion)
@@ -629,7 +630,7 @@ extension Auth: AuthInterop {
   /// or is canceled. Invoked asynchronously on the main thread in the future.
   @objc(signInWithCredential:completion:)
   open func signIn(with credential: AuthCredential,
-                   completion: ((AuthDataResult?, Error?) -> Void)? = nil) {
+                   completion: (@Sendable (AuthDataResult?, Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       let decoratedCallback = self.signInFlowAuthDataResultCallback(byDecorating: completion)
       Task {
@@ -699,7 +700,8 @@ extension Auth: AuthInterop {
   /// not enabled. Enable them in the Auth section of the Firebase console.
   /// - Parameter completion: Optionally; a block which is invoked when the sign in finishes, or is
   /// canceled. Invoked asynchronously on the main thread in the future.
-  @objc open func signInAnonymously(completion: ((AuthDataResult?, Error?) -> Void)? = nil) {
+  @objc open func signInAnonymously(completion: (@Sendable (AuthDataResult?, Error?) -> Void)? =
+    nil) {
     kAuthGlobalWorkQueue.async {
       let decoratedCallback = self.signInFlowAuthDataResultCallback(byDecorating: completion)
       if let currentUser = self.currentUser, currentUser.isAnonymous {
@@ -765,7 +767,7 @@ extension Auth: AuthInterop {
   /// - Parameter completion: Optionally; a block which is invoked when the sign in finishes, or is
   ///    canceled. Invoked asynchronously on the main thread in the future.
   @objc open func signIn(withCustomToken token: String,
-                         completion: ((AuthDataResult?, Error?) -> Void)? = nil) {
+                         completion: (@Sendable (AuthDataResult?, Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       let decoratedCallback = self.signInFlowAuthDataResultCallback(byDecorating: completion)
       let request = VerifyCustomTokenRequest(token: token,
@@ -834,7 +836,7 @@ extension Auth: AuthInterop {
   /// or is canceled. Invoked asynchronously on the main thread in the future.
   @objc open func createUser(withEmail email: String,
                              password: String,
-                             completion: ((AuthDataResult?, Error?) -> Void)? = nil) {
+                             completion: (@Sendable (AuthDataResult?, Error?) -> Void)? = nil) {
     guard password.count > 0 else {
       if let completion {
         completion(nil, AuthErrorUtils.weakPasswordError(serverResponseReason: "Missing password"))
@@ -947,7 +949,7 @@ extension Auth: AuthInterop {
   /// - Parameter completion: Optionally; a block which is invoked when the request finishes.
   /// Invoked asynchronously on the main thread in the future.
   @objc open func confirmPasswordReset(withCode code: String, newPassword: String,
-                                       completion: @escaping (Error?) -> Void) {
+                                       completion: @Sendable @escaping (Error?) -> Void) {
     kAuthGlobalWorkQueue.async {
       let request = ResetPasswordRequest(oobCode: code,
                                          newPassword: newPassword,
@@ -987,7 +989,8 @@ extension Auth: AuthInterop {
   /// Invoked
   /// asynchronously on the main thread in the future.
   @objc open func checkActionCode(_ code: String,
-                                  completion: @escaping (ActionCodeInfo?, Error?) -> Void) {
+                                  completion: @Sendable @escaping (ActionCodeInfo?, Error?)
+                                    -> Void) {
     kAuthGlobalWorkQueue.async {
       let request = ResetPasswordRequest(oobCode: code,
                                          newPassword: nil,
@@ -1032,7 +1035,8 @@ extension Auth: AuthInterop {
   /// - Parameter completion: Optionally; a block which is invoked when the request finishes.
   /// Invoked asynchronously on the main thread in the future.
   @objc open func verifyPasswordResetCode(_ code: String,
-                                          completion: @escaping (String?, Error?) -> Void) {
+                                          completion: @Sendable @escaping (String?, Error?)
+                                            -> Void) {
     checkActionCode(code) { info, error in
       if let error {
         completion(nil, error)
@@ -1065,7 +1069,8 @@ extension Auth: AuthInterop {
   /// - Parameter code: The out of band code to be applied.
   /// - Parameter completion: Optionally; a block which is invoked when the request finishes.
   /// Invoked asynchronously on the main thread in the future.
-  @objc open func applyActionCode(_ code: String, completion: @escaping (Error?) -> Void) {
+  @objc open func applyActionCode(_ code: String,
+                                  completion: @Sendable @escaping (Error?) -> Void) {
     kAuthGlobalWorkQueue.async {
       let request = SetAccountInfoRequest(requestConfiguration: self.requestConfiguration)
       request.oobCode = code
@@ -1110,7 +1115,7 @@ extension Auth: AuthInterop {
   /// Invoked
   /// asynchronously on the main thread in the future.
   @objc open func sendPasswordReset(withEmail email: String,
-                                    completion: ((Error?) -> Void)? = nil) {
+                                    completion: (@Sendable (Error?) -> Void)? = nil) {
     sendPasswordReset(withEmail: email, actionCodeSettings: nil, completion: completion)
   }
 
@@ -1143,7 +1148,7 @@ extension Auth: AuthInterop {
   /// Invoked asynchronously on the main thread in the future.
   @objc open func sendPasswordReset(withEmail email: String,
                                     actionCodeSettings: ActionCodeSettings?,
-                                    completion: ((Error?) -> Void)? = nil) {
+                                    completion: (@Sendable (Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       let request = GetOOBConfirmationCodeRequest.passwordResetRequest(
         email: email,
@@ -1212,7 +1217,7 @@ extension Auth: AuthInterop {
   /// Invoked asynchronously on the main thread in the future.
   @objc open func sendSignInLink(toEmail email: String,
                                  actionCodeSettings: ActionCodeSettings,
-                                 completion: ((Error?) -> Void)? = nil) {
+                                 completion: (@Sendable (Error?) -> Void)? = nil) {
     if !actionCodeSettings.handleCodeInApp {
       fatalError("The handleCodeInApp flag in ActionCodeSettings must be true for Email-link " +
         "Authentication.")

+ 1 - 1
FirebaseAuth/Sources/Swift/AuthProvider/OAuthProvider.swift

@@ -268,7 +268,7 @@ import Foundation
     /// - Parameter completion: Optionally; a block which is invoked asynchronously on the main
     /// thread when the mobile web flow is completed.
     open func getCredentialWith(_ uiDelegate: AuthUIDelegate?,
-                                completion: ((AuthCredential?, Error?) -> Void)? = nil) {
+                                completion: (@Sendable (AuthCredential?, Error?) -> Void)? = nil) {
       guard let urlTypes = auth.mainBundleUrlTypes,
             AuthWebUtils.isCallbackSchemeRegistered(forCustomURLScheme: callbackScheme,
                                                     urlTypes: urlTypes) else {

+ 3 - 3
FirebaseAuth/Sources/Swift/AuthProvider/PhoneAuthProvider.swift

@@ -52,7 +52,7 @@ import Foundation
     @objc(verifyPhoneNumber:UIDelegate:completion:)
     open func verifyPhoneNumber(_ phoneNumber: String,
                                 uiDelegate: AuthUIDelegate? = nil,
-                                completion: ((_: String?, _: Error?) -> Void)?) {
+                                completion: (@Sendable (_: String?, _: Error?) -> Void)?) {
       verifyPhoneNumber(phoneNumber,
                         uiDelegate: uiDelegate,
                         multiFactorSession: nil,
@@ -71,7 +71,7 @@ import Foundation
     open func verifyPhoneNumber(_ phoneNumber: String,
                                 uiDelegate: AuthUIDelegate? = nil,
                                 multiFactorSession: MultiFactorSession? = nil,
-                                completion: ((_: String?, _: Error?) -> Void)?) {
+                                completion: (@Sendable (_: String?, _: Error?) -> Void)?) {
       guard AuthWebUtils.isCallbackSchemeRegistered(forCustomURLScheme: callbackScheme,
                                                     urlTypes: auth.mainBundleUrlTypes) else {
         fatalError(
@@ -132,7 +132,7 @@ import Foundation
     open func verifyPhoneNumber(with multiFactorInfo: PhoneMultiFactorInfo,
                                 uiDelegate: AuthUIDelegate? = nil,
                                 multiFactorSession: MultiFactorSession?,
-                                completion: ((_: String?, _: Error?) -> Void)?) {
+                                completion: (@Sendable (_: String?, _: Error?) -> Void)?) {
       multiFactorSession?.multiFactorInfo = multiFactorInfo
       verifyPhoneNumber(multiFactorInfo.phoneNumber,
                         uiDelegate: uiDelegate,

+ 18 - 17
FirebaseAuth/Sources/Swift/User/User.swift

@@ -101,7 +101,7 @@ extension User: NSSecureCoding {}
     )
   #endif // !FIREBASE_CI
   @objc(updateEmail:completion:)
-  open func updateEmail(to email: String, completion: ((Error?) -> Void)? = nil) {
+  open func updateEmail(to email: String, completion: (@Sendable (Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       self.updateEmail(email: email, password: nil) { error in
         User.callInMainThreadWithError(callback: completion, error: error)
@@ -173,7 +173,7 @@ extension User: NSSecureCoding {}
   /// - Parameter completion: Optionally; the block invoked when the user profile change has
   /// finished.
   @objc(updatePassword:completion:)
-  open func updatePassword(to password: String, completion: ((Error?) -> Void)? = nil) {
+  open func updatePassword(to password: String, completion: (@Sendable (Error?) -> Void)? = nil) {
     guard password.count > 0 else {
       if let completion {
         completion(AuthErrorUtils.weakPasswordError(serverResponseReason: "Missing Password"))
@@ -234,7 +234,7 @@ extension User: NSSecureCoding {}
     /// finished.
     @objc(updatePhoneNumberCredential:completion:)
     open func updatePhoneNumber(_ credential: PhoneAuthCredential,
-                                completion: ((Error?) -> Void)? = nil) {
+                                completion: (@Sendable (Error?) -> Void)? = nil) {
       kAuthGlobalWorkQueue.async {
         self.internalUpdateOrLinkPhoneNumber(credential: credential,
                                              isLinkOperation: false) { error in
@@ -303,7 +303,7 @@ extension User: NSSecureCoding {}
   /// `updateEmail(to:)`.
   /// - Parameter completion: Optionally; the block invoked when the reload has finished. Invoked
   ///   asynchronously on the main thread in the future.
-  @objc open func reload(completion: ((Error?) -> Void)? = nil) {
+  @objc open func reload(completion: (@Sendable (Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       self.getAccountInfoRefreshingCache { user, error in
         User.callInMainThreadWithError(callback: completion, error: error)
@@ -361,7 +361,7 @@ extension User: NSSecureCoding {}
   /// finished. Invoked asynchronously on the main thread in the future.
   @objc(reauthenticateWithCredential:completion:)
   open func reauthenticate(with credential: AuthCredential,
-                           completion: ((AuthDataResult?, Error?) -> Void)? = nil) {
+                           completion: (@Sendable (AuthDataResult?, Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       Task {
         do {
@@ -463,7 +463,7 @@ extension User: NSSecureCoding {}
     @objc(reauthenticateWithProvider:UIDelegate:completion:)
     open func reauthenticate(with provider: FederatedAuthProvider,
                              uiDelegate: AuthUIDelegate?,
-                             completion: ((AuthDataResult?, Error?) -> Void)? = nil) {
+                             completion: (@Sendable (AuthDataResult?, Error?) -> Void)? = nil) {
       kAuthGlobalWorkQueue.async {
         Task {
           do {
@@ -507,7 +507,7 @@ extension User: NSSecureCoding {}
   /// - Parameter completion: Optionally; the block invoked when the token is available. Invoked
   ///    asynchronously on the main thread in the future.
   @objc(getIDTokenWithCompletion:)
-  open func getIDToken(completion: ((String?, Error?) -> Void)?) {
+  open func getIDToken(completion: (@Sendable (String?, Error?) -> Void)?) {
     // |getIDTokenForcingRefresh:completion:| is also a public API so there is no need to dispatch to
     // global work queue here.
     getIDTokenForcingRefresh(false, completion: completion)
@@ -523,7 +523,7 @@ extension User: NSSecureCoding {}
   ///    asynchronously on the main thread in the future.
   @objc(getIDTokenForcingRefresh:completion:)
   open func getIDTokenForcingRefresh(_ forceRefresh: Bool,
-                                     completion: ((String?, Error?) -> Void)?) {
+                                     completion: (@Sendable (String?, Error?) -> Void)?) {
     getIDTokenResult(forcingRefresh: forceRefresh) { tokenResult, error in
       if let completion {
         DispatchQueue.main.async {
@@ -563,7 +563,7 @@ extension User: NSSecureCoding {}
   /// - Parameter completion: Optionally; the block invoked when the token is available. Invoked
   ///    asynchronously on the main thread in the future.
   @objc(getIDTokenResultWithCompletion:)
-  open func getIDTokenResult(completion: ((AuthTokenResult?, Error?) -> Void)?) {
+  open func getIDTokenResult(completion: (@Sendable (AuthTokenResult?, Error?) -> Void)?) {
     getIDTokenResult(forcingRefresh: false) { tokenResult, error in
       if let completion {
         DispatchQueue.main.async {
@@ -584,7 +584,7 @@ extension User: NSSecureCoding {}
   /// asynchronously on the main thread in the future.
   @objc(getIDTokenResultForcingRefresh:completion:)
   open func getIDTokenResult(forcingRefresh: Bool,
-                             completion: ((AuthTokenResult?, Error?) -> Void)?) {
+                             completion: (@Sendable (AuthTokenResult?, Error?) -> Void)?) {
     kAuthGlobalWorkQueue.async {
       self.internalGetToken(forceRefresh: forcingRefresh, backend: self.backend) { token, error in
         var tokenResult: AuthTokenResult?
@@ -660,7 +660,7 @@ extension User: NSSecureCoding {}
   /// fails.
   @objc(linkWithCredential:completion:)
   open func link(with credential: AuthCredential,
-                 completion: ((AuthDataResult?, Error?) -> Void)? = nil) {
+                 completion: (@Sendable (AuthDataResult?, Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       if self.providerDataRaw[credential.provider] != nil {
         User.callInMainThreadWithAuthDataResultAndError(
@@ -747,7 +747,7 @@ extension User: NSSecureCoding {}
     @objc(linkWithProvider:UIDelegate:completion:)
     open func link(with provider: FederatedAuthProvider,
                    uiDelegate: AuthUIDelegate?,
-                   completion: ((AuthDataResult?, Error?) -> Void)? = nil) {
+                   completion: (@Sendable (AuthDataResult?, Error?) -> Void)? = nil) {
       kAuthGlobalWorkQueue.async {
         Task {
           do {
@@ -847,7 +847,7 @@ extension User: NSSecureCoding {}
   /// - Parameter completion: Optionally; the block invoked when the request to send an email
   /// verification is complete, or fails. Invoked asynchronously on the main thread in the future.
   @objc(sendEmailVerificationWithCompletion:)
-  open func __sendEmailVerification(withCompletion completion: ((Error?) -> Void)?) {
+  open func __sendEmailVerification(withCompletion completion: (@Sendable (Error?) -> Void)?) {
     sendEmailVerification(completion: completion)
   }
 
@@ -867,7 +867,7 @@ extension User: NSSecureCoding {}
   /// verification is complete, or fails. Invoked asynchronously on the main thread in the future.
   @objc(sendEmailVerificationWithActionCodeSettings:completion:)
   open func sendEmailVerification(with actionCodeSettings: ActionCodeSettings? = nil,
-                                  completion: ((Error?) -> Void)? = nil) {
+                                  completion: (@Sendable (Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       self.internalGetToken(backend: self.backend) { accessToken, error in
         if let error {
@@ -932,7 +932,7 @@ extension User: NSSecureCoding {}
   /// `reauthenticate(with:)`.
   /// - Parameter completion: Optionally; the block invoked when the request to delete the account
   /// is complete, or fails. Invoked asynchronously on the main thread in the future.
-  @objc open func delete(completion: ((Error?) -> Void)? = nil) {
+  @objc open func delete(completion: (@Sendable (Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       self.internalGetToken(backend: self.backend) { accessToken, error in
         if let error {
@@ -985,7 +985,8 @@ extension User: NSSecureCoding {}
   /// - Parameter completion: Optionally; the block invoked when the request to send the
   /// verification email is complete, or fails.
   @objc(sendEmailVerificationBeforeUpdatingEmail:completion:)
-  open func __sendEmailVerificationBeforeUpdating(email: String, completion: ((Error?) -> Void)?) {
+  open func __sendEmailVerificationBeforeUpdating(email: String,
+                                                  completion: (@Sendable (Error?) -> Void)?) {
     sendEmailVerification(beforeUpdatingEmail: email, completion: completion)
   }
 
@@ -997,7 +998,7 @@ extension User: NSSecureCoding {}
   /// verification email is complete, or fails.
   @objc open func sendEmailVerification(beforeUpdatingEmail email: String,
                                         actionCodeSettings: ActionCodeSettings? = nil,
-                                        completion: ((Error?) -> Void)? = nil) {
+                                        completion: (@Sendable (Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       self.internalGetToken(backend: self.backend) { accessToken, error in
         if let error {

+ 1 - 1
FirebaseAuth/Sources/Swift/User/UserProfileChangeRequest.swift

@@ -59,7 +59,7 @@ import Foundation
   /// This method should only be called once.Once called, property values should not be changed.
   /// - Parameter completion: Optionally; the block invoked when the user profile change has been
   /// applied.
-  @objc open func commitChanges(completion: ((Error?) -> Void)? = nil) {
+  @objc open func commitChanges(completion: (@Sendable (Error?) -> Void)? = nil) {
     kAuthGlobalWorkQueue.async {
       if self.consumed {
         fatalError("Internal Auth Error: commitChanges should only be called once.")