【问题标题】:Firebase admin SDK getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND"Firebase 管理员 SDK getaddrinfo ENOTFOUND metadata.google.internal。错误代码:ENOTFOUND"
【发布时间】:2019-08-06 01:05:42
【问题描述】:

我正在尝试设置 admin sdk 并创建了一个新的私钥。我什至恢复到只有 admin sdk 的旧版本,但它不起作用。有什么可以缓存在我的设备上的吗?

Nest application successfully started NestApplication true
Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND". Error: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND".
    at FirebaseAppError.FirebaseError [as constructor] (/Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/utils/error.js:42:28)
    at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/utils/error.js:88:28)
    at new FirebaseAppError (/Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/utils/error.js:122:28)
    at /Users/user/Documents/Dev/project/demo/node_modules/firebase-admin/lib/firebase-app.js:121:23
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at /Users/user/Documents/Dev/project/demo/node_modules/@nestjs/core/router/router-execution-context.js:44:28
    at /Users/user/Documents/Dev/project/demo/node_modules/@nestjs/core/router/router-proxy.js:8:17 ExceptionsHandler

这就是我尝试使用这两个包的方式:

import * as firebase from 'firebase-admin';
import * as serviceAccount from '../../firebase_credentials.json';

const config = {
    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,
};

if (!firebase.apps.length) {
    firebase.initializeApp(config);
}

export const firebaseAuth = firebase.auth();

export function create(email: string, password: string) {
    firebaseAuth.createUser({
        email: email,
        emailVerified: false,
        password: password,
        displayName: email,
        disabled: false,
    })
        .then( (userRecord) => {
            // See the UserRecord reference doc for the contents of userRecord.
            console.log('Successfully created new user:', userRecord.uid);
        })
        .catch((error) => {
            console.log('Error creating new user:', error);
        });

}

我应该如何解决这个问题?

感谢您的帮助

【问题讨论】:

    标签: node.js firebase firebase-authentication nestjs


    【解决方案1】:

    您不能在一个应用中同时使用 Admin SDK 和常规 Firebase JavaScript SDK。如果应用程序在可能不受信任的环境中运行,则应使用常规 JavaScript SDK。如果它在受信任的环境(例如您的开发机器、您控制的服务器或 Cloud Functions)中运行,您可以使用适用于该环境的 JavaScript SDK 或 Admin SDK(在您的情况下使用 Node.js)。

    【讨论】:

    • 感谢您的回复。我试图恢复到只使用管理 SDK 的旧版本。我得到和以前一样的错误。知道为什么吗? (更新的初始帖子)
    • 这是一个不同的问题。在人们回复后,请不要编辑您的问题以更改其含义,因为现在我上面的回答已经没有意义了。如果您对解决我的答案的旧代码有其他问题,请针对该问题打开一个新问题。
    猜你喜欢
    • 2019-03-14
    • 2016-09-20
    • 2017-10-16
    • 1970-01-01
    • 2018-03-03
    • 1970-01-01
    • 2014-10-20
    • 1970-01-01
    • 2018-05-24
    相关资源
    最近更新 更多