首页 文章

删除本地用户时从firebase获取旧数据

提问于
浏览
-3

我正在使用电子邮件密码登录的Android应用程序 . 用户是在本地sqlite数据库和firebase身份验证中创建的 .

Situation :用户卸载应用程序,删除本地数据库 . 然后用户重新安装应用程序并希望使用旧凭据登录,但用户不在本地存在,因此应用程序尝试创建新的 . - 但用户已在我的firebase用户表auth中存在远程 .

Question :我如何使用电子邮件,传递以及可能的一些额外内容查询 firebase authfirebase 以获取用户信息 .

我发现的大多数答案都是指使用来自firebase的更新事件,但此时由于用户尚未通过身份验证,因此无法实现

2 回答

  • 0

    我自己解决了 .

    这很简单,完全没有 . 我的修复的一部分在下面 . 但总之 . 我从firebase获取用户,然后对firebase进行更新,然后在addValueEventListener中恢复用户(new ValueEventListener()

    _fbAuth.signInWithEmailAndPassword(_email, _password).addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
        if (task.isSuccessful()) {
    
            Log.d(TAG, "Firebase login success");
    
            FirebaseUser fbUser = _fbAuth.getCurrentUser();
            String uid = fbUser.getUid();
    
            FireBaseWriteHelper wh = new FireBaseWriteHelper();
            FireBaseReadHelper fireBaseReadHelper = new FireBaseReadHelper(getApplicationContext(), uid, Util.VERSION_KEY_FREE);
    
            DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
            Date date = new Date();
            wh.UpdateUserLastLogIn(uid, format.format(date));
    
            _user = _userHelper.CheckUserExist(_email, _password);
    
            mPasswordView.setError(null);
            mEmailView.setError(null);
    
        } else {
            try {
                throw task.getException();
            } catch (FirebaseAuthInvalidUserException e) {
            } catch (FirebaseAuthInvalidCredentialsException e) {
            } catch (FirebaseNetworkException e) {
            } catch (Exception e) {
            }
        }
    }
    });
    
  • 0

    您可以在离线模式下使用Firebase . 您不需要使用两个数据库 .
    指南here .

相关问题