属性"值"在打字稿中的 gcloud param defineSecret 的类型"SecretParam"上不存在



我正在编写一个firestore函数,我想为它设置一些秘密。我在firebase文档中阅读了如何设置一个秘密参数:

https://firebase.google.com/docs/functions/config-env#secret_parameters

所以我试过了:

import * as functions from "firebase-functions";
import {defineSecret} from 'firebase-functions/params';
const someToken = defineSecret("TOKEN_NAME");
import * as express from "express";
import {bootstrap, services} from "./bootstrap";

export const app = express();
app.use(express.json());
app.get("/", (req, res) => {
res.sendStatus(200);
});
app.post("/", async (req, res) => {
if (!req.body) {
res.send("json body missing!");
return;
}
await bootstrap(someToken.value());
services.useGraphQL?.getEntity(req.body).then(
(response) => {
res.status(200).send(response);
},
() => {
console.error(`Error while ${req.body.command}`);
res.sendStatus(500);
});
}
);
export default functions
.runWith({secrets: ["TOKEN_NAME"]})
.https.onRequest(app);

我的问题是;someToken.value(("抛出错误";类型"SecretParam"上不存在属性"value";。那么我做错了什么?我该怎么做才能正确地做?

我试图以不同的方式读取Object的值,但其他所有内容都解决了更多的类型错误。

访问机密时,它们会作为云函数的环境变量添加。在本例中,可以通过process.env.MY_SECRET访问它们。

另外,您是否对someToken对象进行了JSON序列化并记录了它?这将使您能够看到对象结构是什么,并可能在上述操作不起作用的情况下揭示可用的对象密钥。

最新更新