DEV Community

jacob30
jacob30

Posted on

Firebase local tips

If you're getting the following error error: Failed to parse private key: Error: Invalid PEM formatted message when using Firebase locally. Try replacing the following with the following:

export class Database {
    public database: admin.database.Database;

    constructor() {
        const app = admin.apps.find((it: any) => it?.name === "[DEFAULT]") ||
            admin.initializeApp({
                credential: admin.credential.cert({
                    projectId: config.FIREBASE_PROJECT_ID,
                    clientEmail: config.FIREBASE_CLIENT_EMAIL,
                    privateKey: config.FIREBASE_PRIVATE_KEY!.replace(/\\n/gm, "\n"),
                }),
                databaseURL: config.FIREBASE_DATABASE
            });

        this.database = getDatabase(app);
    }
Enter fullscreen mode Exit fullscreen mode
export class Database {
  public database: admin.database.Database;

  constructor() {
    const app = admin.initializeApp({
      credential: {
        getAccessToken: () =>
          Promise.resolve({ access_token: 'foo', expires_in: 3600 }),
      },
      databaseURL: `${config.FIREBASE_URL_WITH_PORT}/?ns=demo-yourprojectname`,
    });
 this.database = getDatabase(app);
  }
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more