Auth+Combine.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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)
  15. import Combine
  16. import FirebaseAuth
  17. @available(swift 5.0)
  18. @available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *)
  19. extension Auth {
  20. // MARK: - Authentication State Management
  21. /// Registers a publisher that publishes authentication state changes.
  22. ///
  23. /// The publisher emits values when:
  24. ///
  25. /// - It is registered,
  26. /// - a user with a different UID from the current user has signed in, or
  27. /// - the current user has signed out.
  28. ///
  29. /// The publisher will emit events on the **main** thread.
  30. ///
  31. /// - Returns: A publisher emitting a `User` instance (if the user has signed in) or `nil` (if the user has signed out).
  32. /// The publisher will emit on the *main* thread.
  33. public func authStateDidChangePublisher() -> AnyPublisher<User?, Never> {
  34. let subject = PassthroughSubject<User?, Never>()
  35. let handle = addStateDidChangeListener { auth, user in
  36. subject.send(user)
  37. }
  38. return subject
  39. .handleEvents(receiveCancel: {
  40. self.removeStateDidChangeListener(handle)
  41. })
  42. .eraseToAnyPublisher()
  43. }
  44. /// Registers a publisher that publishes ID token state changes.
  45. ///
  46. /// The publisher emits values when:
  47. ///
  48. /// - It is registered,
  49. /// - a user with a different UID from the current user has signed in,
  50. /// - the ID token of the current user has been refreshed, or
  51. /// - the current user has signed out.
  52. ///
  53. /// The publisher will emit events on the **main** thread.
  54. ///
  55. /// - Returns: A publisher emitting a `User` instance (if a different user is signed in or
  56. /// the ID token of the current user has changed) or `nil` (if the user has signed out).
  57. /// The publisher will emit on the *main* thread.
  58. public func idTokenDidChangePublisher() -> AnyPublisher<User?, Never> {
  59. let subject = PassthroughSubject<User?, Never>()
  60. let handle = addIDTokenDidChangeListener { auth, user in
  61. subject.send(user)
  62. }
  63. return subject
  64. .handleEvents(receiveCancel: {
  65. self.removeIDTokenDidChangeListener(handle)
  66. })
  67. .eraseToAnyPublisher()
  68. }
  69. /// Sets the `currentUser` on the calling Auth instance to the provided `user` object.
  70. ///
  71. /// The publisher will emit events on the **main** thread.
  72. ///
  73. /// - Parameter user: The user object to be set as the current user of the calling Auth instance.
  74. /// - Returns: A publisher that emits when the user of the calling Auth instance has been updated or
  75. /// an error was encountered. The publisher will emit on the **main** thread.
  76. @discardableResult
  77. public func updateCurrentUser(_ user: User) -> Future<Void, Error> {
  78. Future<Void, Error> { promise in
  79. self.updateCurrentUser(user) { error in
  80. if let error = error {
  81. promise(.failure(error))
  82. } else {
  83. promise(.success(()))
  84. }
  85. }
  86. }
  87. }
  88. // MARK: - Anonymous Authentication
  89. /// Asynchronously creates an anonymous user and assigns it as the calling Auth instance's current user.
  90. ///
  91. /// If there is already an anonymous user signed in, that user will be returned instead.
  92. /// If there is any other existing user signed in, that user will be signed out.
  93. ///
  94. /// The publisher will emit events on the **main** thread.
  95. ///
  96. /// - Returns: A publisher that emits the result of the sign in flow. The publisher will emit on the *main* thread.
  97. /// - Remark:
  98. /// Possible error codes:
  99. /// - `AuthErrorCodeOperationNotAllowed` - Indicates that anonymous accounts are
  100. /// not enabled. Enable them in the Auth section of the Firebase console.
  101. ///
  102. /// See `AuthErrors` for a list of error codes that are common to all API methods
  103. @discardableResult
  104. public func signInAnonymously() -> Future<AuthDataResult, Error> {
  105. Future<AuthDataResult, Error> { promise in
  106. self.signInAnonymously { authDataResult, error in
  107. if let error = error {
  108. promise(.failure(error))
  109. } else if let authDataResult = authDataResult {
  110. promise(.success(authDataResult))
  111. }
  112. }
  113. }
  114. }
  115. // MARK: - Email/Password Authentication
  116. /// Creates and, on success, signs in a user with the given email address and password.
  117. ///
  118. /// The publisher will emit events on the **main** thread.
  119. ///
  120. /// - Parameters:
  121. /// - email: The user's email address.
  122. /// - password: The user's desired password.
  123. /// - Returns: A publisher that emits the result of the sign in flow. The publisher will emit on the *main* thread.
  124. /// - Remark:
  125. /// Possible error codes:
  126. /// - `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  127. /// - `AuthErrorCodeEmailAlreadyInUse` - Indicates the email used to attempt sign up
  128. /// already exists. Call fetchProvidersForEmail to check which sign-in mechanisms the user
  129. /// used, and prompt the user to sign in with one of those.
  130. /// - `AuthErrorCodeOperationNotAllowed` - Indicates that email and password accounts
  131. /// are not enabled. Enable them in the Auth section of the Firebase console.
  132. /// - `AuthErrorCodeWeakPassword` - Indicates an attempt to set a password that is
  133. /// considered too weak. The NSLocalizedFailureReasonErrorKey field in the NSError.userInfo
  134. /// dictionary object will contain more detailed explanation that can be shown to the user.
  135. ///
  136. /// See `AuthErrors` for a list of error codes that are common to all API methods
  137. @discardableResult
  138. public func createUser(withEmail email: String,
  139. password: String) -> Future<AuthDataResult, Error> {
  140. Future<AuthDataResult, Error> { promise in
  141. self.createUser(withEmail: email, password: password) { authDataResult, error in
  142. if let error = error {
  143. promise(.failure(error))
  144. } else if let authDataResult = authDataResult {
  145. promise(.success(authDataResult))
  146. }
  147. }
  148. }
  149. }
  150. /// Signs in a user with the given email address and password.
  151. ///
  152. /// The publisher will emit events on the **main** thread.
  153. ///
  154. /// - Parameters:
  155. /// - email: The user's email address.
  156. /// - password: The user's password.
  157. /// - Returns: A publisher that emits the result of the sign in flow. The publisher will emit on the *main* thread.
  158. /// - Remark:
  159. /// Possible error codes:
  160. /// - `AuthErrorCodeOperationNotAllowed` - Indicates that email and password
  161. /// accounts are not enabled. Enable them in the Auth section of the
  162. /// Firebase console.
  163. /// - `AuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
  164. /// - `AuthErrorCodeWrongPassword` - Indicates the user attempted
  165. /// sign in with an incorrect password.
  166. /// - `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  167. ///
  168. /// See `AuthErrors` for a list of error codes that are common to all API methods
  169. @discardableResult
  170. public func signIn(withEmail email: String,
  171. password: String) -> Future<AuthDataResult, Error> {
  172. Future<AuthDataResult, Error> { promise in
  173. self.signIn(withEmail: email, password: password) { authDataResult, error in
  174. if let error = error {
  175. promise(.failure(error))
  176. } else if let authDataResult = authDataResult {
  177. promise(.success(authDataResult))
  178. }
  179. }
  180. }
  181. }
  182. // MARK: - Email/Link Authentication
  183. /// Signs in using an email address and email sign-in link.
  184. ///
  185. /// The publisher will emit events on the **main** thread.
  186. ///
  187. /// - Parameters:
  188. /// - email: The user's email address.
  189. /// - link: The email sign-in link.
  190. /// - Returns: A publisher that emits the result of the sign in flow. The publisher will emit on the *main* thread.
  191. /// - Remark:
  192. /// Possible error codes:
  193. /// - `AuthErrorCodeOperationNotAllowed` - Indicates that email and password
  194. /// accounts are not enabled. Enable them in the Auth section of the
  195. /// Firebase console.
  196. /// - `AuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
  197. /// - `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  198. ///
  199. /// See `AuthErrors` for a list of error codes that are common to all API methods
  200. @available(watchOS, unavailable)
  201. @discardableResult
  202. public func signIn(withEmail email: String,
  203. link: String) -> Future<AuthDataResult, Error> {
  204. Future<AuthDataResult, Error> { promise in
  205. self.signIn(withEmail: email, link: link) { authDataResult, error in
  206. if let error = error {
  207. promise(.failure(error))
  208. } else if let authDataResult = authDataResult {
  209. promise(.success(authDataResult))
  210. }
  211. }
  212. }
  213. }
  214. /// Sends a sign in with email link to provided email address.
  215. ///
  216. /// The publisher will emit events on the **main** thread.
  217. ///
  218. /// - Parameters:
  219. /// - email: The email address of the user.
  220. /// - actionCodeSettings: An `ActionCodeSettings` object containing settings related to
  221. /// handling action codes.
  222. /// - Returns: A publisher that emits whether the call was successful or not. The publisher will emit on the *main* thread.
  223. @available(watchOS, unavailable)
  224. @discardableResult
  225. public func sendSignInLink(toEmail email: String,
  226. actionCodeSettings: ActionCodeSettings) -> Future<Void, Error> {
  227. Future<Void, Error> { promise in
  228. self.sendSignInLink(toEmail: email, actionCodeSettings: actionCodeSettings) { error in
  229. if let error = error {
  230. promise(.failure(error))
  231. } else {
  232. promise(.success(()))
  233. }
  234. }
  235. }
  236. }
  237. // MARK: - Email-based Authentication Helpers
  238. /// Fetches the list of all sign-in methods previously used for the provided email address.
  239. ///
  240. /// The publisher will emit events on the **main** thread.
  241. ///
  242. /// - Parameter email: The email address for which to obtain a list of sign-in methods.
  243. /// - Returns: A publisher that emits a list of sign-in methods for the specified email
  244. /// address, or an error if one occurred. The publisher will emit on the *main* thread.
  245. /// - Remark: Possible error codes:
  246. /// - `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  247. ///
  248. /// See `AuthErrors` for a list of error codes that are common to all API methods
  249. public func fetchSignInMethods(forEmail email: String) -> Future<[String], Error> {
  250. Future<[String], Error> { promise in
  251. self.fetchSignInMethods(forEmail: email) { signInMethods, error in
  252. if let error = error {
  253. promise(.failure(error))
  254. } else if let signInMethods = signInMethods {
  255. promise(.success(signInMethods))
  256. }
  257. }
  258. }
  259. }
  260. // MARK: - Password Reset
  261. /// Resets the password given a code sent to the user outside of the app and a new password for the user.
  262. ///
  263. /// The publisher will emit events on the **main** thread.
  264. ///
  265. /// - Parameters:
  266. /// - code: Out-of-band (OOB) code given to the user outside of the app.
  267. /// - newPassword: The new password.
  268. /// - Returns: A publisher that emits whether the call was successful or not. The publisher will emit on the *main* thread.
  269. /// - Remark: Possible error codes:
  270. /// - `AuthErrorCodeWeakPassword` - Indicates an attempt to set a password that is considered too weak.
  271. /// - `AuthErrorCodeOperationNotAllowed` - Indicates the admin disabled sign in with the specified identity provider.
  272. /// - `AuthErrorCodeExpiredActionCode` - Indicates the OOB code is expired.
  273. /// - `AuthErrorCodeInvalidActionCode` - Indicates the OOB code is invalid.
  274. ///
  275. /// See `AuthErrors` for a list of error codes that are common to all API methods
  276. @discardableResult
  277. public func confirmPasswordReset(withCode code: String,
  278. newPassword: String) -> Future<Void, Error> {
  279. Future<Void, Error> { promise in
  280. self.confirmPasswordReset(withCode: code, newPassword: newPassword) { error in
  281. if let error = error {
  282. promise(.failure(error))
  283. } else {
  284. promise(.success(()))
  285. }
  286. }
  287. }
  288. }
  289. /// Checks the validity of a verify password reset code.
  290. ///
  291. /// The publisher will emit events on the **main** thread.
  292. ///
  293. /// - Parameter code: The password reset code to be verified.
  294. /// - Returns: A publisher that emits an error if the code could not be verified. If the code could be
  295. /// verified, the publisher will emit the email address of the account the code was issued for.
  296. /// The publisher will emit on the *main* thread.
  297. @discardableResult
  298. public func verifyPasswordResetCode(_ code: String) -> Future<String, Error> {
  299. Future<String, Error> { promise in
  300. self.verifyPasswordResetCode(code) { email, error in
  301. if let error = error {
  302. promise(.failure(error))
  303. } else if let email = email {
  304. promise(.success(email))
  305. }
  306. }
  307. }
  308. }
  309. /// Checks the validity of an out of band code.
  310. ///
  311. /// The publisher will emit events on the **main** thread.
  312. ///
  313. /// - Parameter code: The out of band code to check validity.
  314. /// - Returns: A publisher that emits the email address of the account the code was issued for or an error if
  315. /// the code could not be verified. The publisher will emit on the *main* thread.
  316. @discardableResult
  317. public func checkActionCode(code: String) -> Future<ActionCodeInfo, Error> {
  318. Future<ActionCodeInfo, Error> { promise in
  319. self.checkActionCode(code) { actionCodeInfo, error in
  320. if let error = error {
  321. promise(.failure(error))
  322. } else if let actionCodeInfo = actionCodeInfo {
  323. promise(.success(actionCodeInfo))
  324. }
  325. }
  326. }
  327. }
  328. /// Applies out of band code.
  329. ///
  330. /// The publisher will emit events on the **main** thread.
  331. ///
  332. /// - Parameter code: The out-of-band (OOB) code to be applied.
  333. /// - Returns: A publisher that emits an error if the code could not be applied. The publisher will emit on the *main* thread.
  334. /// - Remark: This method will not work for out-of-band codes which require an additional parameter,
  335. /// such as password reset codes.
  336. @discardableResult
  337. public func applyActionCode(code: String) -> Future<Void, Error> {
  338. Future<Void, Error> { promise in
  339. self.applyActionCode(code) { error in
  340. if let error = error {
  341. promise(.failure(error))
  342. } else {
  343. promise(.success(()))
  344. }
  345. }
  346. }
  347. }
  348. /// Initiates a password reset for the given email address.
  349. ///
  350. /// The publisher will emit events on the **main** thread.
  351. ///
  352. /// - Parameter email: The email address of the user.
  353. /// - Returns: A publisher that emits whether the call was successful or not. The publisher will emit on the *main* thread.
  354. /// - Remark: Possible error codes:
  355. /// - `AuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was sent in the request.
  356. /// - `AuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in the console for this action.
  357. /// - `AuthErrorCodeInvalidMessagePayload` - Indicates an invalid email template for sending update email.
  358. ///
  359. /// See `AuthErrors` for a list of error codes that are common to all API methods
  360. @discardableResult
  361. public func sendPasswordReset(withEmail email: String) -> Future<Void, Error> {
  362. Future<Void, Error> { promise in
  363. self.sendPasswordReset(withEmail: email) { error in
  364. if let error = error {
  365. promise(.failure(error))
  366. } else {
  367. promise(.success(()))
  368. }
  369. }
  370. }
  371. }
  372. /// Initiates a password reset for the given email address and `ActionCodeSettings`.
  373. ///
  374. /// The publisher will emit events on the **main** thread.
  375. ///
  376. /// - Parameter email: The email address of the user.
  377. /// - Parameter actionCodeSettings: An `ActionCodeSettings` object containing settings related to
  378. /// handling action codes.
  379. /// - Returns: A publisher that emits whether the call was successful or not. The publisher will emit on the *main* thread.
  380. /// - Remark: Possible error codes:
  381. /// - `AuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was sent in the request.
  382. /// - `AuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in the console for this action.
  383. /// - `AuthErrorCodeInvalidMessagePayload` - Indicates an invalid email template for sending update email.
  384. /// - `AuthErrorCodeMissingIosBundleID` - Indicates that the iOS bundle ID is missing
  385. /// when `handleCodeInApp` is set to YES.
  386. /// - `AuthErrorCodeMissingAndroidPackageName` - Indicates that the android package name is missing
  387. /// when the `androidInstallApp` flag is set to true.
  388. /// - `AuthErrorCodeUnauthorizedDomain` - Indicates that the domain specified in the continue URL is not whitelisted
  389. /// in the Firebase console.
  390. /// - `AuthErrorCodeInvalidContinueURI` - Indicates that the domain specified in the continue URI is not valid.
  391. ///
  392. /// See `AuthErrors` for a list of error codes that are common to all API methods
  393. @discardableResult
  394. public func sendPasswordReset(withEmail email: String,
  395. actionCodeSettings: ActionCodeSettings) -> Future<Void, Error> {
  396. Future<Void, Error> { promise in
  397. self.sendPasswordReset(withEmail: email, actionCodeSettings: actionCodeSettings) { error in
  398. if let error = error {
  399. promise(.failure(error))
  400. } else {
  401. promise(.success(()))
  402. }
  403. }
  404. }
  405. }
  406. // MARK: - Other Authentication providers
  407. #if os(iOS) || targetEnvironment(macCatalyst)
  408. /// Signs in using the provided auth provider instance.
  409. ///
  410. /// The publisher will emit events on the **main** thread.
  411. ///
  412. /// - Parameters:
  413. /// - provider: An instance of an auth provider used to initiate the sign-in flow.
  414. /// - uiDelegate: Optionally, an instance of a class conforming to the `AuthUIDelegate`
  415. /// protocol. This is used for presenting the web context. If `nil`, a default `AuthUIDelegate`
  416. /// will be used.
  417. /// - Returns: A publisher that emits an `AuthDataResult` when the sign-in flow completed
  418. /// successfully, or an error otherwise. The publisher will emit on the *main* thread.
  419. /// - Remark: Possible error codes:
  420. /// - `AuthErrorCodeOperationNotAllowed` - Indicates that email and password accounts are not enabled.
  421. /// Enable them in the Auth section of the Firebase console.
  422. /// - `AuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
  423. /// - `AuthErrorCodeWebNetworkRequestFailed` - Indicates that a network request within a
  424. /// `SFSafariViewController` or `WKWebView` failed.
  425. /// - `AuthErrorCodeWebInternalError` - Indicates that an internal error occurred within a
  426. /// `SFSafariViewController` or `WKWebView`.`
  427. /// - `AuthErrorCodeWebSignInUserInteractionFailure` - Indicates a general failure during a web sign-in flow.`
  428. /// - `AuthErrorCodeWebContextAlreadyPresented` - Indicates that an attempt was made to present a new web
  429. /// context while one was already being presented.`
  430. /// - `AuthErrorCodeWebContextCancelled` - Indicates that the URL presentation was cancelled prematurely
  431. /// by the user.`
  432. /// - `AuthErrorCodeAccountExistsWithDifferentCredential` - Indicates the email asserted by the credential
  433. /// (e.g. the email in a Facebook access token) is already in use by an existing account that cannot be
  434. /// authenticated with this sign-in method. Call `fetchProvidersForEmail` for this user’s email and then
  435. /// prompt them to sign in with any of the sign-in providers returned. This error will only be thrown if
  436. /// the "One account per email address" setting is enabled in the Firebase console, under Auth settings.
  437. ///
  438. /// See `AuthErrors` for a list of error codes that are common to all API methods
  439. @discardableResult
  440. public func signIn(with provider: FederatedAuthProvider,
  441. uiDelegate: AuthUIDelegate?) -> Future<AuthDataResult, Error> {
  442. Future<AuthDataResult, Error> { promise in
  443. self.signIn(with: provider, uiDelegate: uiDelegate) { authDataResult, error in
  444. if let error = error {
  445. promise(.failure(error))
  446. } else if let authDataResult = authDataResult {
  447. promise(.success(authDataResult))
  448. }
  449. }
  450. }
  451. }
  452. #endif // os(iOS) || targetEnvironment(macCatalyst)
  453. /// Asynchronously signs in to Firebase with the given Auth token.
  454. ///
  455. /// The publisher will emit events on the **main** thread.
  456. ///
  457. /// - Parameter token: A self-signed custom auth token.
  458. /// - Returns: A publisher that emits an `AuthDataResult` when the sign-in flow completed
  459. /// successfully, or an error otherwise. The publisher will emit on the *main* thread.
  460. /// - Remark: Possible error codes:
  461. /// - `AuthErrorCodeInvalidCustomToken` - Indicates a validation error with the custom token.
  462. /// - `AuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
  463. /// - `AuthErrorCodeCustomTokenMismatch` - Indicates the service account and the API key
  464. /// belong to different projects.
  465. ///
  466. /// See `AuthErrors` for a list of error codes that are common to all API methods
  467. @discardableResult
  468. public func signIn(withCustomToken token: String) -> Future<AuthDataResult, Error> {
  469. Future<AuthDataResult, Error> { promise in
  470. self.signIn(withCustomToken: token) { authDataResult, error in
  471. if let error = error {
  472. promise(.failure(error))
  473. } else if let authDataResult = authDataResult {
  474. promise(.success(authDataResult))
  475. }
  476. }
  477. }
  478. }
  479. /// Asynchronously signs in to Firebase with the given 3rd-party credentials (e.g. a Facebook
  480. /// login Access Token, a Google ID Token/Access Token pair, etc.) and returns additional
  481. /// identity provider data.
  482. ///
  483. /// The publisher will emit events on the **main** thread.
  484. ///
  485. /// - Parameter credential: The credential supplied by the IdP.
  486. /// - Returns: A publisher that emits an `AuthDataResult` when the sign-in flow completed
  487. /// successfully, or an error otherwise. The publisher will emit on the *main* thread.
  488. /// - Remark: Possible error codes:
  489. /// - `FIRAuthErrorCodeInvalidCredential` - Indicates the supplied credential is invalid.
  490. /// This could happen if it has expired or it is malformed.
  491. /// - `FIRAuthErrorCodeOperationNotAllowed` - Indicates that accounts
  492. /// with the identity provider represented by the credential are not enabled.
  493. /// Enable them in the Auth section of the Firebase console.
  494. /// - `FIRAuthErrorCodeAccountExistsWithDifferentCredential` - Indicates the email asserted
  495. /// by the credential (e.g. the email in a Facebook access token) is already in use by an
  496. /// existing account, that cannot be authenticated with this sign-in method. Call
  497. /// fetchProvidersForEmail for this user’s email and then prompt them to sign in with any of
  498. /// the sign-in providers returned. This error will only be thrown if the "One account per
  499. /// email address" setting is enabled in the Firebase console, under Auth settings.
  500. /// - `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled.
  501. /// - `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted sign in with an
  502. /// incorrect password, if credential is of the type EmailPasswordAuthCredential.
  503. /// - `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
  504. /// - `FIRAuthErrorCodeMissingVerificationID` - Indicates that the phone auth credential was
  505. /// created with an empty verification ID.
  506. /// - `FIRAuthErrorCodeMissingVerificationCode` - Indicates that the phone auth credential
  507. /// was created with an empty verification code.
  508. /// - `FIRAuthErrorCodeInvalidVerificationCode` - Indicates that the phone auth credential
  509. /// was created with an invalid verification Code.
  510. /// - `FIRAuthErrorCodeInvalidVerificationID` - Indicates that the phone auth credential was
  511. /// created with an invalid verification ID.
  512. /// - `FIRAuthErrorCodeSessionExpired` - Indicates that the SMS code has expired.
  513. ///
  514. /// See `AuthErrors` for a list of error codes that are common to all API methods
  515. @discardableResult
  516. public func signIn(with credential: AuthCredential) -> Future<AuthDataResult, Error> {
  517. Future<AuthDataResult, Error> { promise in
  518. self.signIn(with: credential) { authDataResult, error in
  519. if let error = error {
  520. promise(.failure(error))
  521. } else if let authDataResult = authDataResult {
  522. promise(.success(authDataResult))
  523. }
  524. }
  525. }
  526. }
  527. }
  528. #endif // canImport(Combine) && swift(>=5.0)