Hi, I’ve tried to find the answer to this elsewhere but haven’t been successful; I’m hoping someone can kindly help me.
I am trying to create an app where a user logs in and can view PDF files specific to them. I’ve created the user login process (using Firebase) and have created: Authentication, RealTime Database and Storage.
The first two work fine to login / logout and to retrieve text data. I now need a user to be able to retrieve files specific to them which have already been added to their record (not generic URL files that anyone can see).
Is this possible? If not possible to directly connect my app with the storage database, is it possible to connect a field in my realtime database with the url of a file in my storage? That way I can set the field to display the url of the file and clicking it would then show.
Yes, just put the url in your realtime db under the users email address. For example you’re json to send to firebase would be something like {email:{“fileName”:“lkjdsflkjcikjl”,“fileUrl”:“www.url.com”,“date”:“6/25/20”}} (assuming email is your variable).
Then when you retrieve it you’ll retrieve the email key.
Thanks very much for replying to my post. I’m really new to both Thunkable and programming, so my follow up questions might be a little basic (apologies).
The tutorials I’ve been watching so far has my realtime db set up so that data is stored under the user’s UID (which is common to both the authentication and the realtime). As a test, I’ve created a structure in my realtime db of:
I can then “get” that data using a key that has the above structure.
I’m going to set aside how I get the storage url into the Test_Data_Field for the moment, and just assume that its already there (manually added a test PDF). I’m not sure what to do next. Is there a function in Thunkable that will read the url and allow the user to tap it in order to view? I re-created the block you kindly added (above) but then didn’t know what to do with it. Does it connect to the PDF viewer in some way?
I’m likely to be missing something (or many things!) here; if you could dumb it down for me, that would be greatly appreciated
Based on your data structure (assuming the ‘AySHtKT…’ is your key) it would look like this:
If your key is actually generated by firebase then you may have to search for the user_email, which is a bit more involved with that data structure (and not recommended by me). Just as long as you know that key you should be good.
Also, another point just to save you some headache as you work through this process: if your data object comes back null and you try to use it it will stop your app at that point. So I usually put in some logic to make sure ‘data’ is not null. Something like this:
Hi, thanks very much for the advice. I think I’ll have to have a play around with it in order to understand what to do. My knowledge gaps seem to be how to connect in with Firebase’s authenticatio, its storage and the realtime db so the app will get Thunkable to log the user in, but then connect data from the realtime db and files from storage.
If you have any advice on how the firebase authentication with its user ID and email can link in with its realtime db, it would be very gratefully received. My problem is less the fact that I don’t know the answers, its more I don’t know the right questions to ask
The block I created (the purple block) is a function so it can be added anywhere that you need to get that url. In fact there’s a function block with a “return” feature also that you could use to return the app url and then you just plug in that function block anywhere you need to get the Url.
Keep in mind that the documentation hasn’t been updated to include the newer “cloud” blocks for firebase. They are definately the way to go and it seems like you’ve already figured out how to use those for the most part.
To use firebase effectively you’ll really need to figure out the data structure and the difference between objects and lists. If you upload a list to firebase for example it will assign numbers.
If you want to search by user email then you’ll want to adjust your structure to something like:
USERS
–>email
------>user data
So you’ll be uploading to a path like this:
There’s a little bit of a learning curve, but far less than programming languages.
The best thing to do is just play around with it and keep diving into the documentation until you see the outcomes you want.