@@ -227,10 +227,16 @@ extension User: NSSecureCoding {}
227
227
@objc ( updatePhoneNumberCredential: completion: )
228
228
open func updatePhoneNumber( _ credential: PhoneAuthCredential ,
229
229
completion: ( ( Error ? ) -> Void ) ? = nil ) {
230
- kAuthGlobalWorkQueue. async {
231
- self . internalUpdateOrLinkPhoneNumber ( credential: credential,
232
- isLinkOperation: false ) { error in
233
- User . callInMainThreadWithError ( callback: completion, error: error)
230
+ Task {
231
+ do {
232
+ try await self . updatePhoneNumber ( credential)
233
+ await MainActor . run {
234
+ completion ? ( nil )
235
+ }
236
+ } catch {
237
+ await MainActor . run {
238
+ completion ? ( error)
239
+ }
234
240
}
235
241
}
236
242
}
@@ -251,15 +257,9 @@ extension User: NSSecureCoding {}
251
257
/// account this new phone number will replace it.
252
258
@available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
253
259
open func updatePhoneNumber( _ credential: PhoneAuthCredential ) async throws {
254
- return try await withCheckedThrowingContinuation { continuation in
255
- self . updatePhoneNumber ( credential) { error in
256
- if let error {
257
- continuation. resume ( throwing: error)
258
- } else {
259
- continuation. resume ( )
260
- }
261
- }
262
- }
260
+ try await auth. authWorker. updateOrLinkPhoneNumber ( user: self ,
261
+ credential: credential,
262
+ isLinkOperation: false )
263
263
}
264
264
#endif
265
265
@@ -296,9 +296,16 @@ extension User: NSSecureCoding {}
296
296
/// - Parameter completion: Optionally; the block invoked when the reload has finished. Invoked
297
297
/// asynchronously on the main thread in the future.
298
298
@objc open func reload( completion: ( ( Error ? ) -> Void ) ? = nil ) {
299
- kAuthGlobalWorkQueue. async {
300
- self . getAccountInfoRefreshingCache { user, error in
301
- User . callInMainThreadWithError ( callback: completion, error: error)
299
+ Task {
300
+ do {
301
+ try await self . reload ( )
302
+ await MainActor . run {
303
+ completion ? ( nil )
304
+ }
305
+ } catch {
306
+ await MainActor . run {
307
+ completion ? ( error)
308
+ }
302
309
}
303
310
}
304
311
}
@@ -310,15 +317,7 @@ extension User: NSSecureCoding {}
310
317
/// `updateEmail(to:)`.
311
318
@available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
312
319
open func reload( ) async throws {
313
- return try await withCheckedThrowingContinuation { continuation in
314
- self . reload { error in
315
- if let error {
316
- continuation. resume ( throwing: error)
317
- } else {
318
- continuation. resume ( )
319
- }
320
- }
321
- }
320
+ let _ = try await auth. authWorker. getAccountInfoRefreshingCache ( self )
322
321
}
323
322
324
323
/// Renews the user's authentication tokens by validating a fresh set of credentials supplied
@@ -418,15 +417,15 @@ extension User: NSSecureCoding {}
418
417
open func reauthenticate( with provider: FederatedAuthProvider ,
419
418
uiDelegate: AuthUIDelegate ? ,
420
419
completion: ( ( AuthDataResult ? , Error ? ) -> Void ) ? = nil ) {
421
- kAuthGlobalWorkQueue . async {
422
- Task {
423
- do {
424
- let credential = try await provider . credential ( with : uiDelegate )
425
- self . reauthenticate ( with : credential , completion : completion )
426
- } catch {
427
- if let completion {
428
- completion ( nil , error )
429
- }
420
+ Task {
421
+ do {
422
+ let result = try await reauthenticate ( with : provider , uiDelegate : uiDelegate )
423
+ await MainActor . run {
424
+ completion ? ( result , nil )
425
+ }
426
+ } catch {
427
+ await MainActor . run {
428
+ completion ? ( nil , error )
430
429
}
431
430
}
432
431
}
@@ -445,15 +444,7 @@ extension User: NSSecureCoding {}
445
444
@discardableResult
446
445
open func reauthenticate( with provider: FederatedAuthProvider ,
447
446
uiDelegate: AuthUIDelegate ? ) async throws -> AuthDataResult {
448
- return try await withCheckedThrowingContinuation { continuation in
449
- self . reauthenticate ( with: provider, uiDelegate: uiDelegate) { result, error in
450
- if let result {
451
- continuation. resume ( returning: result)
452
- } else if let error {
453
- continuation. resume ( throwing: error)
454
- }
455
- }
456
- }
447
+ return try await auth. authWorker. reauthenticate ( with: provider, uiDelegate: uiDelegate)
457
448
}
458
449
#endif
459
450
@@ -478,10 +469,15 @@ extension User: NSSecureCoding {}
478
469
@objc ( getIDTokenForcingRefresh: completion: )
479
470
open func getIDTokenForcingRefresh( _ forceRefresh: Bool ,
480
471
completion: ( ( String ? , Error ? ) -> Void ) ? ) {
481
- getIDTokenResult ( forcingRefresh: forceRefresh) { tokenResult, error in
482
- if let completion {
483
- DispatchQueue . main. async {
484
- completion ( tokenResult? . token, error)
472
+ Task {
473
+ do {
474
+ let tokenResult = try await getIDTokenResult ( forcingRefresh: forceRefresh)
475
+ await MainActor . run {
476
+ completion ? ( tokenResult. token, nil )
477
+ }
478
+ } catch {
479
+ await MainActor . run {
480
+ completion ? ( nil , error)
485
481
}
486
482
}
487
483
}
@@ -496,15 +492,7 @@ extension User: NSSecureCoding {}
496
492
/// - Returns: The Firebase authentication token.
497
493
@available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
498
494
open func getIDToken( forcingRefresh forceRefresh: Bool = false ) async throws -> String {
499
- return try await withCheckedThrowingContinuation { continuation in
500
- self . getIDTokenForcingRefresh ( forceRefresh) { tokenResult, error in
501
- if let tokenResult {
502
- continuation. resume ( returning: tokenResult)
503
- } else if let error {
504
- continuation. resume ( throwing: error)
505
- }
506
- }
507
- }
495
+ return try await getIDTokenResult ( forcingRefresh: forceRefresh) . token
508
496
}
509
497
510
498
/// API included for compatibility with a mis-named Firebase 10 API.
@@ -518,13 +506,7 @@ extension User: NSSecureCoding {}
518
506
/// asynchronously on the main thread in the future.
519
507
@objc ( getIDTokenResultWithCompletion: )
520
508
open func getIDTokenResult( completion: ( ( AuthTokenResult ? , Error ? ) -> Void ) ? ) {
521
- getIDTokenResult ( forcingRefresh: false ) { tokenResult, error in
522
- if let completion {
523
- DispatchQueue . main. async {
524
- completion ( tokenResult, error)
525
- }
526
- }
527
- }
509
+ getIDTokenResult ( forcingRefresh: false , completion: completion)
528
510
}
529
511
530
512
/// Retrieves the Firebase authentication token, possibly refreshing it if it has expired.
@@ -539,34 +521,15 @@ extension User: NSSecureCoding {}
539
521
@objc ( getIDTokenResultForcingRefresh: completion: )
540
522
open func getIDTokenResult( forcingRefresh: Bool ,
541
523
completion: ( ( AuthTokenResult ? , Error ? ) -> Void ) ? ) {
542
- kAuthGlobalWorkQueue. async {
543
- self . internalGetToken ( forceRefresh: forcingRefresh) { token, error in
544
- var tokenResult : AuthTokenResult ?
545
- if let token {
546
- do {
547
- tokenResult = try AuthTokenResult . tokenResult ( token: token)
548
- AuthLog . logDebug ( code: " I-AUT000017 " , message: " Actual token expiration date: " +
549
- " \( String ( describing: tokenResult? . expirationDate) ) , " +
550
- " current date: \( Date ( ) ) " )
551
- if let completion {
552
- DispatchQueue . main. async {
553
- completion ( tokenResult, error)
554
- }
555
- }
556
- return
557
- } catch {
558
- if let completion {
559
- DispatchQueue . main. async {
560
- completion ( tokenResult, error)
561
- }
562
- }
563
- return
564
- }
524
+ Task {
525
+ do {
526
+ let tokenResult = try await getIDTokenResult ( forcingRefresh: forcingRefresh)
527
+ await MainActor . run {
528
+ completion ? ( tokenResult, nil )
565
529
}
566
- if let completion {
567
- DispatchQueue . main. async {
568
- completion ( nil , error)
569
- }
530
+ } catch {
531
+ await MainActor . run {
532
+ completion ? ( nil , error)
570
533
}
571
534
}
572
535
}
@@ -582,15 +545,7 @@ extension User: NSSecureCoding {}
582
545
@available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
583
546
open func getIDTokenResult( forcingRefresh forceRefresh: Bool = false ) async throws
584
547
-> AuthTokenResult {
585
- return try await withCheckedThrowingContinuation { continuation in
586
- self . getIDTokenResult ( forcingRefresh: forceRefresh) { tokenResult, error in
587
- if let tokenResult {
588
- continuation. resume ( returning: tokenResult)
589
- } else if let error {
590
- continuation. resume ( throwing: error)
591
- }
592
- }
593
- }
548
+ try await auth. authWorker. getIDTokenResult ( user: self , forcingRefresh: forceRefresh)
594
549
}
595
550
596
551
/// Associates a user account from a third-party identity provider with this user and
0 commit comments