Using flutter http://flutter.io,我已经安装了firebase 身份验证 https://pub.dartlang.org/packages/firebase_auth and 火库 https://pub.dartlang.org/packages/cloud_firestore只要我对用户没有任何规则,我就能够使用 firebase auth 进行身份验证并调用 firestore。
我有一个可以调用的按钮_handleEmailSignIn
我确实得到了一个有效的用户(因为他们位于 Firebase Auth DB 中)
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
final FirebaseAuth _auth = FirebaseAuth.instance;
void _handleEmailSignIn(String email, String password) async {
try {
FirebaseUser user = await _auth.signInWithEmailAndPassword(
email: email, password: password);
print("Email Signed in " + user.uid); // THIS works
} catch (err) {
print("ERROR CAUGHT: " + err.toString());
}
}
然后,我有另一个按钮调用此函数来尝试将记录添加到testing123
收藏。
Future<Null> _helloWorld() async {
try {
await Firestore.instance
.collection('testing123')
.document()
.setData(<String, String>{'message': 'Hello world!'});
print('_initRecord2 DONE');
} catch (err) {
print("ERROR CAUGHT: " + err.toString());
}
}
现在,只要我没有任何关于检查请求用户的规则,这就可以工作。这有效...
service cloud.firestore {
match /databases/{database}/documents {
match /testing123auth/{doc} {
allow read, create
}
}
}
这并不给出PERMISSION_DENIED: Missing or insufficient permissions.
当我想确保我拥有经过身份验证的用户时_handleEmailSignIn
.
service cloud.firestore {
match /databases/{database}/documents {
match /testing123auth/{doc} {
allow read, create: if request.auth != null;
}
}
}
我怀疑 firestore 请求不包括 firebase 用户。我的意思是配置 firestore 以包含用户还是这应该作为 firebase 的一部分自动进行?