【问题标题】:Firebase displayName return nullFirebase 显示名称返回 null
【发布时间】:2020-07-10 11:52:06
【问题描述】:

当我使用 gooogle 或 facebook 注册时,我可以在控制台中看到我的 displayName。但是当我使用电子邮件和密码注册时,我在控制台中看不到 displayName,它返回 null。但有趣部分是它在 firebase 数据库中设置了显示名称但无法检索。

class SignUp extends React.Component {
constructor(){
    super();
    this.state = {
        displayName:"",
        email:"",
        password:"",
        confirmPassword: ""
        }
}
// HandleChange function
handleChange = event => {
    const {value, name} = event.target;
    this.setState({[name]:value})
}
//HandleSubmit function
handleSubmit = async event => {
    event.preventDefault();
    const {displayName, email, password, confirmPassword} = this.state;
    if(password !== confirmPassword) {
        alert("Passwords don't match ")
        return;
    }
    try {
        // firebase speacial function for email and password signins
        const {user} = await auth.createUserWithEmailAndPassword(email,password);
        await createUserProfileDocument(user, {displayName, password});
        
        //clearing out the form after submit
        this.setState({
            displayName:"",
            email:"",
            password:"",
            confirmPassword: ""
        })
    } catch (error) {
        alert(error.message)
    }
}
render(){

【问题讨论】:

标签: javascript reactjs firebase firebase-authentication


【解决方案1】:

Firebase 身份验证中的新电子邮件/密码帐户未设置显示名称。如果您想在创建帐户后添加一个,则必须update the profile as described in the documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    • 2021-09-28
    • 2020-01-26
    • 1970-01-01
    • 2020-03-02
    • 1970-01-01
    相关资源
    最近更新 更多