failed: DatabaseError: Permission denied Firebase the user is being created but database is not updating

依然范特西╮ 提交于 2021-01-28 13:46:43

问题


This is account create activity : Here the user is being created but the unless i change the rules to read write rules to true the database is not getting updated.

I only want the users database who is authorized. Please help

class CreateAccountActivity : AppCompatActivity() {

    var mAuth: FirebaseAuth? = null
    var mDatabase: DatabaseReference? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_create_account)

        mAuth = FirebaseAuth.getInstance();

        idbuttonsignup.setOnClickListener{
            var email = idemail.text.toString().trim()
            var password = idpassword.text.toString().trim()
            var displayName = iddisplayname.text.toString().trim()

            if(!TextUtils.isEmpty(email) || !TextUtils.isEmpty(password) || !TextUtils.isEmpty(displayName)){
                createAccount(email,password,displayName)
            }else{
                Toast.makeText(this,"Please fill out all the fields", Toast.LENGTH_LONG).show()
            }
        }


    }



    private fun createAccount(email: String, password: String, displayName: String){
        mAuth!!.createUserWithEmailAndPassword(email,password)
            .addOnCompleteListener{
                    task: Task<AuthResult> ->

                if(task.isSuccessful){
                    var currentUserID = mAuth!!.currentUser
                    var userID = currentUserID!!.uid
                    Toast.makeText(this,"Task is sucessfull", Toast.LENGTH_LONG).show()
                    mDatabase = FirebaseDatabase.getInstance().reference.child("Users").child(userID)
                    var userObject = HashMap<String, String>()
                    userObject.put("display_name",displayName)
                    userObject.put("status", "Hello there...")
                    userObject.put("image", "default")
                    userObject.put("thumb_image","default")

                    mDatabase!!.setValue(userObject).addOnCompleteListener{
                            task: Task<Void> ->
                        if(task.isSuccessful){
                            var dashboardIntentOkc = Intent(this, DashboardActivity::class.java)
                            dashboardIntentOkc.putExtra( "name", displayName)
                            startActivity(dashboardIntentOkc)
                            finish()
                            Toast.makeText(this,"User Created", Toast.LENGTH_LONG).show()
                        }else{
                            Toast.makeText(this,"User Not Created", Toast.LENGTH_LONG).show()
                        }
                    }


                }
            }
    }

}

_______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ please help


回答1:


Have you define the rules in the Firebase Database for read and write operations. Check the Firebase official page if not.

Get Started with Database Rules



来源:https://stackoverflow.com/questions/62254482/failed-databaseerror-permission-denied-firebase-the-user-is-being-created-but

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!