gpt4 book ai didi

javascript - 在注册 Firebase 上保存用户的额外详细信息

转载 作者:行者123 更新时间:2023-12-02 06:30:42 25 4
gpt4 key购买 nike

我想保存用户的额外详细信息,即数字、年龄,仅在用户注册时(一次)。但是没有回调来检查注册是否成功。

firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});

所以当你想在用户注册而不是使用时只存储一次数据时该怎么办

firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
} else {
// No user is signed in.
}
});

每次用户登录/注销时都会触发,但我不想每次都保存额外的注册详细信息。

最佳答案

firebase.auth().createUserWithEmailAndPassword($scope.email, $scope.password)
.then(function(user) {
var ref = firebase.database().ref().child("user");
var data = {
email: $scope.email,
password: $scope.password,
firstName: $scope.firstName,
lastName: $scope.lastName,
id:user.uid
}
ref.child(user.uid).set(data).then(function(ref) {//use 'child' and 'set' combination to save data in your own generated key
console.log("Saved");
$location.path('/profile');
}, function(error) {
console.log(error);
});
})
.catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode == 'auth/weak-password') {
alert('The password is too weak.');
} else if (errorCode == 'auth/email-already-in-use') {
alert('The email is already taken.');
} else if (errorCode == 'auth/weak-password') {
alert('Password is weak');
} else {
alert(errorMessage);
}
console.log(error);
});

Here's the result在这里,我将数据保存在“user.uid”键中,该键在用户成功注册后由 firebase 返回。

关于javascript - 在注册 Firebase 上保存用户的额外详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38101572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com