如何验证 Firebase 规则中的密钥?

问题描述 投票:0回答:1

在实时 Firebase 数据库中,这是我的数据结构:

{'comments': {
  ${project_uuid}: {
     ${thread_uuid}: {
        'author': 12,
        'data': 'who lot of text'
     }
  }
}}

我想验证

comments
内部只有uuid对象。我使用 bolt 生成 Firebase 规则:

path /comments {
   read() { auth != null }
   write() { auth != null }

   /{project_uuid} is UuidOnly {
       /{thread_uuid} is Thread;
   }      
}

type Thread {
   author: Number,
   data: String,
}

type UuidOnly {
  validate() {
    // The next line is the problem
    this.parent().key().test(/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/)
  }
}

在最后一行中,

key()
似乎无法用作函数。我如何进行此验证以确保注释内只有 uuid 对象?

firebase-realtime-database firebase-security
1个回答
0
投票

问候尼克,请尝试以下操作

type UuidOnly {
  validate() {
    data.test(/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/)
  }
}

尝试上述方法并告诉我

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.