error with updating user information firebase - java

so i am creating a sign up page and connect that with firebase users
i am recieving error with updating profile
my code goes as follow:
for creating new user i use
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Log.v("SignUp", "222222222222222222222222222");
Toast.makeText(SignUp.this, "SignUp failed",
Toast.LENGTH_SHORT).show();
} else {
Log.v("SignUp", "333333333333333333333333333");
uploadImage();
}
}
});
and the uploadImage() method is
public void uploadImage() {
if (image != null) {
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference main = storage.getReferenceFromUrl("link to my account");
StorageReference storageReference = main.child("images/" + image.getLastPathSegment());
UploadTask uploadTask = storageReference.putFile(image);
//addonFailurelistener too
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.v("SignUp", "777777777777777777777777");
String download = taskSnapshot.getDownloadUrl().toString();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.build();
//i tried here with .setDisplayName(name)
//and with setPhotoUri(Uri.parse(download)
FirebaseAuth.getInstance().getCurrentUser().updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.v("SignUp", "8888888888888888888888888888");
addDatabase();
} else {
FirebaseAuth.getInstance().getCurrentUser().delete().addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.v("SignUp", "999999999999999999999999999");
Toast.makeText(SignUp.this, "Error Occuered While setting your account", Toast.LENGTH_LONG);
finish();
startActivity(new Intent(SignUp.this, SignUp.class));
} else {
Log.v("SignUp", "..........................");
Toast.makeText(SignUp.this, "Error Cannot be resolved \n please try with another Email", Toast.LENGTH_LONG);
finish();
}
}
});
}
}
});
}
});
}
and my logcat get output like that
V/SignUp: 333333333333333333333333333
V/SignUp: 777777777777777777777777
V/SignUp: ..........................
i followed the firebase guide but looks like i am doing something wrong
any idea why it doesnt work? thanks

i get it automatically resolved after waiting for 24 hours so i am assuming account get blocked for 24h after some number of logIn in a single day

Related

Link two tables in firebase using Id in android studio using Java

have a problem, I'm working on a university project, I have two tables in firebase, the gallery table that contains the photos of the itinerary and the itinerary table that contains the various itineraries of the users now I have to make sure that the id of the itinerary and the ID of the image so as to have a photo corresponding to each itinerary ì, also created by the same user. I did so:
public void addImageItinerary() {
storageReference = FirebaseStorage.getInstance().getReference();
referenceDb = FirebaseDatabase.getInstance().getReference();
firestore = FirebaseFirestore.getInstance();
auth = FirebaseAuth.getInstance();
if (images != null) {
StorageReference itineraryRef = storageReference.child("itinerary_image/" + FirebaseAuth.getInstance().getCurrentUser().getUid() + ".jpg");
itineraryRef.putFile(images).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
#Override
public void onComplete(#NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful()) {
itineraryRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
String itineraryId = referenceDb.child("Itinerary").push().getKey();
Log.i("itineraryId", itineraryId);
HashMap<String, Object> map = new HashMap<>();
map.put("image", uri.toString());
referenceDb.child("Gallery").child(FirebaseAuth.getInstance().getCurrentUser().getUid()+ "/" + itineraryId).setValue(map).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
// APRO SCHERMATA MAPPA
// openMapFragment();
Toast.makeText(insertImage_fragment.getActivity(), "ok", Toast.LENGTH_SHORT).show();
} else {
//ERRORE
Toast.makeText(insertImage_fragment.getActivity(), "Operation failed. Please try again", Toast.LENGTH_SHORT).show();
}
}
});
}
});
} else {
Toast.makeText(insertImage_fragment.getActivity(), task.getException().toString(), Toast.LENGTH_SHORT).show();
}
}
});
} else{
Toast.makeText(insertImage_fragment.getActivity(),"Please add image", Toast.LENGTH_SHORT).show();
}
}
enter image description here

Firebase android studio not inserting data correctly

This is the data being inserted the the correct one is the yay#gmail.com while the incorrectly inserted ones are the ones with a:Name
mAuth.createUserWithEmailAndPassword(email, pass)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()) {
Teachers teachers = new Teachers(user, pass, email);
FirebaseDatabase.getInstance().getReference("Teachers")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(teachers).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if(task.isSuccessful()) {
Toast.makeText(RegisterTeacher.this, "Teacher has been registered!", Toast.LENGTH_SHORT).show();
Intent i = new Intent(RegisterTeacher.this, TeacherLogin.class);
startActivity(i);
}
else {
Toast.makeText(RegisterTeacher.this, "Failed to register!", Toast.LENGTH_SHORT).show();
}
}
});
} else {
Toast.makeText(RegisterTeacher.this, "Failed to register! Try again!", Toast.LENGTH_SHORT).show();
}
}
});

realtime Database in firebase doesn't save data

realtime Database in firebase doesn't save data and doesn't show any errors
i have already set
"rules": {
".read": "true",
".write": "true"
}
and this is the function it create new user and it's created in firebase but the user name and email doesn't save in realtime database
public void createUser(String email, String password, String userName) {
auth = FirebaseAuth.getInstance();
auth.createUserWithEmailAndPassword(email, password).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(getContext(), "user created", Toast.LENGTH_SHORT).show();
User user = new User(email, userName);
FirebaseDatabase.getInstance().getReference().child("Users")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(getContext(), "user info added", Toast.LENGTH_SHORT).show();
}
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
});
}
and this line is appere as toast i don't know how it is happen
Toast.makeText(getContext(), "user info added", Toast.LENGTH_SHORT).show()

E/StorageException: Unable to obtain an upload URL

I don't know why I'm getting this exception E/StorageException: Unable to obtain an upload URL whenever it gets to uploading file/image onto Firebase Storage. It's also returning W/NetworkRequest: error sending network request error. Although I don't experience any internet connectivity problems. I've also tried running this with another device but it results in the same thing.
firebaseAuth.createUserWithEmailAndPassword(inputEmail, inputPassword).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
firebaseAuth.getCurrentUser().sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull final Task<Void> task) {
final String uID = firebaseAuth.getCurrentUser().getUid();
if (task.isSuccessful()) {
storageReference = FirebaseStorage.getInstance().getReference("image").child(uID); // for image uploads
storageReference.putFile(image_uri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
//image uri is taken care of in the onActivityResult method.
member.setImage_url(taskSnapshot.getUploadSessionUri().toString());
member.setEmail(email.getText().toString().trim());
member.setFname(fname.getText().toString().trim());
member.setLname(lname.getText().toString().trim());
df = FirebaseDatabase.getInstance().getReference("Member").child(uID); //points to the address
df.setValue(member).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
startActivity(new Intent(Register.this, Login.class));
Toast.makeText(Register.this, "Registered successfully, please verify your email.", Toast.LENGTH_LONG).show();
}
});
RprogressBar.setVisibility(View.INVISIBLE);
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(Register.this, e.getMessage(), Toast.LENGTH_LONG).show();
RprogressBar.setVisibility(View.INVISIBLE);
}
});
} else {
Toast.makeText(Register.this, task.getException().getMessage(), Toast.LENGTH_LONG).show();
RprogressBar.setVisibility(View.INVISIBLE);
}
}
});
} else {
Toast.makeText(Register.this, task.getException().getMessage(), Toast.LENGTH_LONG).show();
RprogressBar.setVisibility(View.INVISIBLE);
}
I still only have the slightest idea of what is happening but I've seen some other answers from a similar post and they suggested using VPN I'm currently in the Philippines so if anyone is having a similar problem try using VPN.

need help creating user in firebase auth

im working on a project with firebase, and i have some problems creating users.
there is my code:
private void createAccount(String email, String password) {
Log.d(TAG, "createAccount:" + email);
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "createUserWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
}
else {
Log.w(TAG, "createUserWithEmail:failure", task.getException());
Toast.makeText(getApplicationContext(), "Authentication failed.", Toast.LENGTH_SHORT).show();
}
}
});
}

Categories