Firebase管理员SDK getaddrinfo ENOTFOUND metadata.google.internal。错误代码:ENOTFOUND”

时间:2019-08-05 15:53:26

标签: node.js firebase firebase-authentication nestjs

我正在尝试设置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);
        });

}

该如何解决?

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

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