diff --git a/packages/firebase_ui_auth/lib/firebase_ui_auth.dart b/packages/firebase_ui_auth/lib/firebase_ui_auth.dart index ec3189f39491..dcc6e427348a 100644 --- a/packages/firebase_ui_auth/lib/firebase_ui_auth.dart +++ b/packages/firebase_ui_auth/lib/firebase_ui_auth.dart @@ -18,6 +18,7 @@ export 'src/auth_state.dart' CredentialReceived, SignedIn, SigningIn, + UserCreated, AuthFailed, DifferentSignInMethodsFound, MFARequired; diff --git a/packages/firebase_ui_auth/lib/src/auth_flow.dart b/packages/firebase_ui_auth/lib/src/auth_flow.dart index 8726dd625761..ac344ade4ecc 100644 --- a/packages/firebase_ui_auth/lib/src/auth_flow.dart +++ b/packages/firebase_ui_auth/lib/src/auth_flow.dart @@ -144,7 +144,11 @@ class AuthFlow extends ValueNotifier @override void onSignedIn(UserCredential credential) { - value = SignedIn(credential.user); + if (credential.additionalUserInfo?.isNewUser ?? false) { + value = UserCreated(credential); + } else { + value = SignedIn(credential.user); + } } @override diff --git a/packages/firebase_ui_auth/lib/src/auth_state.dart b/packages/firebase_ui_auth/lib/src/auth_state.dart index 47b25cd03ebf..d7c205742c7c 100644 --- a/packages/firebase_ui_auth/lib/src/auth_state.dart +++ b/packages/firebase_ui_auth/lib/src/auth_state.dart @@ -5,7 +5,7 @@ import 'package:firebase_ui_auth/firebase_ui_auth.dart'; import 'package:flutter/widgets.dart'; import 'package:firebase_auth/firebase_auth.dart' - show AuthCredential, MultiFactorResolver, User; + show AuthCredential, MultiFactorResolver, User, UserCredential; /// An abstract class for all auth states. /// [AuthState] transitions could be captured with an [AuthStateChangeAction]: @@ -146,6 +146,14 @@ class SignedIn extends AuthState { SignedIn(this.user); } +/// A state that indicates that a new user account was created. +class UserCreated extends AuthState { + /// A [UserCredential] that was obtained during authentication process. + final UserCredential credential; + + UserCreated(this.credential); +} + /// {@template ui.auth.auth_state.different_sign_in_methods_found} /// An [AuthState] that indicates that there are different auth providers /// associated with an email that was used to authenticate. diff --git a/packages/firebase_ui_auth/lib/src/flows/email_flow.dart b/packages/firebase_ui_auth/lib/src/flows/email_flow.dart index 12f6c16beb03..ceab53cb2e9f 100644 --- a/packages/firebase_ui_auth/lib/src/flows/email_flow.dart +++ b/packages/firebase_ui_auth/lib/src/flows/email_flow.dart @@ -10,14 +10,6 @@ import 'package:firebase_ui_auth/firebase_ui_auth.dart'; /// [AwaitingEmailAndPassword]. class AwaitingEmailAndPassword extends AuthState {} -/// A state that indicates that a new user account was created. -class UserCreated extends AuthState { - /// A [fba.UserCredential] that was obtained during authentication process. - final fba.UserCredential credential; - - UserCreated(this.credential); -} - /// A state that indicates that user registration is in progress. /// UIs often reflect this state with a loading indicator. class SigningUp extends AuthState {}