如何在Firebase管理员中测试云功能验证触发器?

时间:2020-07-31 14:26:01

标签: node.js firebase firebase-authentication google-cloud-functions

我创建了一个服务,该服务应在创建新用户时触发一些方法。

export class CloudFunctionTriggersWrapper {
    constructor(
        private cloudFunctionTriggersService: CloudFunctionTriggersService
    ) {

    }

    private get logId() {
        return `[${this.constructor.name}]`;
    }

    listen(){
        functions.auth.user().onCreate(async (user) => {
            console.log(this.logId, `new User created ${user.toJSON()} `)
            await this.cloudFunctionTriggersService.onCreateUser(user)
        });
    }
}

我在NodeJ上本地运行此代码。

当我创建新用户(通过移动应用Android客户端)时,服务器端没有任何反应(触发器未触发)

我是否必须将其部署到Firebase才能正常工作?

如果是这样,如果我在onCreate内的方法中进行了更改,该怎么办,我每次更改时都必须部署吗?

1 个答案:

答案 0 :(得分:1)

您无法执行的操作。 Firebase提供的Cloud Functions SDK仅允许您构建要部署到Cloud Functions以便在Google基础架构上运行的功能。它不允许您在自己的硬件上运行自己的触发器。

如果您希望代码在创建用户帐户时运行,则必须编写并部署auth trigger才能在Google的云中运行。

如果要在部署之前在本地测试功能,可以使用functions shell手动模拟将传递给该功能的事件。