Running firebase admin and firestore on google app engine

Viewed 334

I am currently running a node js server on Google App Engine, in the server, I am using firebase-admin package to interact with firebase. I am following the docs https://firebase.google.com/docs/admin/setup and initialise the app like this:

import admin from 'firebase-admin';

const NODE_ENV = process.env.NODE_ENV;

if (NODE_ENV === 'production') {
  admin.initializeApp();
} else {
  // eslint-disable-next-line @typescript-eslint/no-var-requires
  const firebaseAccountCredentials = require('../../credentials.json');
  const serviceAccount = firebaseAccountCredentials as admin.ServiceAccount;
  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
  });
}

export const db = admin.firestore();

It works all fine locally, as I am passing the credentials however when it is run inside App Engine, I see this error: details: 'The Cloud Firestore API is not available for Datastore Mode projects.'.

Do I have to set service accounts to connect to firebase? If so how? Couldn't find the documentation for that.

This is my app.yaml

runtime: nodejs
env: flex

Thanks

1 Answers

The error message you are getting is pretty self explanatory. What is happening is that you are trying to connect to a Firestore DB in Datastore mode with the Firestore admin SDK, which is not possible.

The reason why this was working in your local environment is likely because you were using an emulator with Firestore properly setup in Native mode, but in the live environment you probably set it up as a Firestore with Datastore mode, in order to fix it you will have to create another Firestore in Native mode.

Related