Created
August 4, 2026 21:02
-
-
Save devvspaces/fe283208d4dbd1ab97dfc0e6e0bdea4c to your computer and use it in GitHub Desktop.
Make firebase admin work with nestjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { App, initializeApp, cert, getApps } from 'firebase-admin/app'; | |
| import { getMessaging, Message } from 'firebase-admin/messaging'; | |
| import { ServiceAccount } from 'firebase-admin'; | |
| // Ensure gaxios (used by firebase-admin & google-auth-library) uses Node native fetch | |
| function patchGaxiosClass(Gaxios: any) { | |
| if (Gaxios && !(Gaxios.prototype as any).__fetchPatched) { | |
| (Gaxios.prototype as any).__fetchPatched = true; | |
| const originalRequest = Gaxios.prototype.request; | |
| Gaxios.prototype.request = function (opts: any) { | |
| opts = opts || {}; | |
| opts.fetchImplementation = opts.fetchImplementation || this.defaults?.fetchImplementation || globalThis.fetch; | |
| return originalRequest.call(this, opts); | |
| }; | |
| } | |
| } | |
| try { | |
| const fbPath = require.resolve('firebase-admin'); | |
| const gauthPath = require.resolve('google-auth-library', { paths: [fbPath] }); | |
| const gaxiosPath = require.resolve('gaxios', { paths: [gauthPath] }); | |
| patchGaxiosClass(require(gaxiosPath).Gaxios); | |
| } catch {} | |
| try { | |
| patchGaxiosClass(require('gaxios').Gaxios); | |
| } catch {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment