skip to Main Content

When you create user using firebase auth on flutter, you able to set email and password while creating user. I also need to set display name while creating user, but i found only way to set display name after creating user.

I used code like this

FirebaseAuth.instance.
    createUserWithEmailAndPassword(
  email: eMail.text.trim(),
  password: passWord.text.trim(),
)
    .then((uC){
  uC.user!
      .updateDisplayName(userName.text.trim());
}

But this isn’t what I need

2

Answers


  1. yes, you can use fireStore to add user detail to firebase after SignUp is successful.

    Future<bool> signUp(String name,String email,String phone,String password,BuildContext context) async {
        try{
    
          //loading dialog starts
          showLoadingDialog(context);
          UserCredential credential = await _auth.createUserWithEmailAndPassword(email: email, password: password);
    
          //if user creation is success, create a user model
          if(credential.user == null) return false;
          UserModel user = UserModel(
            uId: credential.user!.uid.toString(),
            name: name,
            email: credential.user!.email.toString(),
            phone: phone,
          );
    
          //and upload user model to firebase
          await _fireStore.collection('users').doc(credential.user!.uid).set(user.toMap()).then((value){
            showSnackBar(context, "Sign Up Successful!");
          });
          return true;
        }on FirebaseAuthException catch(exception){
          showSnackBar(context, getMessageFromErrorCode(exception.code));
          return false;
        }finally{
          //pops loading dialog
          Navigator.pop(context);
        }
      }
    
    Login or Signup to reply.
  2. With the Flutter (and other client-side SDKs) it will always require an extra API call to set the display name of the user.

    If creating the user and setting their display name atomically is a requirement for you app, consider using the Admin SDK in a trusted environment (such as your development machine, a server that you control, or Cloud Functions/Cloud Run) to perform that action atomically, creating an endpoint for your this, and then calling that from your app.

    Also see:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search