@@ -33,38 +33,53 @@ abstract class FirebaseAuth {
3333 Stream <FirebaseUser > currentUser ();
3434
3535 /// Returns a future that completes after authenticated.
36- Future <FirebaseUser > googleSignIn ();
36+ ///
37+ /// May optionally disable [prompt] if the user is already authenticated.
38+ Future <FirebaseUser > googleSignIn ({bool prompt: true });
3739
3840 /// Sign out of any authenticated account.
3941 Future <Null > signOut ();
4042}
4143
4244class _SdkFirebaseAuth implements FirebaseAuth {
43- static final sdk. AuthProvider _googleAuth = new sdk.GoogleAuthProvider ();
45+ static final _googleAuth = new sdk.GoogleAuthProvider ();
4446
4547 final sdk.App _app;
4648 final _onUserChanged = new StreamController <FirebaseUser >.broadcast ();
4749
4850 FirebaseUser _currentUser;
51+ bool _wasInitialized = false ;
4952
5053 _SdkFirebaseAuth (this ._app) {
5154 _app.auth ().onAuthStateChanged.listen ((event) {
5255 final user = event.user;
56+ _wasInitialized = true ;
5357 _currentUser = user != null ? new FirebaseUser ._fromSdk (user) : null ;
5458 _onUserChanged.add (_currentUser);
5559 });
5660 }
5761
5862 @override
5963 Stream <FirebaseUser > currentUser () async * {
60- yield _currentUser;
64+ if (_wasInitialized) {
65+ yield _currentUser;
66+ }
6167 yield * _onUserChanged.stream;
6268 }
6369
6470 @override
65- Future <FirebaseUser > googleSignIn () async {
66- final user = await _app.auth ().signInWithPopup (_googleAuth);
67- return new FirebaseUser ._fromSdk (user.user);
71+ Future <FirebaseUser > googleSignIn ({
72+ bool prompt: true ,
73+ }) async {
74+ _googleAuth.setCustomParameters (< String , String > {
75+ 'prompt' : prompt ? 'select_account' : 'none' ,
76+ });
77+ try {
78+ final user = await _app.auth ().signInWithPopup (_googleAuth);
79+ return new FirebaseUser ._fromSdk (user.user);
80+ } catch (_) {
81+ return null ;
82+ }
6883 }
6984
7085 @override
@@ -132,6 +147,7 @@ class IfFirebaseAuthDirective implements OnDestroy, OnInit {
132147 bool _lastCondition;
133148 FirebaseUser _currentUser;
134149 StreamSubscription <FirebaseUser > _userSub;
150+ bool _wasInitialized = false ;
135151
136152 IfFirebaseAuthDirective (
137153 this ._authService,
@@ -142,7 +158,9 @@ class IfFirebaseAuthDirective implements OnDestroy, OnInit {
142158 @Input ()
143159 set ifFirebaseAuth (bool newCondition) {
144160 _checkCondition = newCondition;
145- _toggle (_checkCondition ? _currentUser != null : _currentUser == null );
161+ if (_wasInitialized) {
162+ _toggle (_checkCondition ? _currentUser != null : _currentUser == null );
163+ }
146164 }
147165
148166 @override
@@ -155,6 +173,7 @@ class IfFirebaseAuthDirective implements OnDestroy, OnInit {
155173 _userSub = _authService.currentUser ().listen ((user) {
156174 _currentUser = user;
157175 _toggle (_checkCondition ? _currentUser != null : _currentUser == null );
176+ _wasInitialized = true ;
158177 });
159178 }
160179
0 commit comments