【发布时间】:2018-11-17 12:31:40
【问题描述】:
我正在开发一个 Ionic 应用程序,除其他事项外,该应用程序应分配一个相应的数据库条目,其密钥与他们在注册时获得的用户生成的 UID 相同。另外需要注意的是,用户自己不能创建帐户 - 只有单个管理员可以。
这是我当前的代码。
addUserToDb(username: string, email: string, password: string) {
this.firebaseAuth.auth.createUserWithEmailAndPassword(email, password).then(data => {
var newId = data.user.uid; // Gets UID of new user.
const usersRef = this.db.list('users'); // Gets list to be pushed to
let keyToChange = usersRef.push(
{
admin: false,
identifier: data.user.email,
username: username,
}).key; // Does the push AND gets the key for the newly added entry
console.log(`User's old id is ` + keyToChange + " | User's new id will be " + newId);
var userToUpdate = this.db.object('users/' + keyToChange); // Gets entry to be edited
userToUpdate.update({[keyToChange]: newId}); // <- WHAT DO I DO HERE?
console.log('Success!', username);
})
.catch(err => {
username: null;
email: null;
password: null;
console.log('Something went wrong:', err.message);
});
}
现在,代码导致了这个结果:
我该如何解决这个问题?谢谢!
【问题讨论】:
标签: javascript ionic-framework firebase-realtime-database nosql angularfire