【问题标题】:How to save user's name along with email in firebase? [duplicate]如何在firebase中保存用户名和电子邮件? [复制]
【发布时间】:2016-03-25 16:33:50
【问题描述】:

Firebase 仅保存用户的电子邮件。我也想保存他/她的名字。

如何做到这一点?

这是我用来创建和登录用户的一些代码:

public void loginByEmailMethod() {
        //creating account
        ref.createUser(email, password, new Firebase.ValueResultHandler<Map<String, Object>>() {
            @Override
            public void onSuccess(Map<String, Object> result) {
                System.out.println("Successfully created user account with uid: " + result.get("uid"));
                Toast.makeText(getBaseContext(), "Account successfully created!", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onError(FirebaseError firebaseError) {
                // there was an error
                Toast.makeText(getBaseContext(), "Account not created!", Toast.LENGTH_LONG).show();
            }
        });

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //logging in the user
                ref.authWithPassword(email, password, new Firebase.AuthResultHandler() {
                    @Override
                    public void onAuthenticated(AuthData authData) {
                        System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());
                        Intent mainActivityIntent = new Intent(SignupScreenActivity.this, MainActivity.class);
                        startActivity(mainActivityIntent);

                        Toast.makeText(getBaseContext(), "User logged in successfully!", Toast.LENGTH_LONG).show();

                    }

                    @Override
                    public void onAuthenticationError(FirebaseError firebaseError) {
                        // there was an error
                        Toast.makeText(getBaseContext(), "User not logged in!", Toast.LENGTH_LONG).show();
                        progressDialog.dismiss();
                    }
                });
            }
        }, 2000);
    }

问题在于,使用这种方法,我只能保存用户的电子邮件地址,而不能保存他/她的姓名。

请告诉我如何将姓名与电子邮件一起保存。

提前致谢。

【问题讨论】:

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


    【解决方案1】:

    您通常希望将任何其他用户信息存储在 /users 节点中。

    这样

    uid
      name: "Ted"
      fav_movie "Airplane"
      position: "Sitting front facing forward"
    

    uid 是您在 Firebase 中创建用户时创建的用户 ID。

    这是 Firebase 中非常常见的设计模式,在他们的 User Authentication 指南中有一个非常棒的示例。

    在“存储用户数据”部分的大约 1/2 处是您要查看的内容。

    【讨论】:

      猜你喜欢
      • 2016-11-18
      • 2018-07-24
      • 2023-03-09
      • 1970-01-01
      • 2018-10-04
      • 2019-10-26
      • 2017-11-20
      • 2022-11-19
      • 2017-09-16
      相关资源
      最近更新 更多