【发布时间】:2017-07-04 03:25:27
【问题描述】:
在我的项目中,只有管理员可以将用户添加到 firebase。 在创建时,我想获取用户 ID,因为我想在 Firebase 数据库中设置该用户的个人资料。
public void addNewFaculty(View view){
String name,email,password,rePassword;
name = txtname.getText().toString();
email = txtEmail.getText().toString().trim();
password = txtPassword.getText().toString().trim();
rePassword = txtRepassword.getText().toString().trim();
if(password.equals(rePassword))
{
Toast.makeText(this, "Password is not match", Toast.LENGTH_SHORT).show();
return;
}
databaseReference= FirebaseDatabase.getInstance().getReference();
firebaseUser = firebaseAuth.getCurrentUser();
String id= firebaseUser.getUid();
databaseReference = databaseReference.child("Profile").child(id);
databaseReference.child("Name").setValue(name);
// and some other things
firebaseAuth.createUserWithEmailAndPassword(email,password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(getApplicationContext(), "Employee Added Successfully", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "Please try Again", Toast.LENGTH_SHORT).show();
}
}
});
}
我的火力基地结构是 我的firebase结构如下。我想在创建用户时获取用户 ID Here is my Firebase Auth Image
【问题讨论】:
标签: android firebase-realtime-database firebase-authentication