FireBaseUI Auth-如何知道帐户是来自新注册用户还是现有用户? [英] FireBaseUI Auth - how to know if account is from a new signup or existing user?
问题描述
我正在使用 firebaseUI进行身份验证.实际上,它会打开一个外部活动,然后将用户登录到Firebase,然后在onActivityResult中向开发人员发送回电.它的工作原理很好,问题是我需要知道用户是新注册用户还是现有用户.是否有任何一种元数据或我可以用来了解这一点的东西?这是我到目前为止在JAVA ANDROID中所拥有的:
I am using firebaseUI for authentication. it essentially opens a a external activity and logs the user into firebase and sends the developer a call back in onActivityResult. It works great the problem is i need to know if the user is a new signup or an existing user. is there any kind of metadata or something i can use to know this ? here is what i have so far IN JAVA ANDROID:
private void ititFireBaseUi() {
AuthUI.getInstance()
.signOut(getActivity())
.addOnCompleteListener(new OnCompleteListener<Void>() {
public void onComplete(@NonNull Task<Void> task) {
// Choose authentication providers
List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build());
//new AuthUI.IdpConfig.Builder(AuthUI.TWITTER_PROVIDER).build());
// Create and launch sign-in intent
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.setLogo(R.drawable.logo)
.build(),
RC_SIGN_IN);
}
});
}
,然后显示结果:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
IdpResponse response = IdpResponse.fromResultIntent(data);
//I WOULD LIKE TO KNOW HERE IF THE USER IS A NEW USER OR EXISTING USER
String msg = "";
if (resultCode == RESULT_OK) {
// Successfully signed in
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
msg = "generating token with email:" + user.getEmail();
Timber.d(msg);
Toast.makeText(getActivity(), msg, Toast.LENGTH_LONG).show();
presenter.generateTokenWithFireBase(user);
// ...
} else {
// Sign in failed, check response for error code
}
}
}
}
我看到了元类那也许可以帮助我,但我不知道如何使用它.
I see a meta class that maybe can help me but i dont know how to use it.
gradle:实现'com.firebaseui:firebase-ui-auth:3.2.2'
gradle : implementation 'com.firebaseui:firebase-ui-auth:3.2.2'
推荐答案
请勿使用创建和登录时间戳比较.我发现它不可靠.
Do not use the creation and sign in timestamp comparison. I found it to be unreliable.
IdpResponse
具有 isNewUser()
方法,用于告诉您登录名是否是新帐户.
IdpResponse
has a isNewUser()
method to tell you whether the login is a new account or not.
这篇关于FireBaseUI Auth-如何知道帐户是来自新注册用户还是现有用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!