GOOGLE ADS

sábado, 23 de abril de 2022

Registrar usuario usando Firebase Authentication - problema con el registro de usuario

Estoy tratando de crear una aplicación de chat y tengo que registrar usuarios y lo estoy haciendo con Firebase. Una vez que he ingresado todos los datos hago clic en registrarse y me sale el mensaje:

No puedes registrarte con este correo electrónico o contraseña

Entonces no sale bien.

No creo que haya nada malo con el código. Tengo el emulador conectado a internet, he conectado firebase a la app, no se si debo revisar otras cosas.

Importé este proyecto de github. ¿Tal vez hice algo mal en el proceso? ¿Puedes explicar qué pude haber hecho mal?

Error en registro:

E/Auth: No se puede crear el usuario

com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: la dirección de correo electrónico tiene un formato incorrecto.

en com.google.android.gms.internal.firebase-auth api.zzti.zza(com.google.firebase:firebase-auth@@21.0.3:28)

 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Register");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
username = findViewById(R.id.username);
email = findViewById(R.id.email);
password = findViewById(R.id.password);
btn_register = findViewById(R.id.btn_register);
firebaseAuth = FirebaseAuth.getInstance();
// When register is clicked check if fields are empty and if password is longer than 6 characters and call register method
btn_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String txt_username = username.getText().toString();
String txt_email = email.getText().toString();
String txt_password = password.getText().toString();
if (TextUtils.isEmpty(txt_username) || TextUtils.isEmpty(txt_email) || TextUtils.isEmpty(txt_password)) {
Toast.makeText(RegisterActivity.this, "All fields are required", Toast.LENGTH_SHORT).show();
}
else if (txt_password.length() < 6) {
Toast.makeText(RegisterActivity.this, "Password must be at least 6 characters", Toast.LENGTH_SHORT).show();
}
else {
register(txt_username, txt_email, txt_password);
}
}
});
}
private void register(final String username, final String email, final String password) {
// If register task is successful add a reference to Users
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
assert firebaseUser!= null;
String userid = firebaseUser.getUid();
reference = FirebaseDatabase.getInstance().getReference("Users").child(userid);
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("id", userid);
hashMap.put("username", username);
hashMap.put("imageURL", "default");
hashMap.put("status", "offline");
hashMap.put("search", username.toLowerCase());
reference.setValue(hashMap).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
}
});
}
else {
Toast.makeText(RegisterActivity.this, "You can't register with this email or password", Toast.LENGTH_SHORT).show();
}
}
});
}


Solución del problema


When a task fails, it contains an exception with details about the cause of the problem. You should log that exception, so that you can find and fix the root cause:

@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
...
}
else {
Log.e("Auth", "Unable to create user", task.getException()); //

No hay comentarios:

Publicar un comentario

Regla de Firestore para acceder a la generación de subcolección Permisos faltantes o insuficientes

Tengo problemas con las reglas de Firestore para permitir el acceso a algunos recursos en una subcolección. Tengo algunos requests document...