[英]failed: DatabaseError: Permission denied Firebase the user is being created but database is not updating
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.这是帐户创建活动:这里正在创建用户,但除非我将规则更改为读写规则为 true,否则数据库不会更新。
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 _______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ 请帮忙
Have you define the rules in the Firebase Database for read and write operations.您是否在 Firebase 数据库中定义了读写操作的规则。 Check the Firebase official page if not.如果没有,请查看 Firebase 官方页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.