Home Kotlin Firebase UserAuthentication need assistance
Reply: 0

Kotlin Firebase UserAuthentication need assistance

user2483
1#
user2483 Published in June 18, 2018, 8:45 pm

Hey Guys Im trying to push the user data in kotlin to firebase but when i click the create account button nothing happends here is the code for Create account class

class CreateAccount : AppCompatActivity() {
var mAuth:FirebaseAuth?=null
var mdata:DatabaseReference?=null


override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_create_account)
    mAuth= FirebaseAuth.getInstance()
    Createacc.setOnClickListener{
        var email=acemail.text.toString().trim()
        var pass=acpass.text.toString().trim()
        var name=acname.text.toString().trim()

        if(!TextUtils.isEmpty(email)||!TextUtils.isEmpty(name)||!TextUtils.isEmpty(pass)){
            createAccount(email,pass,name)
        }
        else{
            Toast.makeText(this,"Please fill all the details",Toast.LENGTH_LONG).show()
        }
    }
}

fun createAccount(email: String,password:String,dispname:String){

    mAuth!!.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this,{
          task: Task<AuthResult> ->
        if(task.isSuccessful){
            var curruser=mAuth!!.currentUser
            var userid=curruser!!.uid
            Toast.makeText(this,"Building user wait",Toast.LENGTH_LONG).show()
            var uobject=HashMap<String,String>()
            uobject.put("Display_name",dispname)
            uobject.put("Status","Hi I'm New")
            uobject.put("image","default")
            uobject.put("thumb image","default")

            mdata=FirebaseDatabase.getInstance().reference.child("Users").child(userid)
            mdata!!.setValue(uobject).addOnCompleteListener{
                task:Task<Void>  ->
                if(task.isSuccessful){
                    Toast.makeText(this,"User Created",Toast.LENGTH_LONG).show()
                }
                else{
                    Toast.makeText(this,"OOPS!! User not Created",Toast.LENGTH_LONG).show()
                }
            }
        }
    })
}

} Main problem is in create account function ,it is being called correctly but right after the createUserWithEmailAndPassword function the task is not successfull hence the if loop does not run. There nothing is printed in the toast Neither "User created " nor "OOPS not created" i dont know whats going on. I have installed the firebase dependency and my app is connected to a firebase database.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.319992 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO