How to Setup Indexes and Storage Rules in Firebase for your Tik-Tik app | Appy Pie Help

How to Setup Indexes and Storage Rules in Firebase for your Tik-Tik app?

Follow the below steps to setup Indexes and Storage Rules in Firebase for your Tik-Tik 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 video_comment appId Ascending
    video_id Ascending
    created Ascending
2 videos appId Descending
    user_id Descending
    created Descending
3 follow_users appId Ascending
    followed_user_id Ascending
    created Descending
4 follow_users appId Ascending
    follower_user_id Ascending
    created Descending
5 video_comment appId Ascending
    video_id Ascending
    created Descending
6 video_like_dislike action Ascending
    appId Ascending
    user_id Ascending
    created Descending
7 videos appId Ascending
    created Descending
8 fav_sound appId Ascending
    user_id Ascending
    created 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 video_comment and fields to be indexed include appID, video_id, and created with their respective order of indexing.

a.Copy video_comment 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 appId (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 video_id and select Ascending from the dropdown next to your added field.

  • Click Add field to add a new field.
  • In this field,  copy and paste created and select Ascending 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.e.Once done, your index will be created and displayed in the Composite Index section.
Step 9 : 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;

    }

  }

}

Step 15 : Click on the Publish button.

Step 16 : Once done, your published changes will be propagated.

Share this :

Was this article helpful?