douxiong3245 2018-10-19 23:00
浏览 85
已采纳

每次注册时,如何将用户和其他详细信息添加到数据库中的用户节点?

I've tried to create the code by using what I've found online about adding additional details to a user node, but I've come up without a clear cut and definite solution. I can't make heads or tails with Google searches and other such things, but I only found a depreciated solution that's not supported and does not work with the current version of Firebase. So far, here's what I've come up with:

(function(){
  var ref = new firebase.database();
  ref.onAuth(function(authData) {
    if (authData && isNewUser) {
      // save the user's profile into Firebase so we can list users,
      // use them in Security and Firebase Rules, and show profiles
      ref.child("users").child(authData.uid).set({
        provider: authData.provider,
        name: getName(authData)
      });
    }
  });
    var ui = new firebaseui.auth.AuthUI(firebase.auth());
    var uiConfig = {
        callbacks: {
          signInSuccessWithAuthResult: function(authResult, redirectUrl) {
            // User successfully signed in.
            // Return type determines whether we continue the redirect automatically
            // or whether we leave that to developer to handle.
            return true;
          },
          uiShown: function() {
            // The widget is rendered.
            // Hide the loader.
            document.getElementById('loader').style.display = 'none';
          }
        },
        // Will use popup for IDP Providers sign-in flow instead of the default, redirect.
        signInFlow: 'popup',
        signInSuccessUrl: 'map_menu.php',
        signInOptions: [
          firebase.auth.EmailAuthProvider.PROVIDER_ID,
        ],
        // Terms of service url.
        tosUrl: 'map_menu.php',
        // Privacy policy url.
        privacyPolicyUrl: 'map_menu.php'
      };

      ui.start('#firebaseui-auth-container', uiConfig);
})()
  • 写回答

1条回答 默认 最新

  • dousao9569 2018-10-20 06:07
    关注

    You should add a code to get the user data like uid as the main child of the user and all other details as sub child nodes of this node in your database.

    A Json structure that looks something like this:

    {
          "accounts" : {
            "userId value" : {
              "email" : "",
              "userId" : ""
            },
            "userId value" : {
              "email" : "",
              "userId" : ""
            }
          }
    

    To save the users' details in this node, just when they are registered, you can add a code like this:

    var uid = firebase.auth().currentUser.uid;
    firebase.database().ref().child('accounts').child(uid).set({
      email: user.email,
      userId: uid
    })

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备