Onecity : How to Set up Indexes, Storage Rules, Database Rules, and Generate New Private key in Firebase for your Short Video Sharing app?
Follow the below Setup Indexes, Storage Rules, Database Rules, and Generate New Private key in Firebase for your Short Sharing app:
Step 1 : Go to Firebase. If you have a Firebase account, Sign in, else Signup.
Step 2 : Click on Get Started.Step 3 : Select your Firebase project for which you want to add indexes. If you haven’t created a project, click on Add Project.Step 4 : Once you have selected the project, click on Firestore Database under Build.Step 5 : Go to the Indexes tabStep 6 : Click on Create Index.
Step 7 : You need to add the following index details in the composite index section to configure the Tik-Tik app. The data to be entered is given in the table below:
S.No |
Collection ID | Fields to be Indexed | Order of Indexing |
1 | tittikUser | userName | Ascending |
userId | Descending | ||
2 | tiktikVideo | blocked | Descending |
createdAt | Descending | ||
3 | tiktikVideo | userId | Ascending |
createdAt | Descending | ||
4 | tiktikUserLIkedVideo | Blocked | Ascending |
createdAt | Descending |
Step 8 : Once you click on Create Index, a new popup to create composite index will open. Here you need to add all the details as given in the table above sequentially.
For example, let’s add the data from the above table for S.No 1, where the collection ID is tittikUser and fields to be indexed include userName, userId with their respective order of indexing.
a.Copy tittikUser from the table and paste it into the collection ID field in the popup.
b.Scroll down to the Fields to Index section and enter the fields provided in the table sequentially.
- In the first field path, copy and paste userName (refer to the above table), and select Ascending from the dropdown next to your added field.
- Similarly, in the second field path, copy and paste userId and select Descending from the dropdown next to your added field.
c. Once you have added the fields to be indexed, scroll down and go to the Query Scope section. Under Query Scope, select the Collection option
d.Click on the Create Index button.
Step 9 : Once done, your index will be created and displayed in the Composite Index section.Similarly, add all the index values provided in the table sequentially following the same steps as mentioned above. Once done, your added indexes will be displayed in the Composite Index section. Note: Ensure to add all the indexes correctly to successfully configure the Tik-Tik app.
Once you have added the indexes, you need to define the Database Rules. Click the Rules tab in the Cloud Firestore section.
Step 10 : Replace the existing code with the following code
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
Step 11 : Click on the Publish button.
Step 12 : Once you have replaced the code, your published changes will be propagated.Next, you need to define the Storage Rules. Click Storage under Build in the side menu.Step 13 : On your Storage dashboard, click on the Rules tab.
Step 14 : Replace the existing code with the following code
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}
Step 15 : Click on the Publish button.
Step 16 : Once done, your published changes will be propagated. And click on the gear icon in the top left.
Step 17 : Click on users and permissions
Step 18 : Under Project Settings, Click on Service Accounts
Step 19 : Click on Generate New Private Key to generate a private key file for your service account.
Step 20 : After clicking on Generate New Private Key, a pop-up will open for confirmation. Click on Generate Key and securely store the JSON file containing the key.
Step 21 : Upload the downloaded file on the creator software.