Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

470
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda