Testing Firebase with Companion

Hi

I am new to Kodular but I have been enjoying it for the last few weeks. Previously I have used thunkable.

My app needs to use a firebase database and I have set it up. It works when installed to a phone via an apk but not through Companion which I understand is by design?

Up to now I have used Companion for all my development / testing and its a great system, especially through the USB - very quick. If I have to do all the database development through the apk route it is not going to be usable.

Is there any way to use firebase when I am developing the app that works with Companion? Perhaps a Web API or an extension?

Thanks in advance.

1 Like

Hi @Patrick_Dight Welcome to Kodular Community

Strange…it should be same in companion as in apk.
There can be some other issues.
You should show your blocks and designer properties also.

2 Likes

AFAIK, only Firebase authentication doesn’t work in the companion. Everything else should debug fine.

I should have also said that the blocks I posted give a FirebaseError Permission denied.

I missed this entirely. It didn’t occur to me that I could use the database without the Authenticating component. I already have a firebase database which I put into the url of the database component. How do I securely access the database while developing using Companion without using Firebase Authentication? I see there is a Firebase Token property already populated - do I use this in a rule? Do I set this to something from the Firebase Console?

Please excuse my not understanding such a basic point. I have read the documentation and searched but I still don’t get it.

I have a simple test…

image

Thanks again.

Does your test work?

No @Mateja I get Permission denied. However, when I change the firebase Database Rules to be as follows…

It works. So I guess the problem is just how to protect the database while it is in development? It is not ideal to open it up to the world like this. I will read up some more on rules.

check bucket name, because if you leave it empty in firebase database properties it sometimes change automatically to app name.

Thanks @ImranTariq. I think I have a working solution but it does not appear to be ideal.

I can set up 2 sets of rules in Firebase, one set for a ‘production’ bucket and another set for a ‘develop’ bucket…

image

Here is the data…

image

Now when I am developing I use the ‘develop’ project bucket as the property for the firebase database. I can bypass a user login step by initialising a variable with a Firebase User UID and saving data to a bucket of that name etc etc

image

When I release a production app I just change the Project Bucket to ‘prod’ which the firebase rules are set up to allow only authenticated users. Obviously rules can be expanded to only allow access to their own data etc as required.

This look workable but it does not provide any protection to the develop bucket in the database which does not appear to be desirable? Is it intended that Kodular firebase development be done in such an unsafe manner? Am I missing a better solution?

Thanks again in advance.

well, playing with firebase rules is still a mystery for many users including me, i have tried that to set many times as you are trying but after failing i leaved and started using other databases, i think if someone can help the only will be staff of firebase.

I think there is no need to use two project buckets.
What you can do is to set rules to test mode while developing app and change it to locked mode when your app is ready to be published or tests.

Hi @vknow360

Yes this could work as well, but even after going live there will always be a need to bug fix / further develop. It is mostly a matter of preference though.

I am interested to see if anyone has an opinion on this?

Also, What about the use case where a firebase database is needed but only the app itself will authenticate? For instance to store shared information between users. How does this work?

Regards

Here is a solution for testing. Just getting started with Firebase, so YMMV.

I’m storing the Token in TinyDB.

blocks1 blocks2

Then use a text field to display my token.

blocks3

Create an apk to install on device so that you can fetch the token.

Next I use a global variable to indicate testing in Companion. (Tried to use Device Utilities - Is Emulator, but it always came back false.)

blocks4
When testing, display a text box to enter the token. I fetch the token from previous runs so that I don’t have to paste it in subsequent runs.


blocks6

Then proceed using the token.

Now using the app from the apk, copy the token. Start companion and paste in token. Repeat when you need a fresh token.

I do this and still some times have the permission error. Do you know why??