小编sie*_*fix的帖子

Firestore / Firebase模拟器未运行

我正在尝试使用此处列出的指南在本地测试我的功能 :https://firebase.google.com/docs/functions/local-emulator

我已经安装了最新的firebase-tools

npm install -g firebase-tools

在我package.json我确认正在运行

"firebase-admin": "^7.3.0",
"firebase-functions": "^2.3.1",
Run Code Online (Sandbox Code Playgroud)

当我尝试使用以下命令运行函数时

firebase emulators:start

它给了我下面的输出。我究竟做错了什么?

Starting emulators: ["functions"]
?  Your requested "node" version "8" doesn't match your global version "11"
?  functions: Emulator started at http://localhost:5001
i  functions: Watching "[FUNCTIONS FOLDER PATH]" for Cloud Functions...
?  Default "firebase-admin" instance created!
?  Ignoring trigger "[FUNCTION NAME]" because the service "firebaseauth.googleapis.com" is not yet supported.
?  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running. …
Run Code Online (Sandbox Code Playgroud)

firebase firebase-tools google-cloud-functions google-cloud-firestore firebase-cli

8
推荐指数
6
解决办法
5677
查看次数

云函数部署 - 类型错误:instance.INTERNAL.registerComponent 不是函数

当我尝试部署 Cloud Functions 时出现此错误。已尝试使用firebase-admin8.8.0、8.7.0 和 8.6.1(最后 3 个版本)

运行firebase-functions3.3.0

知道问题是什么吗?还有其他人有这个问题吗?

Error: Error occurred while parsing your function triggers.

TypeError: instance.INTERNAL.registerComponent is not a function
    at registerDatabase (/PATH/cloud-functions/functions/node_modules/firebase-admin/node_modules/@firebase/database/dist/index.node.cjs.js:15165:39)
    at Object.<anonymous> (/PATH/cloud-functions/functions/node_modules/firebase-admin/node_modules/@firebase/database/dist/index.node.cjs.js:15196:5)
    at Module._compile (internal/modules/cjs/loader.js:721:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Module.require (internal/modules/cjs/loader.js:657:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at FirebaseNamespace.get [as database] (/PATH/cloud-functions/functions/node_modules/firebase-admin/lib/firebase-namespace.js:282:38)
Run Code Online (Sandbox Code Playgroud)

google-cloud-functions google-cloud-firestore

6
推荐指数
2
解决办法
3453
查看次数

Firestore 安全规则正则表达式

我试图评估string公司的FireStore安全规则基础上,匹配的正则表达式功能

我的代码是 username.matches('^(?!\.)(?!_)(?!.*\.$)(?!.*?\.\.)[a-z0-9_.]+$')

在线使用正则表达式模拟器它正在工作

https://regex101.com/r/bDXMg3/2/

但是在安全规则中使用相同的语法会引发大量错误

在此处输入图片说明

我试图然后双重逃避每个 .

使用代码 username.matches('^(?!\\.)(?!_)(?!.*\\.$)(?!.*?\\.\\.)[a-z0-9_.]+$')

它只显示一个错误(开头的红色 ^ 符号),但随后它给了我以下错误

在此处输入图片说明

Invalid regular expression pattern. Pattern: ^(?!\.)(?!_)(?!.*\.$)(?!.*?\.\.)[a-z0-9_.]+$.
Run Code Online (Sandbox Code Playgroud)

我的目标是:

  • 不以.或开头_
  • 不以a结尾 .
  • 不允许.连续两个
  • 只有小写letter charactersnumbers

谁能让我知道我做错了什么?

firebase-security google-cloud-firestore

4
推荐指数
1
解决办法
2536
查看次数

Firestore 安全规则:request.time“未定义对象”

我正在尝试根据AngularFirebase 网站上的示例中给出的request.time创建安全规则。

我的功能是

function isThrottled() {
    return request.time < resource.data.lastUpdate + duration.value(1, 'm')
}
Run Code Online (Sandbox Code Playgroud)

我试图去的地方 allow update: if isThrottled() == false

但是,当我尝试使用此规则更新文档时,由于未在对象上定义时间而失败。

错误:simulator.rules 行 [169],列 [12]。对象上的属性时间未定义。

不应该每个请求都有一个timeTimeStamp附加到它吗?这与我初始化 Cloud Functions 或客户端应用程序的方式有关吗?

截图如下:

在此处输入图片说明 在此处输入图片说明

编辑

其余更新安全规则的片段是:

service cloud.firestore {
  match /databases/{db}/documents {
    match /users/{userId} {
      match /username/{id} {
        allow update: if isSelf(userId)
                      && usernameAvailable(incomingData().username)
                      && incomingData().username is string
                      && incomingData().username.size() <= 25
                      && incomingFields().size() == 1
                      && isThrottled() == false;
      }
    }

    function …
Run Code Online (Sandbox Code Playgroud)

firebase-security google-cloud-firestore

4
推荐指数
1
解决办法
2608
查看次数

Google RE2 Regex 转义句号和下划线错误

我正在尝试验证username具有以下特征的字符串:

  • 不以.或开头_
  • 不以a结尾 .
  • 不允许.连续两个
  • 只有小写letter charactersnumbers

我的代码是 username.matches('^(?!\.)(?!_)(?!.*\.$)(?!.*?\.\.)[a-z0-9_.]+$')

在线使用正则表达式模拟器它正在工作

https://regex101.com/r/bDXMg3/2/

但是在Google RE2 语法中使用相同的语法(在Firestore 安全规则中使用)会引发大量错误

在此处输入图片说明

我试图然后双重逃避每个 .

使用代码 username.matches('^(?!\\.)(?!_)(?!.*\\.$)(?!.*?\\.\\.)[a-z0-9_.]+$')

它只显示一个错误(开头的红色 ^ 符号),但随后它给了我以下错误

在此处输入图片说明

Invalid regular expression pattern. Pattern: ^(?!\.)(?!_)(?!.*\.$)(?!.*?\.\.)[a-z0-9_.]+$.
Run Code Online (Sandbox Code Playgroud)

谁能让我知道我做错了什么?

regex re2

4
推荐指数
1
解决办法
2540
查看次数