|
18 | 18 | import FirebaseAuth
|
19 | 19 |
|
20 | 20 | @available(swift 5.0)
|
21 |
| - @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) |
| 21 | + @available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, watchOS 6.0, *) |
22 | 22 | extension Auth {
|
23 | 23 | // MARK: - Authentication State Management
|
24 | 24 |
|
|
27 | 27 | /// The publisher emits values when:
|
28 | 28 | ///
|
29 | 29 | /// - It is registered,
|
30 |
| - /// - A user with a different UID from the current user has signed in, or |
31 |
| - /// - The current user has signed out. |
| 30 | + /// - a user with a different UID from the current user has signed in, or |
| 31 | + /// - the current user has signed out. |
32 | 32 | ///
|
33 | 33 | /// The publisher will emit events on the **main** thread.
|
34 | 34 | ///
|
35 |
| - /// - Returns: A publisher emitting a `User` instance (if the user has signed in) or `nil` (if the user has signed out) |
| 35 | + /// - Returns: A publisher emitting a `User` instance (if the user has signed in) or `nil` (if the user has signed out). |
| 36 | + /// The publisher will emit on the *main* thread. |
36 | 37 | public func authStateDidChangePublisher() -> AnyPublisher<User?, Never> {
|
37 | 38 | let subject = PassthroughSubject<User?, Never>()
|
38 | 39 | let handle = addStateDidChangeListener { auth, user in
|
|
50 | 51 | /// The publisher emits values when:
|
51 | 52 | ///
|
52 | 53 | /// - It is registered,
|
53 |
| - /// - A user with a different UID from the current user has signed in, |
54 |
| - /// - The ID token of the current user has been refreshed, or |
55 |
| - /// - The current user has signed out. |
| 54 | + /// - a user with a different UID from the current user has signed in, |
| 55 | + /// - the ID token of the current user has been refreshed, or |
| 56 | + /// - the current user has signed out. |
56 | 57 | ///
|
57 | 58 | /// The publisher will emit events on the **main** thread.
|
58 | 59 | ///
|
59 |
| - /// - Returns: A publisher emitting a `User` instance (if a different user as signed in or |
60 |
| - /// the ID token of the current user has changed) or `nil` (if the user has signed out) |
| 60 | + /// - Returns: A publisher emitting a `User` instance (if a different user is signed in or |
| 61 | + /// the ID token of the current user has changed) or `nil` (if the user has signed out). |
| 62 | + /// The publisher will emit on the *main* thread. |
61 | 63 | public func idTokenDidChangePublisher() -> AnyPublisher<User?, Never> {
|
62 | 64 | let subject = PassthroughSubject<User?, Never>()
|
63 | 65 | let handle = addIDTokenDidChangeListener { auth, user in
|
|
70 | 72 | .eraseToAnyPublisher()
|
71 | 73 | }
|
72 | 74 |
|
73 |
| - /// Sets the currentUser on the calling Auth instance to the provided user object. |
| 75 | + /// Sets the `currentUser` on the calling Auth instance to the provided `user` object. |
74 | 76 | ///
|
75 | 77 | /// The publisher will emit events on the **main** thread.
|
76 | 78 | ///
|
77 | 79 | /// - Parameter user: The user object to be set as the current user of the calling Auth instance.
|
78 |
| - /// - Returns: A publisher that emits as soon as the user of the calling Auth instance has been |
79 |
| - /// updated or an error was encountered. The publisher will emit on the *main* thread. |
| 80 | + /// - Returns: A publisher that emits when the user of the calling Auth instance has been updated or |
| 81 | + /// an error was encountered. The publisher will emit on the **main** thread. |
80 | 82 | @discardableResult
|
81 | 83 | public func updateCurrentUser(_ user: User) -> Future<Void, Error> {
|
82 | 84 | Future<Void, Error> { promise in
|
|
92 | 94 |
|
93 | 95 | // MARK: - Anonymous Authentication
|
94 | 96 |
|
95 |
| - /// Asynchronously creates and becomes an anonymous user. |
| 97 | + /// Asynchronously creates an anonymous user and assigns it as the calling Auth instance's current user. |
96 | 98 | ///
|
97 | 99 | /// If there is already an anonymous user signed in, that user will be returned instead.
|
98 | 100 | /// If there is any other existing user signed in, that user will be signed out.
|
99 | 101 | ///
|
100 | 102 | /// The publisher will emit events on the **main** thread.
|
101 | 103 | ///
|
102 |
| - /// - Returns: A publisher that emits the result of the sign in flow. |
| 104 | + /// - Returns: A publisher that emits the result of the sign in flow. The publisher will emit on the *main* thread. |
103 | 105 | /// - Remark:
|
104 | 106 | /// Possible error codes:
|
105 | 107 | /// - `AuthErrorCodeOperationNotAllowed` - Indicates that anonymous accounts are
|
|
128 | 130 | /// - Parameters:
|
129 | 131 | /// - email: The user's email address.
|
130 | 132 | /// - password: The user's desired password.
|
131 |
| - /// - Returns: A publisher that emits the result of the sign in flow. |
| 133 | + /// - Returns: A publisher that emits the result of the sign in flow. The publisher will emit on the *main* thread. |
132 | 134 | /// - Remark:
|
133 | 135 | /// Possible error codes:
|
134 | 136 | /// - `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
|
|
156 | 158 | }
|
157 | 159 | }
|
158 | 160 |
|
159 |
| - /// Signs in using an email address and password. |
| 161 | + /// Signs in a user with the given email address and password. |
160 | 162 | ///
|
161 | 163 | /// The publisher will emit events on the **main** thread.
|
162 | 164 | ///
|
163 | 165 | /// - Parameters:
|
164 | 166 | /// - email: The user's email address.
|
165 |
| - /// - password: The user's desired password. |
166 |
| - /// - Returns: A publisher that emits the result of the sign in flow. |
| 167 | + /// - password: The user's password. |
| 168 | + /// - Returns: A publisher that emits the result of the sign in flow. The publisher will emit on the *main* thread. |
167 | 169 | /// - Remark:
|
168 | 170 | /// Possible error codes:
|
169 | 171 | /// - `AuthErrorCodeOperationNotAllowed` - Indicates that email and password
|
|
198 | 200 | /// - Parameters:
|
199 | 201 | /// - email: The user's email address.
|
200 | 202 | /// - link: The email sign-in link.
|
201 |
| - /// - Returns: A publisher that emits the result of the sign in flow. |
| 203 | + /// - Returns: A publisher that emits the result of the sign in flow. The publisher will emit on the *main* thread. |
202 | 204 | /// - Remark:
|
203 | 205 | /// Possible error codes:
|
204 | 206 | /// - `AuthErrorCodeOperationNotAllowed` - Indicates that email and password
|
|
208 | 210 | /// - `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
|
209 | 211 | ///
|
210 | 212 | /// See `AuthErrors` for a list of error codes that are common to all API methods
|
| 213 | + @available(watchOS, unavailable) |
211 | 214 | @discardableResult
|
212 | 215 | public func signIn(withEmail email: String,
|
213 | 216 | link: String) -> Future<AuthDataResult, Error> {
|
|
230 | 233 | /// - email: The email address of the user.
|
231 | 234 | /// - actionCodeSettings: An `ActionCodeSettings` object containing settings related to
|
232 | 235 | /// handling action codes.
|
233 |
| - /// - Returns: A publisher that emits whether the call was successful or not. |
| 236 | + /// - Returns: A publisher that emits whether the call was successful or not. The publisher will emit on the *main* thread. |
| 237 | + @available(watchOS, unavailable) |
234 | 238 | @discardableResult
|
235 | 239 | public func sendSignInLink(toEmail email: String,
|
236 | 240 | actionCodeSettings: ActionCodeSettings) -> Future<Void, Error> {
|
|
253 | 257 | ///
|
254 | 258 | /// - Parameter email: The email address for which to obtain a list of sign-in methods.
|
255 | 259 | /// - Returns: A publisher that emits a list of sign-in methods for the specified email
|
256 |
| - /// address, or an error if one occurred. |
| 260 | + /// address, or an error if one occurred. The publisher will emit on the *main* thread. |
257 | 261 | /// - Remark: Possible error codes:
|
258 | 262 | /// - `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
|
259 | 263 | ///
|
|
277 | 281 | /// The publisher will emit events on the **main** thread.
|
278 | 282 | ///
|
279 | 283 | /// - Parameters:
|
280 |
| - /// - code: Out-of-band code given to the user outside of the app. |
| 284 | + /// - code: Out-of-band (OOB) code given to the user outside of the app. |
281 | 285 | /// - newPassword: The new password.
|
282 |
| - /// - Returns: A publisher that emits whether the call was successful or not. |
| 286 | + /// - Returns: A publisher that emits whether the call was successful or not. The publisher will emit on the *main* thread. |
283 | 287 | /// - Remark: Possible error codes:
|
284 | 288 | /// - `AuthErrorCodeWeakPassword` - Indicates an attempt to set a password that is considered too weak.
|
285 |
| - /// - `AuthErrorCodeOperationNotAllowed` - Indicates the administrator disabled sign in with the specified identity provider. |
| 289 | + /// - `AuthErrorCodeOperationNotAllowed` - Indicates the admin disabled sign in with the specified identity provider. |
286 | 290 | /// - `AuthErrorCodeExpiredActionCode` - Indicates the OOB code is expired.
|
287 | 291 | /// - `AuthErrorCodeInvalidActionCode` - Indicates the OOB code is invalid.
|
288 | 292 | ///
|
|
308 | 312 | /// - Parameter code: The password reset code to be verified.
|
309 | 313 | /// - Returns: A publisher that emits an error if the code could not be verified. If the code could be
|
310 | 314 | /// verified, the publisher will emit the email address of the account the code was issued for.
|
| 315 | + /// The publisher will emit on the *main* thread. |
311 | 316 | @discardableResult
|
312 | 317 | public func verifyPasswordResetCode(_ code: String) -> Future<String, Error> {
|
313 | 318 | Future<String, Error> { promise in
|
|
326 | 331 | /// The publisher will emit events on the **main** thread.
|
327 | 332 | ///
|
328 | 333 | /// - Parameter code: The out of band code to check validity.
|
329 |
| - /// - Returns: A publisher that emits an error if the code could not be verified. If the code could be |
330 |
| - /// verified, the publisher will emit the email address of the account the code was issued for. |
| 334 | + /// - Returns: A publisher that emits the email address of the account the code was issued for or an error if |
| 335 | + /// the code could not be verified. The publisher will emit on the *main* thread. |
331 | 336 | @discardableResult
|
332 | 337 | public func checkActionCode(code: String) -> Future<ActionCodeInfo, Error> {
|
333 | 338 | Future<ActionCodeInfo, Error> { promise in
|
|
345 | 350 | ///
|
346 | 351 | /// The publisher will emit events on the **main** thread.
|
347 | 352 | ///
|
348 |
| - /// - Parameter code: The out of band code to be applied. |
349 |
| - /// - Returns: A publisher that emits an error if the code could not be applied. |
350 |
| - /// - Remark: This method will not work for out of band codes which require an additional parameter, |
351 |
| - /// such as password reset code. |
| 353 | + /// - Parameter code: The out-of-band (OOB) code to be applied. |
| 354 | + /// - Returns: A publisher that emits an error if the code could not be applied. The publisher will emit on the *main* thread. |
| 355 | + /// - Remark: This method will not work for out-of-band codes which require an additional parameter, |
| 356 | + /// such as password reset codes. |
352 | 357 | @discardableResult
|
353 | 358 | public func applyActionCode(code: String) -> Future<Void, Error> {
|
354 | 359 | Future<Void, Error> { promise in
|
|
367 | 372 | /// The publisher will emit events on the **main** thread.
|
368 | 373 | ///
|
369 | 374 | /// - Parameter email: The email address of the user.
|
370 |
| - /// - Returns: A publisher that emits whether the call was successful or not. |
| 375 | + /// - Returns: A publisher that emits whether the call was successful or not. The publisher will emit on the *main* thread. |
371 | 376 | /// - Remark: Possible error codes:
|
372 | 377 | /// - `AuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was sent in the request.
|
373 | 378 | /// - `AuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in the console for this action.
|
|
392 | 397 | /// The publisher will emit events on the **main** thread.
|
393 | 398 | ///
|
394 | 399 | /// - Parameter email: The email address of the user.
|
395 |
| - /// - Parameter actionCodeSettings: An `ActionCodeSettings` object containing settings related t handling action codes. |
396 |
| - /// - Returns: A publisher that emits whether the call was successful or not. |
| 400 | + /// - Parameter actionCodeSettings: An `ActionCodeSettings` object containing settings related to |
| 401 | + /// handling action codes. |
| 402 | + /// - Returns: A publisher that emits whether the call was successful or not. The publisher will emit on the *main* thread. |
397 | 403 | /// - Remark: Possible error codes:
|
398 | 404 | /// - `AuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was sent in the request.
|
399 | 405 | /// - `AuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in the console for this action.
|
400 | 406 | /// - `AuthErrorCodeInvalidMessagePayload` - Indicates an invalid email template for sending update email.
|
401 |
| - /// - `AuthErrorCodeMissingIosBundleID` - Indicates that the iOS bundle ID is missing when `handleCodeInApp` is set to YES. |
402 |
| - /// - `AuthErrorCodeMissingAndroidPackageName` - Indicates that the android package name is missing when the `androidInstallApp` flag is set to true. |
403 |
| - /// - `AuthErrorCodeUnauthorizedDomain` - Indicates that the domain specified in the continue URL is not whitelisted in the Firebase console. |
| 407 | + /// - `AuthErrorCodeMissingIosBundleID` - Indicates that the iOS bundle ID is missing |
| 408 | + /// when `handleCodeInApp` is set to YES. |
| 409 | + /// - `AuthErrorCodeMissingAndroidPackageName` - Indicates that the android package name is missing |
| 410 | + /// when the `androidInstallApp` flag is set to true. |
| 411 | + /// - `AuthErrorCodeUnauthorizedDomain` - Indicates that the domain specified in the continue URL is not whitelisted |
| 412 | + /// in the Firebase console. |
404 | 413 | /// - `AuthErrorCodeInvalidContinueURI` - Indicates that the domain specified in the continue URI is not valid.
|
405 | 414 | ///
|
406 | 415 | /// See `AuthErrors` for a list of error codes that are common to all API methods
|
|
420 | 429 |
|
421 | 430 | // MARK: - Other Authentication providers
|
422 | 431 |
|
423 |
| - #if !os(tvOS) && !os(macOS) |
424 |
| - |
| 432 | + #if os(iOS) || targetEnvironment(macCatalyst) |
425 | 433 | /// Signs in using the provided auth provider instance.
|
426 | 434 | ///
|
427 | 435 | /// The publisher will emit events on the **main** thread.
|
428 | 436 | ///
|
429 | 437 | /// - Parameters:
|
430 | 438 | /// - provider: An instance of an auth provider used to initiate the sign-in flow.
|
431 |
| - /// - uiDelegate: Optionally an instance of a class conforming to the `AuthUIDelegate` |
| 439 | + /// - uiDelegate: Optionally, an instance of a class conforming to the `AuthUIDelegate` |
432 | 440 | /// protocol. This is used for presenting the web context. If `nil`, a default `AuthUIDelegate`
|
433 | 441 | /// will be used.
|
434 | 442 | /// - Returns: A publisher that emits an `AuthDataResult` when the sign-in flow completed
|
|
466 | 474 | }
|
467 | 475 | }
|
468 | 476 | }
|
469 |
| - |
470 |
| - #endif |
| 477 | + #endif // os(iOS) || targetEnvironment(macCatalyst) |
471 | 478 |
|
472 | 479 | /// Asynchronously signs in to Firebase with the given Auth token.
|
473 | 480 | ///
|
|
545 | 552 | }
|
546 | 553 | }
|
547 | 554 | }
|
548 |
| -#endif |
| 555 | + |
| 556 | +#endif // canImport(Combine) && swift(>=5.0) && canImport(FirebaseAuth) |
0 commit comments