Skip to content

Commit

Permalink
Expose isNewUser boolean. (Closes #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
sam0829 committed Feb 28, 2020
1 parent ee7b74c commit eafec9f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Field | Description |
phoneNumber | Phone number of user |
photoUri | URI of user's photo |
providerId | Indicates through which provider user was authenticated. |
isNewUser | Indicates if user is new |

Please note that above details may be null depending on the provider user used to sign and user's privacy settings on respective provider.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class FirebaseAuthUiPlugin(private val activity: Activity) : MethodCallHandler,
userMap["provider_id"] = user.providerId
userMap["photo_url"] = user.photoUrl?.toString() ?: ""
userMap["is_anonymous"] = user.isAnonymous
userMap["is_new_user"] = response?.isNewUser ?: false

result?.success(userMap)
} else {
Expand Down
4 changes: 3 additions & 1 deletion ios/Classes/SwiftFirebaseAuthUiPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public class SwiftFirebaseAuthUiPlugin: NSObject, FlutterPlugin, FUIAuthDelegate
}
}

public func authUI(_ authUI: FUIAuth, didSignInWith user: User?, error: Error?) {
public func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?) {
let user = authDataResult?.user
if (error != nil) {
if (UInt((error as NSError?)?.code ?? -12) == FUIAuthErrorCode.userCancelledSignIn.rawValue) {
result?(FlutterError(code: ERROR_USER_CANCELLED, message: "User cancelled the sign-in flow",
Expand All @@ -96,6 +97,7 @@ public class SwiftFirebaseAuthUiPlugin: NSObject, FlutterPlugin, FUIAuthDelegate
"photo_url": user?.photoURL?.absoluteString ?? "",
"phone_number": user?.phoneNumber ?? "",
"is_anonymous": user?.isAnonymous ?? false,
"is_new_user": authDataResult?.additionalUserInfo?.isNewUser ?? false,
]
result?(userDisctionary)
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/firebase_auth_ui/firebase_auth_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class FirebaseAuthUi {
userMap["phone_number"] ?? "",
userMap["photo_url"] ?? "",
userMap["provider_id"] ?? "",
isAnonymous: userMap["is_anonymous"] ?? false);
isAnonymous: userMap["is_anonymous"] ?? false,
isNewUser: userMap["is_new_user"]);
}

List<String> _getProviders(List<AuthProvider> providers) {
Expand Down
4 changes: 3 additions & 1 deletion lib/src/firebase_auth_ui/firebase_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ class FirebaseUser {
String photoUri;
String providerId;
bool isAnonymous;
bool isNewUser;

FirebaseUser(this.uid, this.displayName, this.email, this.phoneNumber,
this.photoUri, this.providerId,
{this.isAnonymous = false});
{this.isAnonymous = false, this.isNewUser});

Map<String, dynamic> toJSON() {
return {
Expand All @@ -20,6 +21,7 @@ class FirebaseUser {
"photoUri": photoUri,
"providerId": providerId,
"isAnonymous": isAnonymous,
"isNewUser": isNewUser,
};
}
}

0 comments on commit eafec9f

Please sign in to comment.