我正在使用 firestore 编写一个有角度的应用程序。我正在调用 Auth::createUserWithEmailAndPassword( 来注册用户并调用 Auth::signInWithEmailAndPassword。在这两种情况下,用户都会登录并触发以下订阅this.afa.authState.subscribe( authState => { this.firebaseUser = authState; if (authState) { this.onLoginSuccessfulReceivedFromFirebase(); } else { this.onLogout(); } this.isLoggedIn = authState != null;});有没有办法让我确定回调是否在 createUserWithEmailAndPassword 期间自动登录或在回调函数中专门调用 Auth::signInWithEmailAndPassword 时被触发
2 回答

翻翻过去那场雪
TA贡献2065条经验 获得超14个赞
以不同方式响应帐户创建的最简单方法是等待createUserWithEmailAndPassword解决的承诺。
firebase.auth().createUserWithEmailAndPassword(email, password).then(function(credential) {
console.log(credential.user.uid);
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
添加回答
举报
0/150
提交
取消