Skip to content

Commit 898b9fb

Browse files
authored
FirebaseCombineSwift: Docs & API cleanup (#8088)
* Docs & API cleanup * Style * Review * Review 2 * Review 3 * Review 4 * Review 5
1 parent 4dc7558 commit 898b9fb

10 files changed

+352
-310
lines changed

FirebaseCombineSwift/Sources/Auth/Auth+Combine.swift

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import FirebaseAuth
1919

2020
@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, *)
2222
extension Auth {
2323
// MARK: - Authentication State Management
2424

@@ -27,12 +27,13 @@
2727
/// The publisher emits values when:
2828
///
2929
/// - 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.
3232
///
3333
/// The publisher will emit events on the **main** thread.
3434
///
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.
3637
public func authStateDidChangePublisher() -> AnyPublisher<User?, Never> {
3738
let subject = PassthroughSubject<User?, Never>()
3839
let handle = addStateDidChangeListener { auth, user in
@@ -50,14 +51,15 @@
5051
/// The publisher emits values when:
5152
///
5253
/// - 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.
5657
///
5758
/// The publisher will emit events on the **main** thread.
5859
///
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.
6163
public func idTokenDidChangePublisher() -> AnyPublisher<User?, Never> {
6264
let subject = PassthroughSubject<User?, Never>()
6365
let handle = addIDTokenDidChangeListener { auth, user in
@@ -70,13 +72,13 @@
7072
.eraseToAnyPublisher()
7173
}
7274

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.
7476
///
7577
/// The publisher will emit events on the **main** thread.
7678
///
7779
/// - 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.
8082
@discardableResult
8183
public func updateCurrentUser(_ user: User) -> Future<Void, Error> {
8284
Future<Void, Error> { promise in
@@ -92,14 +94,14 @@
9294

9395
// MARK: - Anonymous Authentication
9496

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.
9698
///
9799
/// If there is already an anonymous user signed in, that user will be returned instead.
98100
/// If there is any other existing user signed in, that user will be signed out.
99101
///
100102
/// The publisher will emit events on the **main** thread.
101103
///
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.
103105
/// - Remark:
104106
/// Possible error codes:
105107
/// - `AuthErrorCodeOperationNotAllowed` - Indicates that anonymous accounts are
@@ -128,7 +130,7 @@
128130
/// - Parameters:
129131
/// - email: The user's email address.
130132
/// - 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.
132134
/// - Remark:
133135
/// Possible error codes:
134136
/// - `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
@@ -156,14 +158,14 @@
156158
}
157159
}
158160

159-
/// Signs in using an email address and password.
161+
/// Signs in a user with the given email address and password.
160162
///
161163
/// The publisher will emit events on the **main** thread.
162164
///
163165
/// - Parameters:
164166
/// - 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.
167169
/// - Remark:
168170
/// Possible error codes:
169171
/// - `AuthErrorCodeOperationNotAllowed` - Indicates that email and password
@@ -198,7 +200,7 @@
198200
/// - Parameters:
199201
/// - email: The user's email address.
200202
/// - 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.
202204
/// - Remark:
203205
/// Possible error codes:
204206
/// - `AuthErrorCodeOperationNotAllowed` - Indicates that email and password
@@ -208,6 +210,7 @@
208210
/// - `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
209211
///
210212
/// See `AuthErrors` for a list of error codes that are common to all API methods
213+
@available(watchOS, unavailable)
211214
@discardableResult
212215
public func signIn(withEmail email: String,
213216
link: String) -> Future<AuthDataResult, Error> {
@@ -230,7 +233,8 @@
230233
/// - email: The email address of the user.
231234
/// - actionCodeSettings: An `ActionCodeSettings` object containing settings related to
232235
/// 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)
234238
@discardableResult
235239
public func sendSignInLink(toEmail email: String,
236240
actionCodeSettings: ActionCodeSettings) -> Future<Void, Error> {
@@ -253,7 +257,7 @@
253257
///
254258
/// - Parameter email: The email address for which to obtain a list of sign-in methods.
255259
/// - 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.
257261
/// - Remark: Possible error codes:
258262
/// - `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.
259263
///
@@ -277,12 +281,12 @@
277281
/// The publisher will emit events on the **main** thread.
278282
///
279283
/// - 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.
281285
/// - 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.
283287
/// - Remark: Possible error codes:
284288
/// - `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.
286290
/// - `AuthErrorCodeExpiredActionCode` - Indicates the OOB code is expired.
287291
/// - `AuthErrorCodeInvalidActionCode` - Indicates the OOB code is invalid.
288292
///
@@ -308,6 +312,7 @@
308312
/// - Parameter code: The password reset code to be verified.
309313
/// - Returns: A publisher that emits an error if the code could not be verified. If the code could be
310314
/// 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.
311316
@discardableResult
312317
public func verifyPasswordResetCode(_ code: String) -> Future<String, Error> {
313318
Future<String, Error> { promise in
@@ -326,8 +331,8 @@
326331
/// The publisher will emit events on the **main** thread.
327332
///
328333
/// - 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.
331336
@discardableResult
332337
public func checkActionCode(code: String) -> Future<ActionCodeInfo, Error> {
333338
Future<ActionCodeInfo, Error> { promise in
@@ -345,10 +350,10 @@
345350
///
346351
/// The publisher will emit events on the **main** thread.
347352
///
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.
352357
@discardableResult
353358
public func applyActionCode(code: String) -> Future<Void, Error> {
354359
Future<Void, Error> { promise in
@@ -367,7 +372,7 @@
367372
/// The publisher will emit events on the **main** thread.
368373
///
369374
/// - 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.
371376
/// - Remark: Possible error codes:
372377
/// - `AuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was sent in the request.
373378
/// - `AuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in the console for this action.
@@ -392,15 +397,19 @@
392397
/// The publisher will emit events on the **main** thread.
393398
///
394399
/// - 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.
397403
/// - Remark: Possible error codes:
398404
/// - `AuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was sent in the request.
399405
/// - `AuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in the console for this action.
400406
/// - `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.
404413
/// - `AuthErrorCodeInvalidContinueURI` - Indicates that the domain specified in the continue URI is not valid.
405414
///
406415
/// See `AuthErrors` for a list of error codes that are common to all API methods
@@ -420,15 +429,14 @@
420429

421430
// MARK: - Other Authentication providers
422431

423-
#if !os(tvOS) && !os(macOS)
424-
432+
#if os(iOS) || targetEnvironment(macCatalyst)
425433
/// Signs in using the provided auth provider instance.
426434
///
427435
/// The publisher will emit events on the **main** thread.
428436
///
429437
/// - Parameters:
430438
/// - 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`
432440
/// protocol. This is used for presenting the web context. If `nil`, a default `AuthUIDelegate`
433441
/// will be used.
434442
/// - Returns: A publisher that emits an `AuthDataResult` when the sign-in flow completed
@@ -466,8 +474,7 @@
466474
}
467475
}
468476
}
469-
470-
#endif
477+
#endif // os(iOS) || targetEnvironment(macCatalyst)
471478

472479
/// Asynchronously signs in to Firebase with the given Auth token.
473480
///
@@ -545,4 +552,5 @@
545552
}
546553
}
547554
}
548-
#endif
555+
556+
#endif // canImport(Combine) && swift(>=5.0) && canImport(FirebaseAuth)

FirebaseCombineSwift/Sources/Auth/GameCenterAuthProvider+Combine.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import FirebaseAuth
1919

2020
@available(swift 5.0)
21+
@available(iOS 13.0, macOS 10.15, macCatalyst 13.0, tvOS 13.0, *)
2122
@available(watchOS, unavailable)
22-
@available(macOS 10.15, iOS 13, tvOS 13, *)
2323
extension GameCenterAuthProvider {
24-
/// Creates a `AuthCredential` for a Game Center sign in.
24+
/// Creates an `AuthCredential` for a Game Center sign in.
2525
///
2626
/// The publisher will emit events on the **main** thread.
2727
///
@@ -40,4 +40,4 @@
4040
}
4141
}
4242

43-
#endif
43+
#endif // canImport(Combine) && swift(>=5.0) && canImport(FirebaseAuth)

0 commit comments

Comments
 (0)