How to create username, address and data using firebase validation
I know how to create email and password authentication with firebase, but this will only create the email and id, but how can I add the name and more details to that id, like how do I call user.getdisplayname?
Here is my code for creating email and password authentication
bv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final ProgressDialog pros=ProgressDialog.show(Register.this,"please wait..","registerring..",true);
mAuth.createUserWithEmailAndPassword(email.getText().toString(),password.getText().toString()).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
pros.dismiss();
if(task.isSuccessful()){
Toast.makeText(Register.this,"sucsseful",Toast.LENGTH_LONG).show();
Intent i=new Intent(Register.this,login.class);
}else {
Log.e("ERROr",task.getException().toString());
Toast.makeText(Register.this,task.getException().getMessage(),Toast.LENGTH_LONG).show();
}
}
});
If you are also talking about creating a database, then how do I link it to user authentication?
private FirebaseUser UserDetaill = FirebaseAuth.getInstance().getCurrentUser() ;
+3
source to share
1 answer
You can use UserProfileChangeRequest
like this
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName("XXX YYYY")
.setPhotoUri(URI)
.build();
UserDetaill.updateProfile(profileUpdates);
USING TASKS
FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, password)
.continueWithTask(new Continuation<AuthResult, Task<? extends Object>>() {
@Override
public Task<? extends Object> then(@NonNull Task<AuthResult> task) throws Exception {
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName("XXX YYYY")
.setPhotoUri(URI)
.build();
return task.getResult().getUser().updateProfile(profileUpdates);
}
});
+2
source to share