我想从NodeJS(TypeScript)
后端验证令牌。在文档中,他们这样提到,但这是在JavaScript
中,我希望它在TypeScript
中
var admin = require("firebase-admin");
var serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
字符串
我想在TypeScript中使用this blog,如下所示
import * as firebase from 'firebase-admin'
import * as serviceAccount from 'firebase-admin'
const params = {
type: serviceAccount.type,
projectId: serviceAccount.project_id,
privateKeyId: serviceAccount.private_key_id,
privateKey: serviceAccount.private_key,
clientEmail: serviceAccount.client_email,
clientId: serviceAccount.client_id,
authUri: serviceAccount.auth_uri,
tokenUri: serviceAccount.token_uri,
authProviderX509CertUrl: serviceAccount.auth_provider_x509_cert_url,
clientC509CertUrl: serviceAccount.client_x509_cert_url
}
firebase.initializeApp({
credential: firebase.credential.cert(params),
})
型
但是我得到了这个错误,我怎么才能摆脱这个呢?
Property 'type' does not exist on type 'typeof import("nodeFirebasebackend/node_modules/firebase-admin/lib/default-namespace")'.ts(2339)
型
的数据
1条答案
按热度按时间kognpnkq1#
查看https://firebase.google.com/docs/reference/admin/node/firebase-admin.serviceaccount上的文档
我可以看到
serviceAccount
具有以下属性:clientEmail
个privateKey
个projectId
个因此,您试图引用不存在的字段。