【发布时间】: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