Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

471
Vistas
How Can I Create Custom Auth For Firebase (Kotlin)

I want to add users to Firebase with usernames,p passwords, and emails. I'm using the Email-Password sign-in method but how can I add the username to the database? Here is the basic code that I wrote for the email&password sign-in method:


    fun signup(view:View){
        val email = binding.emailText.text.toString()
        val username = binding.usernameText2.text.toString()
        val password = binding.passwordText2.text.toString()
        if(email.equals("") || username.equals("") || password.equals("")){
            Toast.makeText(this,"Don't Leave them empty!",Toast.LENGTH_LONG).show()
        }else{
            auth.createUserWithEmailAndPassword(email,password).addOnSuccessListener {
                //sucess
                val intent = Intent(this@SignupActivity,FeedsActivity::class.java)
                startActivity(intent)
                finish()
            }.addOnFailureListener {
                //failed
                Toast.makeText(this,it.localizedMessage,Toast.LENGTH_LONG).show()
            }

        }

    }

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

In order to add some data to the database, you have to choose which database you want to use. You can use either Cloud Firestore, or the Realtime Database. Now, since the sign-in operation is asynchronous, the code that writes data to the database should be added inside the callback. That being said, get the data from the FirebaseUser object:

val firebaseUser = FirebaseAuth.getInstance().currentUser
val email = firebaseUser?.email
val displayName = firebaseUser?.displayName
val user = mapOf(
    displayName to displayName,
    email to email
)

And add it to Firestore:

val db = FirebaseFirestore.getInstance()
val usersRef = db.collection("users")
usersRef.document(uid).set(user)

Or in the Realtime Database:

val db = FirebaseDatabase.getInstance().reference
val usersRef = db.child("users")
usersRef.child(uid).setValue(user)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda