MultiFactorResolver+Combine.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #if canImport(Combine) && swift(>=5.0) && canImport(FirebaseAuth) && !os(tvOS) && !os(macOS)
  15. import Foundation
  16. import Combine
  17. import FirebaseAuth
  18. @available(swift 5.0)
  19. @available(iOS 13, watchOS 6, *)
  20. @available(tvOS, unavailable)
  21. @available(macOS, unavailable)
  22. extension MultiFactorResolver {
  23. /// A helper function to help users complete sign in with a second factor using an
  24. /// `MultiFactorAssertion` confirming the user successfully completed the second factor
  25. ///
  26. /// - Parameter assertion: The base class for asserting ownership of a second factor.
  27. /// - Returns: A publisher that emits an `AuthDataResult` when the sign-in flow completed
  28. /// successfully, or an error otherwise.
  29. public func resolveSignIn(with assertion: MultiFactorAssertion)
  30. -> Future<AuthDataResult, Error> {
  31. Future<AuthDataResult, Error> { promise in
  32. self.resolveSignIn(with: assertion) { authDataResult, error in
  33. if let error = error {
  34. promise(.failure(error))
  35. } else if let authDataResult = authDataResult {
  36. promise(.success(authDataResult))
  37. }
  38. }
  39. }
  40. }
  41. }
  42. #endif