How to have your app work offline from the start - google-cloud-firestore

I am looking for examples/tutorials or an explanation of how I can use my app that has both Firebase Authentication and the Firestore cloud database. I think I understand how to setup offline persistence with the Firestore db, and I think that means that data will be persisted while my app is running and should connection be lost.
What if a user jumps on a a plane with zero connection and wants to run my app and is first presented with the login screen for Authentication. Can you point to an example or tutorial on the best way to setup this so that the app can still run from the beginning with no connectivity and then be able to authenticate and put the data in the Firestore cloud database when connectivity is gained?
Thank you.

According to the official Firebase documentation:
If your app uses Firebase Authentication, the Firebase Realtime
Database client persists the user's authentication token across app
restarts. If the auth token expires while your app is offline, the
client pauses write operations until your app re-authenticates the
user, otherwise the write operations might fail due to security rules.
EDIT:
You can achieve that with Cloud Firestore by enabling offline persistence:
Cloud Firestore supports offline data persistence. This feature caches
a copy of the Cloud Firestore data that your app is actively using, so
your app can access the data when the device is offline. You can
write, read, listen to, and query the cached data. When the device
comes back online, Cloud Firestore synchronizes any local changes made
by your app to the Cloud Firestore backend.
Note that you won't need to make any changes to the code that you use to access Cloud Firestore data.
Here you can see some examples for configuring the offline persistence.

Related

Flutter Firebase Data Privacy

How can we deliver a Flutter / Firebase App and make sure the Dev Team has no access to the Client Data requiring no Manual Setting in Firebase?
Setting up individual Firebase account does not seem to work, as it may be quite time consuming and expensive

was working well but FirebaseException ([cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.)

I have been working on the Flutter app with firebase and the app was working well but today when I trying to retrieve the data from using snapshot I got this exception.
FirebaseException ([cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.)
is there any update on firebase i have to do or what ?
When you create a project and set Firestore access it test mode, it sets the database up to allow public access for only a month. If this suddenly happened without a change on your side, it could be that your security rules expired.
Now would be a good moment to implement proper security rules for your data, as leaving all data publicly accessible is a recipe for future problems.
So learn how to secure the data, have a look at the documentation on security rules, this more technical documentation, and also see:
Firestore Permission Denied in Android
Email: [Firebase] Client access to your Cloud Firestore database expiring in X day(s)

User Management Token - React Native / MongoDB

I am new to react-native development. I need to implement User Authentication for Login and Sign Up for my react native apps. I saw some tutorial using Firebase Authentication but I plan to use the mongoDB instead of Firebase. I am not sure how to use mongoDB. For firebase its pretty simple because they provide API URLS and all we need to do is just send the request with our data. But when I am trying to use mongoDB I am not sure how to implement and get the token key back from server side. Do I need to write server side code for mongoDb or they have simplified API URL like firebase? Please Help . Thank You
You are missing a lot of concepts.
Firebase is a BaaS (Backend as a Service), so it sell you a backend already done with authentication, database ecc.
Mongo DB is a database, it could be IaaS (Infrastructure as a Service) or Paas (Platform as a Service), but it's not a BaaS.
So you can't just replace firebase with mongo, but you need to build your whole backend and have a server to deploy it. You need to manage environments, authentication, security and many other feature that firebase already offers you.

Cloud firestore sensitive information in .json file

In official Cloud Firestore documentation we can read that to connect with Cloud Firestore we need to download private key (.json) and use firebase-admin.
Is it safe to use that metod in client app? Or maybe there is other way to get safe access to Firestore from client app?
Thanks a lot.
As you said "private key (.json) , firebase-admin". These gives direct access to firestore database without authentication. If you don't want to make your client, admin of your firestore :) Don't do it.
Is it safe to use that metod in client app?
firebase-admin is not meant for use in web and mobile clients. It's for backend code running in an environment you fully control. Your users would not have access to this, which means it would be safe for you to use private keys.
You definitely do not want to ship any service account credentials with your app.
Or maybe there is other way to get safe access to Firestore from client app?
You're supposed to use the provided client SDKs to access Firestore from apps, and use security rules to declare which authenticated users are able to read and write which documents.

how to import JSON data from rest API to google firebase?

I am planning to use Firebase as my backend service for the mobile application. As part of the functionality, I need to get the data from external rest API which returns JSON data. I need to update the data periodically so that I can have updated information.
I have an option to call the rest API and update firebase on the mobile application however it is not the right approach. I prefer to keep this logic on the backend service.
Is there a way to use Firebase cloud function to periodically update firebase database from external Rest API?
#Ioki, I assume what you are trying to do is make a mobile app which gets updated data every time a user goes to the app but you want this to be on the backend. I haven't tried it but you might want to use Node js with their Firebase Admin SDK.
See the link: https://firebase.google.com/docs/admin/setup
Although I think it might make more sense to use the real-time database via the iOS/ Android SDK because automatic/ value event updates are basically the purpose of the real- time database. Good luck! :)