当我开始使用Firebase应用程序时,我曾使用下面的语句将其部署到云中以初始化firebase-admin对象:
admin.initializeApp();
过了一会儿,我发现了firebase serve
。但是,当我尝试在本地运行该应用程序时,我在终端控制台中找到了它:
> Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
> at GoogleAuth.getApplicationDefaultAsync (/Users/saulo/Documents/projects/tmp/firebase/socialape-functions/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
> at <anonymous>
> at process._tickCallback (internal/process/next_tick.js:189:7)
为了避免此错误,我需要将admin.initializeApp()
替换为:
admin.initializeApp({
credential: admin.credential.cert(require('../keys/admin.json'))
});
我在找到this post here in the stack-overflow之后做到了,但这不是长期的可持续解决方案。
无论执行上下文如何,如何继续使用相同的initializeApp()
语句?