[英]How to interact with Firebase user after API call?
I perform API call with Retrofit2 to login user via Firebase Authentication with email and password and after that need to interact somehow with user object, ie refresh some data or check if user logged in on next time application starts (I'm getting a correct Json object).我使用 Retrofit2 执行 API 调用以使用电子邮件和密码通过 Firebase 身份验证登录用户,然后需要以某种方式与用户对象进行交互,即刷新一些数据或检查用户是否在下次应用程序启动时登录(我得到了正确的 Json目的)。
But after API call checking FirebaseAuth
object mAuth.getCurrentUser()
gives null
and have no idea how to save login state inside my app.但是在 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();
}
});
How to retrieve FirebaseUser
correctly?如何正确检索
FirebaseUser
?
Thanks.谢谢。
If you're using the Firebase Auth REST API to sign in a user, you can't also use the Firebase Auth SDK to manage that sign-in.如果您使用 Firebase Auth REST API 登录用户,则不能同时使用 Firebase Auth SDK 管理该登录。 You will have to stick to using the REST API for all management.
您必须坚持使用 REST API 进行所有管理。 This means that you'll have to track the ID token that you get from the API, refresh the token every hour before it expires, and maintain your own sense of what it means for the user to be "signed in".
这意味着您必须跟踪从 API 获得的 ID 令牌,在令牌过期前每小时刷新一次,并保持自己对用户“登录”意味着什么的认识。
I highly suggest just using the provided SDK, as it will do all of this for you automatically.我强烈建议只使用提供的 SDK,因为它会自动为您完成所有这些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.