【问题标题】:How to add username with email and password in realtime while user creation?如何在创建用户时实时添加用户名和电子邮件和密码?
【发布时间】:2019-12-25 05:44:46
【问题描述】:

在创建用户时,我想为该特定 UID 创建一个自定义用户名,并检查该用户名是否被其他人使用。

我尝试过使用updateProfile(),但我认为它不起作用。

      btnSignup.addEventListener('click', e => {
            const email = signupEmail.value;
            const pass = signupPassword.value;
            const userName = signupUsername.value;
              firebase.auth().createUserWithEmailAndPassword(email, pass)
              .then(function () {
                user = firebase.auth().currentUser;
                user.sendEmailVerification();
              })
              .then(function () {
                user.updateProfile({
                  username: userName
                });
              })
              .catch(function(error) {
                console.log(error.message);
              });
              alert('Validation link was sent to ' + email + '.');
      });

注册时,我只想将用户名分配给该特定 UID,而不是其他任何东西(个人资料图片和所有)。

【问题讨论】:

  • 你是在前端还是后端使用那个代码?
  • 我在前端使用该代码。
  • 您需要将用户传递给 then 回调,您没有这样做,因此它不起作用

标签: firebase firebase-realtime-database google-cloud-firestore firebase-authentication


【解决方案1】:
let user;
firebase.auth().createUserWithEmailAndPassword(email, pass)
              .then(function () {
                user = firebase.auth().currentUser;
                user.sendEmailVerification();
              })
              .then(function () {
                user.updateProfile({
                  username: userName
                });
              })
              .catch(function(error) {
                console.log(error.message);
              });

这可能会对你有所帮助。

【讨论】:

    猜你喜欢
    • 2013-01-18
    • 2021-07-25
    • 1970-01-01
    • 2020-10-08
    • 1970-01-01
    • 2019-07-10
    • 1970-01-01
    • 2016-11-18
    • 2017-09-16
    相关资源
    最近更新 更多