我目前不能在nodejs中使用firebase-admin读写数据。
如果没有打开日志,它只会永远挂起,永远不会返回错误,也永远不会完成。
然而,在打开日志记录的情况下,它会给出以下结果(它会继续按递减的计划重试-但结果相同):
p:0: Browser went online.
0: set {"path":"/server/saving-data/fireblog/users","value":{"alanisawesome":{"date_of_birth":"June 23, 1912","full_name":"Alan Turing"},"gracehop":{"date_of_birth":"December 9, 1906","full_name":"Grace Hopper"}},"zg":null}
p:0: Buffering put: /server/saving-data/fireblog/users
p:0: Making a connection attempt
p:0: Failed to get token: Error: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "unable to verify the first certificate".
p:0: data client disconnected
p:0: Trying to reconnect in 0ms
0: onDisconnectEvents当我捕捉到(firebase-admin内部的) https请求时,我得到了以下内容:
{ Error: unable to verify the first certificate
at TLSSocket.<anonymous> (_tls_wrap.js:1094:38)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:188:7)
at TLSSocket._finishInit (_tls_wrap.js:616:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:446:38) code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }我尝试从控制台生成一个新的私钥,但它继续返回相同的错误。我还按照别处的建议添加了require('ssl-root-cas').inject(),但它不会改变行为。此外,将实际的json对象传递给admin.credential.cert函数也不会改变行为。
我当前使用的是node v7.7.4。
下面是产生错误的代码:
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.cert('./serviceAccountKey.json'),
databaseURL: 'https://mtg-decks-bc92d.firebaseio.com'
});
// turn on logging
admin.database.enableLogging(true);
const db = admin.database();
const ref = db.ref('server/saving-data/fireblog');
const usersRef = ref.child('users');
usersRef.set({
alanisawesome: {
date_of_birth: 'June 23, 1912',
full_name: 'Alan Turing'
},
gracehop: {
date_of_birth: 'December 9, 1906',
full_name: 'Grace Hopper'
}
}).then(() => {
console.log('set complete');
});发布于 2017-04-15 07:16:58
其他一些帖子建议通过调用require('ssl-root-cas').inject();来添加根证书。你能试试吗?
发布于 2018-12-26 22:39:16
我得到这个错误是因为我的本地机器的时区是手动设置的,所以令牌过期等都是关闭的。
https://stackoverflow.com/questions/43309775
复制相似问题