【问题标题】:How to get UID and add user information with Firebase email/password authentication如何使用 Firebase 电子邮件/密码身份验证获取 UID 和添加用户信息
【发布时间】:2017-01-03 06:56:18
【问题描述】:

我正在使用 firebase 电子邮件/密码身份验证进行注册和登录。但是在注册过程中,我想获取用户 UID 并使用它在 firebase 中创建一个新数据库,其中包含其他用户信息,例如姓名和电话号码.我知道通过登录过程更容易获得 UID,但是如果注册成功,有没有办法通过注册来做到这一点。我正在使用安卓工作室。

【问题讨论】:

  • 您尝试过什么了吗?因为这个话题已经讨论过几次了。例如here 或可能有不少items in this list

标签: android firebase firebase-realtime-database firebase-authentication


【解决方案1】:

可以从完成监听返回的任务中获取用户信息:

    mAuth.createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());

                    if (task.isSuccessful()) {
                        FirebaseUser user = task.getResult().getUser();
                        Log.d(TAG, "onComplete: uid=" + user.getUid());
                    }
                }
            });

【讨论】:

  • 我在文档中看到了这个,我已经尝试过使用。但是我收到了 firebase.auth not found 的错误。我之前遇到过这个错误,我修复了它,所以想知道为什么它又出现了。
  • @PaulMpanga:你能发布错误吗?代码为我成功运行。
  • 成功了,我的 User 类写得很奇怪。谢谢!!
  • 我可以在task.isSuccessful 内的数据库中添加userid 吗? if 中的示例,请执行此操作newStudent.child("uid").setValue(mCurrentUser.getUid());newStudent 是一个 DatabaseReference 会起作用吗?
  • @PeterHaddad:是的
猜你喜欢
  • 2017-04-30
  • 2016-02-11
  • 2019-05-01
  • 1970-01-01
  • 2019-01-27
  • 2019-06-11
  • 1970-01-01
  • 2021-11-21
相关资源
最近更新 更多