1
votes

Very new to Firestore and can't seem to fix the problem I have. I am registering the user with the phone, then prompt the user to edit data in app. However, I am encountering the error, and don't know how to fix it.

The error:

I/flutter ( 7502): [firebase_storage/unauthenticated] User is unauthenticated. Authenticate and try again.

W/Firestore( 7502): (23.0.3) [WriteStream]: (b2291d0) Stream closed with status: Status{code=NOT_FOUND, description=No document to update:

projects/blahblah/databases/(default)/documents/users/CrxXOi8vajhUYfevbPbMRjAHQqrv5, cause=null}.

E/flutter ( 7502): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)]

Unhandled Exception: [cloud_firestore/not-found] Some requested document was not found.

Authentication works fine, as I see the user with the uid in users. However, not in the Firestore collection 'Users'. My rules are very simple:

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {

match /users/{id} {
allow read, delete, update, create: if request.auth != null;
}}}

My storage rules are set to:

 rules_version = '2';
  service firebase.storage {
   match /b/{bucket}/o {
     match /{allPaths=**} {
      allow read, write: if request.auth != null;
     }}

edit profile method is:

  String currentUid() {
 return firebaseAuth.currentUser.uid;
 }

 updateProfile(
  {File image,
  String username,
  String email,
  String sex,
  String dob,
  String phone}) async {
DocumentSnapshot doc = await usersRef.doc(currentUid()).get();
var users = UserModel.fromJson(doc.data());
users.username = username;
users.email = email;
users.phone = phone;
users.dob = dob;
users.sex = sex;

if (image != null) {
  users.photoUrl = await uploadImage(profilePic, image);
}
await usersRef.doc(currentUid()).update(
    {'username': username, 'photoUrl': users.photoUrl, 'phone': phone,
      'dob': dob, 'email': email, 'sex': sex});
return true;
}

Help appreciated very much!

2

2 Answers

0
votes

Your error is coming from Storage, not FireStore. Go to storage and edit the rules there.

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}
0
votes

I finally learned that enforcing the AppCheck storage access was not recommended this early in development. Unenforced the AppCheck for storage and it worked! Will be watching their videos from now on!