简体   繁体   English

Firebase任务:登录+创建帐户

[英]Firebase Tasks: sign in + create account

My app works with Firebase Authentication. 我的应用程序可与Firebase身份验证一起使用。 And when user starts app I need to add new user in Firebase, but I have 3 state: 当用户启动应用程序时,我需要在Firebase中添加新用户,但是我有3种状态:

  1. There is no account 没有帐号
  2. There is an account, but the user signed out 有一个帐户,但用户已注销
  3. There is an account and the user signed in 有一个帐户,用户已登录

For these 3 states, I must do the next: 对于这3个状态,我必须执行以下操作:

  1. create account in Firebase + log in my Database (at the same time) then sign in Firebase 在Firebase中创建帐户+登录我的数据库(同时),然后登录Firebase
  2. sign in Firebase + log in my Database (at the same time) 登录Firebase +登录我的数据库(同时)
  3. log in my Database 登录我的数据库

How to make the first item correctly using Tasks? 如何使用“任务”正确制作第一项? How to control errors? 如何控制错误?

I determine whether the signed user or not, using: 我使用以下方法确定是否已签名的用户:

mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                user = firebaseAuth.getCurrentUser();
                if (user != null) {
                    // User is signed in
                    firebaseAuthUser = true;
                } else {
                    // User is signed out
                    firebaseAuthUser = false;
                }
            }
        };

You can use FirebaseUI-Android to gracefully handle those situations for you. 您可以使用FirebaseUI-Android为您妥善处理这些情况。 It's really simple to implement! 实现起来真的很简单! Please check it here . 在这里检查。

You can check all FirebaseUI features here 您可以在此处检查所有FirebaseUI功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM