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);
}
问题是,使用这种方法,我只能保存用户的电子邮件地址,而不能保存他/她的名字。
请告诉我如何在电子邮件中保存姓名。
提前致谢。
答案 0 :(得分:1)
您通常希望在/ users节点中存储任何其他用户信息。
喜欢这个
uid
name: "Ted"
fav_movie "Airplane"
position: "Sitting front facing forward"
uid是您在Firebase中创建用户时创建的用户ID。
这是Firebase中非常常见的设计模式,在User Authentication指南中有一个非常棒的例子。
您希望查看“存储用户数据”部分中的大约1/2路。