Add AsyncStream support for Firebase Auth#15362
Merged
peterfriese merged 11 commits intoMar 31, 2026
mainfirebase/firebase-ios-sdk:mainfrom
peterfriese/asyncsequences/authfirebase/firebase-ios-sdk:peterfriese/asyncsequences/authCopy head branch name to clipboard
Merged
Add AsyncStream support for Firebase Auth#15362peterfriese merged 11 commits intomainfirebase/firebase-ios-sdk:mainfrom peterfriese/asyncsequences/authfirebase/firebase-ios-sdk:peterfriese/asyncsequences/authCopy head branch name to clipboard
peterfriese merged 11 commits into
mainfirebase/firebase-ios-sdk:mainfrom
peterfriese/asyncsequences/authfirebase/firebase-ios-sdk:peterfriese/asyncsequences/authCopy head branch name to clipboard
Conversation
paulb777
reviewed
Sep 30, 2025
peterfriese
marked this pull request as ready for review
September 30, 2025 09:06
Member
|
/gemini review |
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces AsyncStream-based APIs for observing authentication state and ID token changes, which is a great step towards modernizing the Firebase Auth SDK for Swift concurrency. The implementation is clean, well-documented, and includes a good set of unit tests.
My review includes a few suggestions to enhance the new APIs and tests:
- Broadening the API availability to support older OS versions where Swift concurrency is available.
- Improving the robustness of the unit tests by replacing
Task.sleepwith expectations. - Refactoring duplicated setup code in the tests to improve maintainability.
ncooke3
reviewed
Oct 2, 2025
peterfriese
force-pushed
the
peterfriese/asyncsequences/auth
branch
from
March 30, 2026 11:04
3b1b8d4 to
35f2754
Compare
peterfriese
added a commit
that referenced
this pull request
Mar 31, 2026
Introduces `AsyncSequence` support for `Query.snapshots` and `DocumentReference.snapshots`, enabling developers to handle Firestore real-time updates using Swift's structured concurrency. - Provides a modern, async-await compatible alternative to `addSnapshotListener`. - Supports both `Query` and `DocumentReference` snapshot streams. - Automatically handles listener registration and cleanup on task cancellation. - Configured with an unbounded buffering policy to ensure no snapshot events are lost. This work follows similar patterns introduced for Firebase Auth and Remote Config, bringing consistency to the developer experience across the Firebase Apple SDKs. Related Projects: - Firebase Auth AsyncSequence (#15362) - Remote Config AsyncSequence (#15352) Public API: - `DocumentReference.snapshots(includeMetadataChanges:) -> DocumentSnapshotsSequence` - `Query.snapshots(includeMetadataChanges:) -> QuerySnapshotsSequence` Tested on iOS, macOS, tvOS, and watchOS. Signed-off-by: Peter Friese <peter@peterfriese.dev> Co-authored-by: Nick Cooke <36927374+ncooke3@users.noreply.github.com>
This commit introduces an `AsyncStream`-based API for observing authentication state changes, aligning the Firebase Auth SDK with modern Swift concurrency patterns. The new `authStateChanges` computed property on `Auth` returns an `AsyncStream<User?>` that emits the current user whenever the authentication state changes. This provides a more ergonomic alternative to the traditional closure-based `addStateDidChangeListener`. Key changes include: - The implementation of `authStateChanges` in a new `Auth+Async.swift` file. - Comprehensive unit tests in `AuthAsyncTests.swift` covering the stream's behavior for sign-in, sign-out, and cancellation scenarios to prevent resource leaks. - An entry in the `FirebaseAuth/CHANGELOG.md` for the new feature. - Detailed API documentation for `authStateChanges`, including a clear usage example, following Apple's documentation best practices.
This commit introduces an `AsyncStream`-based API for observing ID token changes, aligning the Firebase Auth SDK with modern Swift concurrency patterns. The new `idTokenChanges` computed property on `Auth` returns an `AsyncStream<User?>` that emits the current user whenever the ID token changes. This provides a more ergonomic alternative to the traditional closure-based `addIDTokenDidChangeListener`. Key changes include: - The implementation of `idTokenChanges` in `Auth+Async.swift`. - Comprehensive unit tests in `IdTokenChangesAsyncTests.swift` covering the stream's behavior. - Renamed `AuthAsyncTests.swift` to `AuthStateChangesAsyncTests.swift` to better reflect its content.
…enChanges are `Sendable`.
peterfriese
force-pushed
the
peterfriese/asyncsequences/auth
branch
from
March 31, 2026 11:10
35f2754 to
d26c0fa
Compare
ncooke3
reviewed
Mar 31, 2026
ncooke3
reviewed
Mar 31, 2026
ncooke3
approved these changes
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #15361
To better align the Firebase Auth SDK with modern Swift concurrency, this PR introduces
AsyncStream-based APIs for observing authentication state and ID token changes.Key Features & Benefits
authStateChangesandidTokenChangesproperties onAuthreturn anAsyncStream<User?>, allowing developers to usefor awaitloops to monitor authentication events, which is more idiomatic in modern Swift.addStateDidChangeListenerandaddIDTokenDidChangeListener).Implementation Details
FirebaseAuth/Sources/Auth+Async.swiftfile.FirebaseAuth/Tests/Unit/AuthAsyncTests.swiftto cover sign-in, sign-out, token refresh, and stream cancellation scenarios.FirebaseAuth/CHANGELOG.mdhas been updated to reflect these new features.Example Usage
Monitoring Authentication State
Monitoring ID Token Changes