Я хочу, чтобы пользователи могли видеть только свои собственные данные. Поэтому я не хочу, чтобы пользователи видели данные друг друга. Я просто хочу, чтобы каждый пользователь видел свои добавленные данные. Я думаю, что мне нужно изменить правила Firebase Cloud Strore, и я думаю, что для этого userId должен быть равен documentId. Но как мне это сделать?
Я новичок в этом, спасибо!
Правила Cloud Firestore;
service cloud.firestore {
match /databases/{database}/documents {
// Allow only authenticated content owners access
match /Notes/{userId}/{documents=**} {
allow read, write: if request.auth != null && request.auth.uid ==userId
}
}
}

и я сохраняю useremail, noteTitle... и т.д. в базу данных, как я поделился ;
val noteMapElse = hashMapOf()
noteMapElse.put("userEmail", auth.currentUser!!.email.toString())
noteMapElse.put("noteTitle", titleText.text.toString())
noteMapElse.put("yourNote", noteText.text.toString())
noteMapElse.put("date", Timestamp.now())
//UUID -> Image Name
val uuid = UUID.randomUUID()
val imageName = "$uuid.jpg"
val storage = FirebaseStorage.getInstance()
val reference = storage.reference
val imagesReference = reference.child("images").child(imageName)
imagesReference.putFile(selectedPicture!!).addOnSuccessListener { taskSnapshot ->
// take the picture link to save the database
val uploadedPictureReference =
FirebaseStorage.getInstance().reference.child("images").child(imageName)
uploadedPictureReference.downloadUrl.addOnSuccessListener { uri ->
val downloadUrl = uri.toString()
println(downloadUrl)
noteMapElse.put("downloadUrl", downloadUrl)
db.collection("Notes").add(noteMapElse).addOnCompleteListener { task ->
if (task.isComplete && task.isSuccessful) {
finish()
}
}.addOnFailureListener { exception ->
Toast.makeText(
applicationContext,
exception.localizedMessage?.toString(),
Toast.LENGTH_LONG
).show()
}
}
}
}
Это также мои действия по входу и регистрации;
fun signIn (view: View) {
auth.signInWithEmailAndPassword(mailText.text.toString(), passwordText.text.toString())
.addOnCompleteListener { task ->
if (task.isSuccessful) {
Toast.makeText(applicationContext, "Welcome : ${auth.currentUser?.email.toString()}",
Toast.LENGTH_LONG).show()
val intent = Intent(applicationContext, ListViewActivity::class.java)
startActivity(intent)
finish()
}
}.addOnFailureListener { exception ->
Toast.makeText(
applicationContext,
exception.localizedMessage?.toString(),
Toast.LENGTH_LONG
).show()
}
}
fun signUp (view: View) {
val email = mailText.text.toString()
val password = passwordText.text.toString()
auth.createUserWithEmailAndPassword(email,password).addOnCompleteListener {
if (it.isSuccessful) {
Toast.makeText(applicationContext, "Your Account Has Been Created Successfully", Toast.LENGTH_LONG).show()
val intent = Intent(applicationContext, ListViewActivity::class.java)
startActivity(intent)
finish()
}
}.addOnFailureListener { exception ->
if (exception != null ) {
Toast.makeText(applicationContext,exception.localizedMessage.toString(),Toast.LENGTH_LONG).show()
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/647 ... -firestore