I'm trying to create a child using the user's ID. I found the ID when I created a user here and got the userID in the logcat:
final String fullName = findViewByid(R.id.fullName);
.
. // Other strings declared here
.
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser newUserID = mAuth.getCurrentUser();
userID = newUserID.getUid();
Log.w(TAG, "AuthenticationComplete:true //id:" + userID);
Checked the logcat, seen the userID variable. Checked the auth console, and got "authentication complete:true //id:userid".
This is where the problem comes in.
public void onComplete(@NonNull Task<AuthResult> task) {
.
.
.
});
Log.w(TAG, "AuthenticationComplete:true //id:" + userID);
BasicUser newUser = new BasicUser(fullName, uname, userEmail, password, confirmPassword, city, newState, zip, type);
Log.w(TAG, "idcheck:" + userID);
**reference.child(userID).setValue(newUser);**
I checked my logcat again, I got "authentication complete:true //id:userid" "idcheck: null".
Things I've tried:
- Changing the child to uname (another String variable). Data was posted into real time database as intended
- Putting "" "" around userID. Not sure what I thought it was going to do but it was worth a shot
- Placing all strings and bottom code in onComplete method
I had it working before but not exactly sure how, so I know it's possible. TIA!
UPDATE:
I made the variables global and not final. It's working as expected now.
public class(){
String fullName;
public void signUp(){
public void onComplete(@NonNull Task<AuthResult> task) {
});
Log.w(TAG, "AuthenticationComplete:true //id:" + userID);
BasicUser newUser = new BasicUser(fullName, uname, userEmail, password, confirmPassword, city, newState, zip, type);
Log.w(TAG, "idcheck:" + userID);
reference.child(userID).setValue(newUser);