//create user
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(SignupActivity.this, new OnCompleteListener < AuthResult > () {
@Override
public void onComplete(@NonNull Task < AuthResult > task) {
Toast.makeText(SignupActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Toast.makeText(SignupActivity.this, "Authentication failed." + task.getException(),
Toast.LENGTH_SHORT).show();
} else {
String user_id = auth.getCurrentUser().getUid();
DatabaseReference current_user_db = _Database.child(user_id);
current_user_db.child("name").setValue(name);
current_user_db.child("image").setValue("default");
startActivity(new Intent(SignupActivity.this, ProfileActivity.class));
finish();
}
}
});
}
});
3 回答
电子邮件,显示名称和ID(特定于身份验证系统)等值可在Firebase User object之外使用 . 您可以从FIRAuth class获取对当前登录用户的引用 . 我为iOS提供了链接和类名,但其他平台的结构相似 .
如果要为用户存储其他数据,我建议使用
users
根节点,使用Firebase用户对象的uid
off作为users
子节点的键 .这不是一个安全问题,而只是您对待个人信息的方式 . 您可以在firebase中存储您想要的内容,这样您就可以在用户登录他/她的头像URL(也就是facebook url)或者只是id或任何其他信息时轻松存储,然后检索它 . 如果您需要检索不在旁边使用您的应用程序的用户的信息,那么您当然也可以通过Facebook sdk轻松获得用户许可 . 照顾自己-