@@ -51,6 +51,10 @@ public enum AuthView {
51
51
case updatePassword
52
52
}
53
53
54
+ public enum SignInOutcome : @unchecked Sendable {
55
+ case signedIn( AuthDataResult ? )
56
+ }
57
+
54
58
@MainActor
55
59
private final class AuthListenerManager {
56
60
private var authStateHandle : AuthStateDidChangeListenerHandle ?
@@ -156,9 +160,10 @@ public final class AuthService {
156
160
)
157
161
}
158
162
159
- public func signIn( _ provider: AuthProviderSwift ) async throws {
163
+ public func signIn( _ provider: AuthProviderSwift ) async throws -> SignInOutcome {
160
164
let credential = try await provider. createAuthCredential ( )
161
- try await signIn ( credentials: credential)
165
+ let result = try await signIn ( credentials: credential)
166
+ return result
162
167
}
163
168
164
169
// MARK: - End Provider APIs
@@ -217,12 +222,14 @@ public final class AuthService {
217
222
}
218
223
}
219
224
220
- public func handleAutoUpgradeAnonymousUser( credentials: AuthCredential ) async throws {
225
+ public func handleAutoUpgradeAnonymousUser( credentials: AuthCredential ) async throws -> SignInOutcome {
221
226
if currentUser == nil {
222
227
throw AuthServiceError . noCurrentUser
223
228
}
224
229
do {
225
- try await currentUser? . link ( with: credentials)
230
+ let result = try await currentUser? . link ( with: credentials)
231
+ updateAuthenticationState ( )
232
+ return . signedIn( result)
226
233
} catch let error as NSError {
227
234
if error. code == AuthErrorCode . emailAlreadyInUse. rawValue {
228
235
let context = AccountMergeConflictContext (
@@ -237,16 +244,17 @@ public final class AuthService {
237
244
}
238
245
}
239
246
240
- public func signIn( credentials: AuthCredential ) async throws {
247
+ public func signIn( credentials: AuthCredential ) async throws -> SignInOutcome {
241
248
authenticationState = . authenticating
242
249
do {
243
250
if shouldHandleAnonymousUpgrade {
244
- try await handleAutoUpgradeAnonymousUser ( credentials: credentials)
251
+ return try await handleAutoUpgradeAnonymousUser ( credentials: credentials)
245
252
} else {
246
253
let result = try await auth. signIn ( with: credentials)
247
254
signedInCredential = result. credential ?? credentials
255
+ updateAuthenticationState ( )
256
+ return . signedIn( result)
248
257
}
249
- updateAuthenticationState ( )
250
258
} catch {
251
259
authenticationState = . unauthenticated
252
260
errorMessage = string. localizedErrorMessage (
@@ -333,23 +341,24 @@ public extension AuthService {
333
341
return self
334
342
}
335
343
336
- func signIn( withEmail email: String , password: String ) async throws {
344
+ func signIn( withEmail email: String , password: String ) async throws -> SignInOutcome {
337
345
let credential = EmailAuthProvider . credential ( withEmail: email, password: password)
338
- try await signIn ( credentials: credential)
346
+ return try await signIn ( credentials: credential)
339
347
}
340
348
341
- func createUser( withEmail email: String , password: String ) async throws {
349
+ func createUser( withEmail email: String , password: String ) async throws -> SignInOutcome {
342
350
authenticationState = . authenticating
343
351
344
352
do {
345
353
if shouldHandleAnonymousUpgrade {
346
354
let credential = EmailAuthProvider . credential ( withEmail: email, password: password)
347
- try await handleAutoUpgradeAnonymousUser ( credentials: credential)
355
+ return try await handleAutoUpgradeAnonymousUser ( credentials: credential)
348
356
} else {
349
357
let result = try await auth. createUser ( withEmail: email, password: password)
350
358
signedInCredential = result. credential
359
+ updateAuthenticationState ( )
360
+ return . signedIn( result)
351
361
}
352
- updateAuthenticationState ( )
353
362
} catch {
354
363
authenticationState = . unauthenticated
355
364
errorMessage = string. localizedErrorMessage (
0 commit comments