我在比较firebase db中保存的时间间隔与“现在”firebase安全规则时遇到问题。我写的规则是为了防止用户在某个时间之后阅读帖子。
我就是这样
在我的数据库中保存时间戳
:
"time": NSDate().timeIntervalSince1970
这是保安
我写的规则应该阻止阅读
如果在一段时间后:
"follower-feed": {
// ".read": "auth !== null",
".write": "auth !== null",
"$userID": {
"$postID": {
".read": "auth !== null && data.child('time').val() >= ((now / 1000) - 86400)",}}},
这就是
数据库架构
我正在使用存储帖子:
-从动件进给:{
user\u uid\u 1:{
post_uid_1: {
"time": 1515435031.16646
post_uid_2: {
"time": 1515435091.22323
我想指出的是,我已经考虑到了‘now’是以毫秒为单位的这一事实,将其除以1000应该会将我的两个数字设置为相同的秒时间值。我已经扼杀了所有关于firebase文档的内容,但没有任何东西可以帮助我解决这个问题。当我运行模拟器测试以确定请求的读取是否会通过时,它会说它会通过。但是,在我的应用程序中,没有读取任何数据。
这是试图
从firebase读取数据
:
var followingPosts = [Post]()
func loadUserFeed(_ update: @escaping () -> Void) {
userFeedHandle = CURRENT_USER_FEED_REF.observe(DataEventType.value, with: {(snapshot) in
self.followingPosts.removeAll()
for child in snapshot.children.allObjects as! [DataSnapshot] {
let post = Post(postID: child.key, postData: child.value as! Dictionary<String, Any>)
self.followingPosts.append(post)
self.followingPosts.sort(by: { Double(truncating: $0.time) > Double(truncating: $1.time)})
update()
}
if snapshot.childrenCount == 0 {
update()
}
})
}