是什么导致FIREBASE和FLUTTER发出“权限被拒绝"消息 [英] what causes "permission denied"-message with FIREBASE and FLUTTER
问题描述
我遇到了错误
"W/SyncTree(31625):在/address处侦听失败:DatabaseError:权限被拒绝"
'W/SyncTree(31625): Listen at /address failed: DatabaseError: Permission denied'
,同时使用匿名Firebase用户向Firebase发送请求,并且没有花哨的Firebase数据库规则:). ..我想找出导致此消息的原因.
while sending a request to firebase with an anonymous firebase user and without fancy firebase database rules :) . ..and i want to find out what causes this message.
错误与现有用户相同,这意味着用户登录似乎有效,但无法访问数据库.
error is the same with an existing user, means user signIn seems to work but accessing database not.
我到目前为止所做的事情:
- 设置Firebase(包括添加google_service.json,pubspec.yaml中的依赖项)-到目前为止可以正常运行
-
按以下方式创建登录名(例如Google的示例链接):
Future<String> _testSignInAnonymously() async {
final FirebaseUser user = await _auth.signInAnonymously();
assert(user != null);
assert(user.isAnonymous);
assert(!user.isEmailVerified);
assert(await user.getIdToken() != null);
assert(user.providerData.length == 1);
assert(user.providerData[0].providerId == 'firebase');
assert(user.providerData[0].uid != null);
assert(user.providerData[0].displayName != null);
assert(user.providerData[0].photoUrl == null);
assert(user.providerData[0].email != null);
final FirebaseUser currentUser = await _auth.currentUser();
print(currentUser.uid);
print(currentUser.isAnonymous);
assert(user.uid == currentUser.uid);
return 'signInAnonymously succeeded: $user';
}
print语句提供了一个userId(并且此id也位于firebase auth部分中)->在我看来,我已经登录了用户
the print statement provides a userId (and this id is also in firebase auth section) --> seems to me that i've got an logged in user
实现类似于Google示例中的初始化方式(链接):
implement kind of initialization like in the google example (link):
Future<void> main() async {
final FirebaseApp app = await FirebaseApp.configure(
name: 'mydbName',
options: const FirebaseOptions(
googleAppID: 'myAppId',
apiKey: 'myApiKey',
databaseURL: 'myUrl',
),
);
runApp(new MyApp(app));
}
在另一个有状态的状态小部件上,我尝试请求一些Firebase数据:
on another stateful widget in state i try to request some firebase data:
void initState() {
final FirebaseDatabase database = new FirebaseDatabase(app: widget.app);
database.reference().child('address').once().then((DataSnapshot snapshot) {
print('Connected to database and read ${snapshot.value}');
});
super.initState();
}
我已删除了Firebase中的所有规则,除了:
i've removed all rules in firebase except:
".read": "auth != null",
".write": "auth != null",
我在firebase android app
我需要什么:
我需要一些提示,以了解该初始化代码或用户登录名或其他任何问题
I need some hint how to find out if there's any problem with that initialization code or with the user login or something else
推荐答案
在FirebaseApp.configure(
FirebaseDatabase.instance.reference().child(...)
将使用在google-services.json
这篇关于是什么导致FIREBASE和FLUTTER发出“权限被拒绝"消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!