简体   繁体   English

Firebase displayName返回为NULL

[英]Firebase displayName returns as NULL

I am confused as to why when trying to output the display name it returns as NULL yet when I sign up for an account and console.log the displayName it shows my input? 我感到困惑,为什么当尝试输出显示名称时,它返回为NULL却在我注册帐户和console.log displayName时却显示输入?

I added a new field: 我添加了一个新字段:

<input class="mdl-textfield__input" style="display:inline;width:auto;" type="text" id="displayName" name="displayName" placeholder="displayName"/>

Inside of the firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) { function I did a console.log against displayName and it output when the field where submitted and created the user in the DB, but when outputting the displayName is returns as NULL firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {函数内,我对displayName进行了console.log记录,并在字段在数据库中提交并创建用户时输出,但是当输出displayName返回为NULL

firebase.auth().onAuthStateChanged(function(user) {
        // [START_EXCLUDE silent]
        document.getElementById('quickstart-verify-email').disabled = true;
        // [END_EXCLUDE]
        if (user) {
          // User is signed in.
          var displayName = user.displayName;

Im just doing a simple text output on the users details like so: 我只是在用户详细信息上做一个简单的文本输出,如下所示:

document.getElementById('quickstart-account-details').textContent = JSON.stringify(user, null, '  ');

This is probably because you are executing 这可能是因为您正在执行

document.getElementById('quickstart-account-details').textContent = JSON.stringify(user, null, ' ');

before user is populated. 在填充user之前。

If so, try executing the above code inside the if (user) {} block. 如果是这样,请尝试在if (user) {}块内执行以上代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM