当用户被签名并重新签名时,Firestore听众停止聆听
最小可重复的代码
@override
void initState() {
super.initState();
final col = FirebaseFirestore.instance.collection('foo');
col.doc('bar').snapshots().listen((event) {
print('Data = ${event.data()}');
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
ElevatedButton(
onPressed: () => FirebaseAuth.instance.signInAnonymously(),
child: Text('Sign in'),
),
ElevatedButton(
onPressed: () => FirebaseAuth.instance.signOut(),
child: Text('Sign out'),
),
],
),
);
}
我的安全规则是:
allow read, write: if request.auth != null;
当我再次登录并再次登录时,我的听众停止聆听。这是设计吗?每次都有一个签名活动时,我是否应该再次设置听众?
Minimum reproducible code
@override
void initState() {
super.initState();
final col = FirebaseFirestore.instance.collection('foo');
col.doc('bar').snapshots().listen((event) {
print('Data = ${event.data()}');
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
ElevatedButton(
onPressed: () => FirebaseAuth.instance.signInAnonymously(),
child: Text('Sign in'),
),
ElevatedButton(
onPressed: () => FirebaseAuth.instance.signOut(),
child: Text('Sign out'),
),
],
),
);
}
My security rules are:
allow read, write: if request.auth != null;
When I sign out and sign in again, my listener stops listening. Is this by design? Should I again setup my listener each time there's a sign out event?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您看到的是预期的行为。
由于您的安全规则要求在用户中签名以读取数据,因此签名当前用户取消了任何现有的侦听器(因为它们不再满足要求)。
一旦完成登录,您将必须(重新)为听众附加侦听器。
Yes, what you're seeing is the expected behavior.
Since your security rules require that there is a signed in user to read the data, signing out the current user cancels any existing listeners (as they no longer meet the requirement).
You will have to (re)attach listeners for the new user once their sign in is completed.