【发布时间】:2021-05-01 08:24:29
【问题描述】:
我需要使用 Firebase 电话身份验证检测和区分两个用户。这应该在授予进入应用家庭活动的权限之前完成。当我按照here (Stackoverflow) 的建议进行操作时,它通过使用timeStamp() 方法检测用户做得很好。答案是它的工作,但奇怪的是在发送验证码之前我需要新用户的一些数据输入。
为了发送验证码,用户提供一个直接在firebase 中验证的号码。因此我无法检查它是new user(电话号码)还是current user(电话号码)。
这是使用 TimeStamp() 方法的代码。
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential)
{
_firebaseAuth.signInWithCredential(credential).addOnCompleteListener(Objects.requireNonNull(getActivity()), task ->
{
if(task.isSuccessful())
{
//Sign in success, update UI with the signed-in user's information.
FirebaseUser _user = Objects.requireNonNull(task.getResult()).getUser();
long creationTimestamp = Objects.requireNonNull(Objects.requireNonNull(_user).getMetadata()).getCreationTimestamp();
long lastLoginTimestamp = Objects.requireNonNull(Objects.requireNonNull(_user).getMetadata()).getLastSignInTimestamp();
if(creationTimestamp == lastLoginTimestamp)
{
//Create a new user with account
setUserDataToDatabase(_user, _username, _university, _course, _year);
sendUserToWelcome();
}
else
{
//User exists, just login
sendUserToHome();
}
}
else
{
FancyToast.makeText(getContext(), "Enter sent code", FancyToast.LENGTH_SHORT, FancyToast.INFO, false).show();
}
});
}
【问题讨论】:
标签: android firebase-authentication