Home > database >  Property 'value' does not exist on type 'SecretParam' of gcloud param defineSecr
Property 'value' does not exist on type 'SecretParam' of gcloud param defineSecr

Time:10-27

I am writing a firestore function for which I want to set some secrets. I read in the firebase documentation how to set up a secret param:

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

so I tried it that way:

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);

My problem / question is, that "someToken.value()" throws the error "Property 'value' does not exist on type 'SecretParam' ". So what am I doing wrong? What can I do to do it correctly?

I tried to read the value of the Object differently, but everything else resolved in more type errors.

CodePudding user response:

When accessing secrets they are added as environment variables for the cloud function. They can be accessed through process.env.MY_SECRET in this example.

Also, have you JSON serialised the someToken object and logged it? That would enabled you to see what the object structure was and potentially reveal the object key useable if the above doesn't work.

  • Related