我使用Retrofit2执行API调用以使用电子邮件和密码通过Firebase身份验证登录用户,然后需要以某种方式与用户对象进行交互,即刷新一些数据或检查用户是否在下次应用程序启动时登录(我得到了正确的Json目的)。
但是在API调用检查FirebaseAuth
对象mAuth.getCurrentUser()
给出之后,却不null
知道如何在我的应用程序中保存登录状态。
NetworkService.getInstance().getJsonApi()
.loginWithEmail(email, password, true)
.enqueue(new Callback<Transaction.Result>() {
@Override
public void onResponse(Call<Transaction.Result> call, Response<Transaction.Result> response) {
if (response.code() == 200) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
activity.updateUI(user);
activity.startService();
} else {
Log.d(TAG, "signInWithEmail:failure");
activity.showToast("Authentication failed.");
activity.updateUI(null);
}
activity.hideProgressBar();
}
@Override
public void onFailure(Call<Transaction.Result> call, Throwable t) {
t.printStackTrace();
}
});
如何FirebaseUser
正确检索?
谢谢。
如果您使用Firebase Auth REST API登录用户,则也不能使用Firebase Auth SDK来管理该登录。您将必须坚持使用REST API进行所有管理。这意味着您必须跟踪从API获得的ID令牌,在令牌过期之前每小时刷新一次,并保持自己对用户“登录”意味着什么的感觉。
我强烈建议您仅使用提供的SDK,因为它将自动为您完成所有这些工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句