gpt4 book ai didi

ios - Swift:Firebase 读取权限被拒绝

转载 作者:搜寻专家 更新时间:2023-10-31 19:34:49 24 4
gpt4 key购买 nike

所以我正在快速构建这个应用程序,其中包含用户登录前应读取的数据。

为了防止它被从我的应用程序中读取,我提出了基本的安全规则:

".read": "auth != null"

为了防止在登录前读取,我在调用时放置了一个加载 View Controller :

func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {

let ref = Firebase(url: "<my firebase url>")

ref.observeAuthEventWithBlock({ authData in
if authData != nil {
segueToListViewController()
}
})
return true
}

但是当我达到这种程度时,有时 firebase 会给我“权限被拒绝”错误,有时却不会。

我确定有一个登录用户,因为我正在记录所有内容:

  • 登录名已更改
  • 登录 AuthData facebook 的用户:
  • applicationDidBecomeActive
  • 加载 ListViewController
  • 加载数据
  • 错误:错误域=com.firebase 代码=1“权限被拒绝”

那么为什么 Firebase 有时会在用户登录时拒绝阅读?

最佳答案

我来晚了,但如果您将 .read 规则放在更高一级,直接放在 child 名字的下面,这可能会有所帮助。

例如

{
"rules": {
"users": {
"$uid": {
".read": "auth != null && auth.uid == $uid",
".write": "auth != null && auth.uid == $uid"
}
},
"child": {
".read": "auth != null",
".write": "auth != null",
"$child": {
}
}
}
}

关于ios - Swift:Firebase 读取权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31735355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com