Skip to content

Commit 0d91e31

Browse files
committed
[Auth]: Add auth state stream utility
1 parent b20d812 commit 0d91e31

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

FirebaseAuth/Sources/Swift/Auth/Auth.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,23 @@ extension Auth: AuthInterop {
13611361
}
13621362
}
13631363

1364+
open struct AuthState {
1365+
let auth: Auth
1366+
let user: FirebaseAuth.User?
1367+
}
1368+
1369+
open var authStateChanges: AsyncStream<AuthState> {
1370+
return AsyncStream { continuation in
1371+
let listener = self.addStateDidChangeListener { auth, user in
1372+
continuation.yield(AuthState(auth: auth, user: user))
1373+
}
1374+
1375+
continuation.onTermination = { _ in
1376+
self.removeStateDidChangeListener(listener)
1377+
}
1378+
}
1379+
}
1380+
13641381
/// Unregisters a block as an "auth state did change" listener.
13651382
/// - Parameter listenerHandle: The handle for the listener.
13661383
@objc(removeAuthStateDidChangeListener:)

0 commit comments

Comments
 (0)