Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

469
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!