2

I have an application where user registration with name,password,email and current address.But i only know how to registration with email and password. Now i need to registration with name,password,email,currentAddress. Is it possible? And what type of difference between difference between create user with email password and Create user with credential in firebase ? I do the following:

final String password = mPassword.getText().toString();

// final String name = mName.getText().toString();


final String email = mEmail.getText().toString();
//final String currentAddress = mCurrentAddress.getText().toString();

mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(DriverLoginActivity.this, new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
        if (!task.isSuccessful()) {
            Toast.makeText(DriverLoginActivity.this, "Signup error", Toast.LENGTH_SHORT).show();
        } else {
            String user_id = mAuth.getCurrentUser().getUid();
            DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child("Users").child("drivers").child(user_id).child("name");
            current_user_db.setValue(email);
        }

    }
});

It's my error report:

java.lang.NullPointerException at com.example.raifu.mapforinto.DriverLoginActivity$2.onClick(DriverLoginActivity.java:60) at android.view.View.performClick(View.java:4438) at android.view.View$PerformClick.run(View.java:18422) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5019)

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Raifur-rahim
  • 543
  • 1
  • 3
  • 12
  • The error message is quite explicit: you have a `NullPointerException` on `DriverLoginActivity.java:60`. Did you check https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it? – Frank van Puffelen Jan 07 '19 at 15:19
  • @Frank van Puffelen I check that but that's hardly related with my problem – Raifur-rahim Jan 08 '19 at 09:20
  • If it's not related to your problem, then don't post it. See [how to create a minimal, complete, verifiable example](http://stackoverflow.com/help/mcve). – Frank van Puffelen Jan 08 '19 at 13:59

2 Answers2

1

The FirebaseUser object created and used for Firebase Authentication only lets you create and access getEmail(), getDisplayName(), getPhotoUrl() and a few other fields that are not relevant to your use. https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser

Unfortunately you cannot add, modify or remove any fields like name, address etc. from the FirebaseUser object.

What you will have to do is create a model class for your specific implementation of User and store it in the Firebase Firestore and keep it synced to the FirebaseUser created and stored in Firebase Authentication.

EDIT1:

You would need to create a User model which in your case may look something like this:

public class User {

private String fullName;
private String emailAddress;
private String currentAddress;
private String phoneNumber;

    public class User {

    private String fullName;
    private String emailAddress;
    private String currentAddress;
    private String phoneNumber;

    public User(String fullName, String emailAddress, String currentAddress, String phoneNumber) {
        this.fullName = fullName;
        this.emailAddress = emailAddress;
        this.currentAddress = currentAddress;
        this.phoneNumber = phoneNumber;
    }

    public String getFullName() {
        return fullName;
    }

    public String getFullName() {
        return fullName;
    }

    public String getFullName() {
        return fullName;
    }

    public String getFullName() {
        return fullName;
    }
}

When registering your user with Firebase Authentication you would create a field in your Firestore database after that with your User class which contains all useful information about the user you want to store.

Here is a detailed video on how to do this whole process (Firebase Authentication with Custom User Fields in Android). https://www.youtube.com/watch?v=7Yc3Pt37coM

drilonrecica
  • 327
  • 1
  • 4
  • 19
1

if you want to register user with lots of informations like name,age,sex,date of birth etc as many has you want is better you use Firebase Database. the firebase user Object is also helpful but it is limited.

Ayodele Kayode
  • 304
  • 4
  • 20