Reputation: 63
I am trying to update the user profile of users of app I am building. The users information is stored in firebase, the app is coded in dart running on android.
I have tried implementing example from https://firebase.google.com/docs/auth/web/manage-users website.
51 createUser() {
52 if (checkFields()) {
53 //Perform Login
54 var user = FirebaseAuth.instance.currentUser();
55 FirebaseAuth.instance
56 .createUserWithEmailAndPassword(email: _email, password: _password)
57 .then((user) {
58 var userUpdateInfo = new UserUpdateInfo();
59 user.updateProfile(userUpdateInfo)
.then((user) {
60 userUpdateInfo.displayName = _Firstname;
61 FirebaseAuth.instance
.currentUser()
.then((user) {
UserManagement().storeNewuser(user, context);
62 })
.catchError((e) {print(e);});
63 })
.catchError((e) {
64 print(e);
65 });
66 //UserManagement().storeNewuser(user, context);
67 Navigator.of(context).pop();
68 Navigator.of(context)
.pushReplacementNamed('/landingpage');
69 })
.catchError((e) {
70 print("ivlvvliyviv");
71 });
72 }
73 }
The app runs smoothly without does not crushing but when the user updates the firstname but it is not changed on firebase, line 60 was suppose to update the firstname field on firebase, and this is where I am adding my firstname field
Firestore.instance
.collection('/users')
.add({
'email': user.email,
'uid': user.uid,
'firstname': user.firstname,
Upvotes: 2
Views: 1321
Reputation: 51206
In Order to Update Firebase User
- displayName
. You need to make few changes in your Code.
Make - var userUpdateInfo = new UserUpdateInfo();
state variable outside your .then
Function. & then Call user.updateProfile
.
or
Edit Your Create User code As Below:
FirebaseAuth.instance.createUserWithEmailAndPassword(email: _email, password: _password)
.then((user) {
var userUpdateInfo = new UserUpdateInfo();
userUpdateInfo.displayName = _Firstname; // Pass the value you want as displayName
user.updateProfile(userUpdateInfo).then((val){ // will Update the User at Firebase Auth
print('User Display Name Updated.');
});
});
Upvotes: 1