[英]How do you add users and additional details to a user node in the Database every time they're registered?
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.
我无法在Google搜索和其他类似内容上大跌眼镜,但是我只找到了不支持的折旧解决方案,该解决方案不适用于当前版本的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);
})()
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. 您应该添加代码以将用户数据(如
uid
作为用户的uid
节点,并将所有其他详细信息作为数据库中该节点的子子节点。
A Json structure that looks something like this: Json结构如下所示:
{
"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 })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.