I want the user to get a specified amount (500) of money (int) once they get registered into the system with Firebase Auth. The email (with a , instead of a .) is taken from the input of the user which will be the userid (child) in realtime database. And the money should be the child of userid.
I tried it with my writeNewUserMoney
method:
realtime database
I tried it with my writeNewUserMoney
method:
public void writeNewUserMoney() {
String email = encodeUserEmail(signupEmail.getText().toString().trim());
mDatabaseReference = FirebaseDatabase.getInstance().getReference();
mDatabaseReference.child("user").child(email).setValue(500);
}
Here is encodeUserEmail
:
static String encodeUserEmail(String userEmail) {
return userEmail.replace(".", ",");
}
Here is the relevant part of the class:
@Override
public void onClick(View view) {
String user = signupEmail.getText().toString().trim();
String pass = signupPassword.getText().toString().trim();
if (user.isEmpty()){
signupEmail.setError("Email eingeben");
}
if (pass.isEmpty()){
signupPassword.setError("Passwort eingeben");
} else{
auth.createUserWithEmailAndPassword(user, pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(SignUpActivity.this, "SignUp Successful", Toast.LENGTH_SHORT).show();
startActivity(new Intent(SignUpActivity.this, LoginActivity.class));
} else {
Toast.makeText(SignUpActivity.this, "SignUp Failed" + task.getException().getMessage(), Toast.LENGTH_LONG).show();
}
}
});
}
//
FirebaseAuth auth = FirebaseAuth.getInstance();
FirebaseUser kuser = auth.getCurrentUser();
//bestätigungs mail
kuser.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
System.out.println("Email sent");
}
}
});
//bestätigungs mail
//Kontoinstandsetzung
writeNewUserMoney();
}
The database doesn't change when initiating an onClick. I already tried this : Fail to Write data to Firebase Realtime Database Android
If you know any other methods to assign a value in realtime database after the or with reg without the user seeing it, feel free to comment.