Jblew / firebase-functions-rate-limiter

Js/ts library that allows you to set per-time, per-user or per-anything limits for calling Firebase cloud functions
MIT License
100 stars 15 forks source link

Error: The default Firebase app does not exist. when creating limiter object in non root file & outside of function scope #17

Closed jasan-s closed 3 years ago

jasan-s commented 3 years ago

I'm initializing admin in my root functions file(index.js). if I create a limiter object in root index.js file no error is thrown. However, in my case i'm trying to set a limiter in subfolder file i.e (api/emailsend.js)

If i try to create rateLimiter outside of the function and outside of root file where I initialized admin I the following error: Error: The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.

the error is due to me calling admin.firestore() inside this libs FirebaseFunctionsRateLimiter.withFirestoreBackend function. As it seems the admin.initializeApp({}) has not completed when rateLimiter is creation is invoked .

Any suggestions?

jasan-s commented 3 years ago

I just had to import the sub folder files after admin.initializeApp({}) . its working.