如何将用户名和电子邮件保存在Firebase中? [英] How to save user's name along with email in firebase?

查看:136
本文介绍了如何将用户名和电子邮件保存在Firebase中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



如何达到这个目的?

这里有一些我的我创建并登录到用户的代码:

  public void loginByEmailMethod(){
//创建帐户
ref.createUser(email,password,new Firebase.ValueResultHandler< Map< String,Object>>(){
@Override
public void onSuccess(Map< String,Object> result ){
System.out.println(用uid成功创建用户帐户:+ result.get(uid));
Toast.makeText(getBaseContext(),Account successfully created! ,Toast.LENGTH_LONG).show();
}
$ b $ @覆盖
public void onError(FirebaseError firebaseError){
//出现错误
Toast.makeText(getBaseContext(),Account not created!,Toast.LENGTH_LONG).show();
}
});

Handler handler = new Handler();
handler.postDelayed(new Runnable(){
@Override
public void run(){
//登录用户
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 successfully in!,Toast.LENGTH_LONG).show();


$ b @Override $ b $ public void onAuthenticationError(FirebaseError firebaseError){
//有一个错误
Toast.makeText(getBaseContext(),用户未登录!,Toast.LENGTH_LONG).show();
progressDialog.dismiss();
}
});
}
},2000);





$ b

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



请让我知道如何保存名称和电子邮件。



您通常希望将任何其他用户信息存储在/ users节点中。
$ b $解析方案

b



  uid 
名称:Ted
fav_movie飞机
位置:坐在前面朝前

uid是在创建Firebase中的用户。

这是Firebase中非常常见的设计模式,在其用户认证指南。



存储用户数据部分是您要查看的内容。


Firebase saves only email of the user. I want to save his/her name too.

How to achieve this?

Here's a bit of my code with which I'm creating and logging in the user:

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);
    }

The problem is that with this method I can save only the email address of the user and not his/her name.

Please let me know how can I save name along with the email.

Thanks in advance.

解决方案

You would typically want to store any additional user information in a /users node.

Like this

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

The uid was the user id created when you created the user in Firebase.

This is a very common design pattern in Firebase and there's a super terrific example in their User Authentication guide.

About 1/2 way down in the Storing User Data section is what you want to review.

这篇关于如何将用户名和电子邮件保存在Firebase中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆