我有一个防火墙应用程序连接到monaca和OnsenUI。我正在尝试创建一个用户并将他们登录到相同的操作中。我可以成功地创建一个用户,,但是我无法登录。
auth/user-not-found 和
There is no user record corresponding to this identifier. The User may have been deleted我确认新用户在db...Here中是我注册和签名的代码。
//signup function stuff
var login = function() {
console.log('got to login stuff');
var email = document.getElementById('username').value;
var password = document.getElementById('password').value;
//firebases authentication code
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log('User did not sign up correctly');
console.log(errorCode);
console.console.log(errorMessage);
});
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
console.log(error.code);
console.log(error.message);
});
fn.load('home.html');
};发布于 2016-08-30 14:31:57
你的流动中有一种所谓的种族状况。
当您调用createUserWithEmailAndPassword() Firebase时,启动,创建用户帐户。但是这可能需要一些时间,所以浏览器中的代码继续执行。
它立即在signInWithEmailAndPassword()中继续进行。由于Firebase可能仍在创建用户帐户,此调用将失败。
在这种情况下,通常的解决方案是将调用链接在一起,例如使用then()。
firebase.auth().createUserWithEmailAndPassword(email, password).then(function(user) {
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
console.log(error.code);
console.log(error.message);
});
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log('User did not sign up correctly');
console.log(errorCode);
console.console.log(errorMessage);
});但是正如AndréKool已经评论过的:创建一个用户已经自动注册了,所以在本例中,您可以这样做:
firebase.auth().createUserWithEmailAndPassword(email, password).then(function(user) {
// User is created and signed in, do whatever is needed
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log('User did not sign up correctly');
console.log(errorCode);
console.console.log(errorMessage);
});当他们到达您的页面时,您可能很快也想要检测用户是否已签名。。为此,您将使用onAuthStateChanged。从医生那里:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
} else {
// No user is signed in.
}
});发布于 2020-11-06 13:52:00
异步/等待工作也是如此。
(async () => {
try {
const result = await auth().createUserWithEmailAndPassword(email, password).signInWithEmailAndPassword(email, password);
console.log(result);
} catch (error) {
console.error(error);
}
})()https://stackoverflow.com/questions/39229014
复制相似问题