保持用户登录 Fireauth

huangapple 未分类评论44阅读模式
英文:

Keep user logged in Fireauth

问题

所以我有一个问题,我的用户在应用程序关闭时(而不是最小化时)会被注销。有没有办法阻止这种情况发生,这样用户在每次关闭应用程序时都不需要登录?我禁用了setIsSmartLockEnabled,因为用户自动登录有点让人讨厌,比如说另一个用户需要登录到应用程序,那么问题就出现了。

以下是一些代码:

List<AuthUI.IdpConfig> providers = Arrays.asList(
        new AuthUI.IdpConfig.EmailBuilder().build(),
        new AuthUI.IdpConfig.FacebookBuilder().build());
startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().setLogo(R.drawable.menolonely).setAvailableProviders(providers)
        .setIsSmartLockEnabled(false).build(), RC_SIGN_IN);


@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        if (resultCode == RESULT_OK) {
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            if (user != null) {

            // 用户相关操作在这里

            } else {
                Log.d(TAG, "登录错误");
                finish();
            }
        }
    }
}
英文:

So I have this problem that my user gets logged out when the app is closed, not minimized. Is there a way to stop this from happening, so the user dosen't have to login every time he/she closes the app? I disabled setIsSmartLockEnabled, because it's a bit anoying that the user automatically gets signed in, because lets say another user need to login to the app, then the problem appears.

Here is some code:

List&lt;AuthUI.IdpConfig&gt; providers = Arrays.asList(
        new AuthUI.IdpConfig.EmailBuilder().build(),
        new AuthUI.IdpConfig.FacebookBuilder().build());
startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().setLogo(R.drawable.menolonely).setAvailableProviders(providers)
        .setIsSmartLockEnabled(false).build(), RC_SIGN_IN);


@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        if (resultCode == RESULT_OK) {
            FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
            if (user != null) {

            //user.... stuff here

            } else {
            Log.d(TAG, &quot;Error on login&quot;);
            finish();
        }
    }
}

huangapple
  • 本文由 发表于 2020年5月4日 06:52:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/61582680.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定