通过Google SSO进行Firebase web身份验证-如何知道用户是注册还是登录



我想检测用户是否刚刚通过SSO注册或只是登录。

文档没有帮助。

我使用的是React+ES6。这是我目前的身份验证方法:

authWithGoogle = () => {
this.props.setIsLoggingInState(true);
firebaseApp
.auth()
.getRedirectResult()
.catch(() => console.error('something went wrong with Google SSO'));
firebaseApp
.auth()
.signInWithRedirect(googleProvider)
.catch(() => console.error('something went wrong with Google SSO'));
};

老实说,上面的代码似乎不对。。。(但它有效(

您可以执行以下操作:

firebaseApp.auth().getRedirectResult().then(function(userCredential) {
// True if the user is new, false if existing.
console.log(userCredential.additionalUserInfo.isNewUser);
}).catch(function(error) {
// Error occurred.
});

最新更新