【问题标题】:How to fix 'user unauthenticated' firebase storage when authenticating with phone使用手机进行身份验证时如何修复“用户未经身份验证”的 Firebase 存储
【发布时间】:2021-10-29 13:10:46
【问题描述】:

对 Firestore 非常陌生,似乎无法解决我遇到的问题。我正在用手机注册用户,然后提示用户在应用程序中编辑数据。但是,我遇到了错误,不知道如何解决。

错误:

I/flutter (7502): [firebase_storage/unauthenticated] 用户未经身份验证。验证并重试。

W/Firestore(7502): (23.0.3) [WriteStream]: (b2291d0) 流已关闭,状态为:Status{code=NOT_FOUND, description=No document to update:

projects/blahblah/databases/(默认)/documents/users/CrxXOi8vajhUYfevbPbMRjAHQqrv5, cause=null}。

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

未处理的异常:[cloud_firestore/not-found] 未找到某些请求的文档。

身份验证工作正常,因为我在 users 中看到具有 uid 的用户。但是,不在 Firestore 集合“用户”中。我的规则很简单:

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

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

我的存储规则设置为:

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

编辑配置文件方法是:

  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;
}

帮助非常感谢!

【问题讨论】:

    标签: flutter authentication google-cloud-firestore firebase-storage


    【解决方案1】:

    我找到了有关此问题的解决方案。 pub 获取 firebase_app_check: ^0.0.3 这个包。 并简单地调用这个应用程序检查类-

    await FirebaseAppCheck.instance.activate();
    

    对于我的场景,我以这种方式解决了这个问题。

    【讨论】:

      【解决方案2】:

      我终于了解到,在开发初期不建议强制执行 AppCheck 存储访问。未强制执行 AppCheck 进行存储,它工作正常!从现在开始将观看他们的视频!

      【讨论】:

      • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
      【解决方案3】:

      您的错误来自Storage,而不是FireStore。 转到存储并在那里编辑规则。

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

      【讨论】:

      • 您好! @Huthaifa 它们的设置与您在此处发布的完全一样。
      猜你喜欢
      • 1970-01-01
      • 2020-12-04
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 2017-03-11
      • 2015-09-23
      • 1970-01-01
      • 2021-07-30
      相关资源
      最近更新 更多