DmitrySharabin / mavo-firebase-firestore

Firebase backend plugin for Mavo. Store and sync app data in milliseconds. Store and serve files at Google scale. Authenticate users simply and securely. All the Google Firebase powers are at your fingertips.
https://plugins.mavo.io/plugin/firebase-firestore
MIT License
6 stars 0 forks source link

The dynamic nature of mv-storage/mv-source/mv-init/mv-uploads is broken #13

Closed DmitrySharabin closed 4 years ago

DmitrySharabin commented 4 years ago

Reported by @karger

Using the current deployed version, I get a weird bug where if I change the storage location of a firebase mavo dynamically I get errors saying there is already an app defined with that name.

Actually, the bug is present in the development version as well.

It appears that when I change the mv-storage of an app, mavo invokes an updateBackend function. This leads to an invocation of new Backend(url,o) from mavo which invokes the firebase constructor. And your constructor calls firebase.initializeApp() with the config which includes the name of the mavo app—which is an error if that same mavo app was previously initialized.

I'm not sure if mavo should be differentiating an instance of update-backend from create-backend but right now it appears they are combined so your constructor needs to figure out which case it is in.

karger commented 4 years ago

I think #15 is a related problem.

karger commented 4 years ago

After looking at this a bit more, it seems to me that the backend should be initializing one, and only one, firebase app per projectId. There has to be a different one for each projectId because the projectId is part of the app configuration. But there's no benefit I can see to having more than one per projectId because there's nothing we can beneficially vary between two such apps.

I assume that by far the common case would be to have only one projectId for all apps on the page; in this case it would seem natural to just initialize the default firebase app. If there is more than one projectId on the page, you could initialize each app using the projectId as the app name. Or maybe this should be what you always do, since then you don't have to decide which case you are in.

DmitrySharabin commented 4 years ago

Thank you for reporting this bug and your suggestion. It absolutely makes sense, and I implemented it the way you proposed.

Will you please check whether now it works the way you expect? It's still available only in the dev version. If anything goes wrong, we can reopen the issue.

karger commented 4 years ago

I put some comments on certain commits; I'm not sure if you get notified about those.

DmitrySharabin commented 4 years ago

I am notified, don't worry. Thank you.

karger commented 4 years ago

Am I right that there will still be a need to login twice on a page where 2 apps have the same project ID? If so I will wait to test until that is fixed.

DmitrySharabin commented 4 years ago

Nope, you don’t need to login twice. The only reason you will have to do that is when you will use apps with different projectIds on the same page.