Reputation: 123
I know how to create email and password authentication with firebase but that will create only email and id but how do i add name and more detail to that id for instance how I call user.getdisplayname?
Here is my code for creating authentication email and password
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 say to create database as well, then how I link it to the user authentication?
private FirebaseUser UserDetaill = FirebaseAuth.getInstance().getCurrentUser() ;
Upvotes: 3
Views: 495
Reputation: 5339
You can use the 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);
}
});
Upvotes: 2