I started an iOS app using Firebase's Firestore database in test mode, but now that I am done using test mode, how do I convert the database into Production mode?
When you make a new Firestore it says if you want to set it to production mode or test mode. The only difference between the two is that test mode allows read and write capabilities while production does not. To change from Test mode into Production mode all you do is go to Firebase > Firestore > Rules > Edit Rules. Then change the code from:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2021, 6, 6);
}
}
}
To this:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
There is not really a "mode" that you can switch to. If you're referring to the dialog that had you choose your initial security rules, all that did was pre-populate some security rules for you to get started. After that, it's up to you to come up with security rules that suit your application. I strongly suggest reading through the linked documentation to understand what you should do. Whatever you do, it will be highly customized to you specific data and access patterns.
Allow only authenticated users to read/write to Firestore in Production
We can set our security rules in such a way that only authenticated users can read/write to firestore which is a common scenario for an app in production
.
Use a whole separate collection like public
which contains data that doesn't need any authentication if you choose to have some data for everyone.
Change the rules here Firebase > Firestore > Rules > Edit Rules
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /public/{publicDoc}{
allow read: if true;
}
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
Note: You need to set up the authentication for your project to have the above code working.
If your app doesn't have authentication check for other possibilities here
There are some basic rules configurations given by firebase to set up rules for production-ready apps and we can set rules according to our use case. This is the link where all rules are given for test and production mode apps. To edit rules go to Firestore Datbase > Rules.
One thing I did was disabled the sign-in checks in my code:
Future<DocumentReference> addMessageToGuestBook(String message) {
//if (!_loggedIn) {
//throw Exception('Must be logged in');
//}
return FirebaseFirestore.instance
.collection('guestbook')
.add(<String, dynamic>{
'text': message,
'timestamp': DateTime.now().millisecondsSinceEpoch,
'name': FirebaseAuth.instance.currentUser!.displayName,
'userId': FirebaseAuth.instance.currentUser!.uid,
});
}
And then I changed the rules in Firestore to this:
// Allow read/write access to all users under any conditions
// Warning: **NEVER** use this rule set in production; it allows
// anyone to overwrite your entire database.
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
(Assuming you're following the Flutter Firestore tutorial)
© 2022 - 2025 — McMap. All rights reserved.