The problem that I am having is that when i go to write data to my database when i click save in the application nothing happens. This is the error message that I keep receiving:
"2022-04-21 07:58:45.892016 0100 myDiabetes[73926:7110225] 8.10.0 - [Firebase/Firestore][I-FST000001] Write at usersEvents/HLA3HXIKA1OIGfQXju2exrTkGk82 failed: Missing or insufficient permissions."
I have been trying to change the rules etc. but cant seem to have any luck. I have posted the source code.
class LoggingViewController: UIViewController {
var entryviewcontroller:EntryViewController?
@IBOutlet weak var eventTextBox: UITextField!
@IBOutlet weak var datePicker: UIDatePicker!
@IBOutlet weak var notesTextBox: UITextField!
@IBAction func saveEntryButton(_ sender: Any) {
if entryviewcontroller == nil {
entryviewcontroller = EntryViewController()
}
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy hh:mm a"
entryviewcontroller?.event = self.eventTextBox.text ;
entryviewcontroller?.message = self.notesTextBox.text
entryviewcontroller?.dateAndTime = dateFormatter.string(from: self.datePicker.date)
let db = Firestore.firestore()
guard let uid = Auth.auth().currentUser?.uid else {
return
}
db.collection("usersEvents").document(uid).setData([
"event" : entryviewcontroller!.event! ,
"dateAndTime" : entryviewcontroller!.dateAndTime!,
"message" : entryviewcontroller!.message!]){
err in
if let err = err {
print("Error writing document: \(err)")
return
} else {
print("Document successfully written!")
}
}
func viewDidLoad() {
super.viewDidLoad()
}
}
}
CodePudding user response:
update your rule because your firestore dont allow to read and write after 2022-04-21 that are mention in your rules so replace the line:
allow read, write: if
request.time < timestamp.date(2022, 4, 21);
to:
allow read, write: if request.auth != null;