Skip to content

Commit

Permalink
fix(ui_auth): emit UserCreated state when signed in user is new (#10225)
Browse files Browse the repository at this point in the history
  • Loading branch information
lesnitsky authored Jan 10, 2023
1 parent 443418f commit a2ce410
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/firebase_ui_auth/lib/firebase_ui_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export 'src/auth_state.dart'
CredentialReceived,
SignedIn,
SigningIn,
UserCreated,
AuthFailed,
DifferentSignInMethodsFound,
MFARequired;
Expand Down
6 changes: 5 additions & 1 deletion packages/firebase_ui_auth/lib/src/auth_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ class AuthFlow<T extends AuthProvider> extends ValueNotifier<AuthState>

@override
void onSignedIn(UserCredential credential) {
value = SignedIn(credential.user);
if (credential.additionalUserInfo?.isNewUser ?? false) {
value = UserCreated(credential);
} else {
value = SignedIn(credential.user);
}
}

@override
Expand Down
10 changes: 9 additions & 1 deletion packages/firebase_ui_auth/lib/src/auth_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 0 additions & 8 deletions packages/firebase_ui_auth/lib/src/flows/email_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down

0 comments on commit a2ce410

Please sign in to comment.