Firebase身份验证和实时数据库链接

时间:2020-07-06 10:31:59

标签: android firebase firebase-realtime-database firebase-authentication

我已经为Firebase中的用户创建了一个数据库,并且能够在我的应用程序中注册并在数据库中查看他们。是否可以将其链接到Firebase提供的登录身份验证?我可以使用它来登录用户,然后将其他注册详细信息添加到该个人资料ID吗? 这是我的注册用户方法,应该让它来照顾用户还是应该使用Firebase身份验证?有没有办法将两者联系起来?

public void registerUser(View view) {
    //If any of the validations do not pass return will be called and errors will be shown
    if (!validateName() | !validatePassword() | !validatePhoneNo() | !validateEmail() | !validateDOB() | !validateContactName() | !validateContactPhoneNo()) {
        return;
    }
    //Get an instance of the firebase database
    rootNode = FirebaseDatabase.getInstance();
    //Define the reference in the database that should be called
    reference = rootNode.getReference("users");
    //Tag for printing log details
    Log.d(TAG, "Firebase contacted");


//Get all the values from the text fields
String name = regName.getEditText().getText().toString();
String email = regEmail.getEditText().getText().toString();
String phoneNo = regPhoneNo.getEditText().getText().toString();

//Method to get a readable day/month/year from the Datepicker
int day = regDOB.getDayOfMonth();
int month = regDOB.getMonth() + 1;
int year = regDOB.getYear();

@SuppressLint("SimpleDateFormat") SimpleDateFormat dateFormatter = new SimpleDateFormat("MM-dd-yy");
Date date = new Date(year, month, day);
String stringDate = dateFormatter.format(date);
String dob = stringDate;

String emergencyContact = regContact.getEditText().getText().toString();
String contactNumber = regContactPhone.getEditText().getText().toString();
String password = regPassword.getEditText().getText().toString();
//Get the details from our UserHelperClass
UserHelperClass helperClass = new UserHelperClass(name, email, phoneNo, dob, emergencyContact, contactNumber, password);
Log.d(TAG, "Helper class worked");

//Use phoneNo as the unique identifier, this will be set as the first listing of the user
reference.child(phoneNo).setValue(helperClass);
Log.d(TAG, "Completed Method");

1 个答案:

答案 0 :(得分:0)

找到了一个不错的youtube视频来回答这个问题

https://www.youtube.com/watch?v=7Yc3Pt37coM