[英]Firebase secrets not defined in process.env
I'm writing a Firebase function with Cloud Storage trigger.我正在使用 Cloud Storage 触发器编写 Firebase function。 Like this
像这样
const functions = require('firebase-functions')
const doSomethingWithSecrets = require('./doSomethingWithSecrets')
const doSomethingWhenUploaded = functions.runWith({
secrets: ["MY_SECRET_1", "MY_SECRET_2", "MY_SECRET_3"]
}).storage.object().onFinalize(o => {
functions.logger.debug([
process.env.MY_SECRET_1 // undefined
process.env.MY_SECRET_2 // undefined
process.env.MY_SECRET_3 // undefined
])
doSomethingWithSecrets(process.env.MY_SECRET_1, process.env.MY_SECRET_2, process.env.MY_SECRET_3)
// Error: Invalid secret.
})
All three of them returns undefined.他们三个都返回未定义。 I've made sure that they're properly set.
我已确保它们已正确设置。 They show up both when using
firebase functions:secret:accesss MY_SECRET_1
and in Google Cloud Console.它们在使用
firebase functions:secret:accesss MY_SECRET_1
和 Google Cloud Console。
What's wrong?怎么了?
I previously used it with only one secret and it worked.我以前只用一个秘密使用它,并且它有效。 I don't know what happened, I'm using nvm and lost track of which Node version I used when it worked, so it may be a clue.
我不知道发生了什么,我正在使用 nvm 并且在它工作时忘记了我使用的哪个 Node 版本,所以它可能是一个线索。
process.env
returns all the env like normal and none of my secrets shows up. process.env
像往常一样返回所有 env 并且我的秘密都没有出现。
Update your firebase-tools and the issue will resolve itself.更新您的 firebase-tools,问题将自行解决。 I was dealing with this issue all day today and found a git hub issue that fixed the problem in the latest release of 10.9.2.
我今天整天都在处理这个问题,发现一个 git hub 问题在最新版本的 10.9.2 中解决了这个问题。
npm install -g firebase-tools
https://github.com/firebase/firebase-tools/issues/4540 https://github.com/firebase/firebase-tools/issues/4459 https://github.com/firebase/firebase-tools/issues/4540 https://github.com/firebase/firebase-tools/issues/4459
I encountered the exact same issue.我遇到了完全相同的问题。 After much suffering I finally got it to work.
在经历了很多痛苦之后,我终于让它工作了。 When you start using secrets in your functions, you need to redeploy all functions and NOT just the individual function.
当您开始在函数中使用机密时,您需要重新部署所有函数,而不仅仅是单个 function。
eg例如
firebase deploy --only functions:myFunc
results in my secret values coming through as 'undefined' when accessed from my function using runWith(), however after doing a full functions deploy当使用 runWith() 从我的 function 访问时,导致我的秘密值以“未定义”的形式出现,但是在执行完整功能部署后
firebase deploy --only functions
everything worked.一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.