【发布时间】:2020-09-25 21:25:15
【问题描述】:
我正在运行以下 firebase 代码
FirebaseApp app = await FirebaseApp.configure(
name: 'weather app',
options: const FirebaseOptions(
googleAppID: '1:nnnnnnnnn:android:nnnnnnn',
apiKey: 'XXXXXXXX',
projectID: 'XXXXX-XXX-XXX08',
),
);
Firestore firestore = Firestore(app: app);
FirebaseAuth.fromApp(app).signInAnonymously();
如果我第一次在模拟器中运行这段代码,它会抛出以下错误
I/flutter (17766): getConfigState ERROR 2 PlatformException(Error performing get, PERMISSION_DENIED: Missing or insufficient permissions., null)
W/Firestore(17766): (21.3.0) [Firestore]: Listen for Query(weather-api-info/owm) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
但是,如果我只是使用热重载或完全重载来重新加载应用程序,那么它不会抱怨。同样,仅当应用程序在设备上首次运行时才会出现此问题(我可以通过卸载应用程序并重试来重现此问题)
Cloud Firestore 身份验证如下所示(我不打算设置任何登录或身份验证,但也不想保持打开状态
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
【问题讨论】:
-
您的安全规则要求用户在查询时登录。
-
那个@DougStevenson,有没有办法让我保持访问关闭但没有登录,或者如何以管理员身份登录..?另外,为什么相同的代码第二次运行没有抱怨?
-
无法将 Firestore 查询仅限于您的应用。您必须使用 Firebase 身份验证来限制访问。
-
@KenWhite 刚刚完成,点击保存按钮,太快了……
-
@DougStevenson 谢谢,但是,如果我第二次使用 hotreload 重新加载代码,同样的代码可以工作..**输出**
I/flutter (17766): getConfigState from firebase https://community-open-weather-map.p.rapidapi.com/weather/
标签: firebase flutter google-cloud-firestore firebase-security