简体   繁体   English

如何在createUserWithEmailAndPassword(web)之后设置用户数据

[英]How to set user data after createUserWithEmailAndPassword (web)

I have search on other questions but I can't find anything, so I'm sorry if this is a duplicated. 我已经搜索了其他问题,但我找不到任何东西,所以如果这是重复的话,我很抱歉。

I'm trying to save extra user data on sign up to database, the signup is not a problem but I can't store the data, I'm trying this: 我正在尝试在注册到数据库时保存额外的用户数据,注册不是问题,但我无法存储数据,我正在尝试这样做:

//add a real time listener
   firebase.auth().onAuthStateChanged(firebaseUser =>{



    if (user != null) {


      firebase.database().ref().child( firebaseUser.uid ).set( {
        /**store data**/
      } );

    console.log("Sign-in provider: "+ firebaseUser.providerId);
    console.log("Provider-specific UID: "+ firebaseUser.uid);
    console.log("name: "+firebaseUser.name);
    console.log("email: "+firebaseUser.email);
    console.log("country:"+firebaseUser.country);
     //console.log("  Photo URL: "+firebaseUser.photoURL);



    //window.location.href = "index.html";


     }else{
      console.log('not logged in');

     }
});

You can store any of the properties of the Firebase User . 您可以存储Firebase用户的任何属性。 This should work: 这应该工作:

firebase.database().ref().child( firebaseUser.uid ).set( {
    firebaseUser.displayName,
    lastSignInTimestamp: Date.now()
});

If that doesn't work, your user might not have permission to write to the location in the database. 如果这不起作用,则您的用户可能没有权限写入数据库中的位置。 To troubleshoot that, attach an error listener: 要解决此问题,请附加错误侦听器:

firebase.database().ref().child( firebaseUser.uid ).set( {
    firebaseUser.displayName,
    lastSignInTimestamp: Date.now()
}.catch(function(error) {
    console.error(error);
});

If indeed it's a security problem, see the first blue note in the Firebase documentation about writing data to the database . 如果确实存在安全问题,请参阅Firebase文档中有关将数据写入数据库的第一个蓝色注释。

暂无
暂无

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

相关问题 Firebase 使用 createUserWithEmailAndPassword 后看不到用户 - Firebase cannot see user after using createUserWithEmailAndPassword createUserWithEmailAndPassword之后无法使用collection.set - Unable to use collection.set after createUserWithEmailAndPassword 如何使用 auth().createUserWithEmailAndPassword 接收用户名和国家/地区 - How to receive user name and country with auth().createUserWithEmailAndPassword 如何在 createUserWithEmailAndPassword 上取消 onAuthStateChanged - how to cancel onAuthStateChanged on createUserWithEmailAndPassword Firebase createUserWithEmailAndPassword未在登录时授权用户 - Firebase createUserWithEmailAndPassword not authorizing user on sign in 如何侦听由 firebase createUserWithEmailAndPassword 创建的用户已写入 firebase 数据库? - How to listen that a user created by firebase createUserWithEmailAndPassword has been written to the firebase database? 在javascript和firebase中使用“ createUserWithEmailAndPassword(电子邮件,密码)”时如何获取用户ID - How to take user Id when using “createUserWithEmailAndPassword(email, password)” in javascript and firebase createUserWithEmailAndPassword VUEJS 更新用户配置文件时出错 - createUserWithEmailAndPassword VUEJS error updating user profile 在 createUserWithEmailAndPassword 失败后 Nuxt firebase 编写文档 - Nuxt firebase write doc after createUserWithEmailAndPassword fail 从 web 工作人员获取数据后无法将数据设置到剪贴板 - Cannot set data to clipboard after getting data from web worker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM