Skip to content

Latest commit

 

History

History
37 lines (22 loc) · 2.45 KB

POSTINSTALL.md

File metadata and controls

37 lines (22 loc) · 2.45 KB

See it in action

You can test out this extension right away!

  1. Go to your Cloud Firestore dashboard in the Firebase console.

  2. Call the HTTP function passing an object with the properties described in the README. You need to specify the type of change you'd like to execute, the collection you wish to add the document to, the fieldName you want to ensure uniqueness, and the document itself.

  3. In a few seconds, you'll see a new collection in Firestore with a new document, that document will have as the key the value of the field of the document you sent to the function.

  4. This newly created collection and documents will prevent the client creating documents with duplicate values for the specified field, since we're using transactions inside the function that check the uniqueness of the specified field.

  5. You have the option to hash the field selecting 'Yes' when prompted to hash the field upon installation, due to constraints on document IDs.

  6. You also have the option to require auth selecting 'Yes' when prompted to require auth upon installation, since you may want this function to be invoked only by authenticated users.

Using the extension

Call the function with the collection users and fieldName username, with a document with id exampleId with the string "bob1234" as the value to the field username will result in the following document written in the collection users-username:

{
  bob1234: {
    id: exampleId,
    username: bob1234,
  },
}

If you opted in to hash the field, instead of "bob1234", you'll see a hashed value as the document id.

Now, if a client-side app wants to create / update a document with the string "bob1234" to the field username in users, the function will return an error with a 'already-exists': code. For creating, updating and delting, the parameters are always change, collection, fieldName and document, the change should always be one between CREATE, UPDATE, and DELETE, collection and fieldName should always be valid Firestore strings since they'll be used as collection and field names respectively, and the document should always contain the id as a field.

Monitoring

As a best practice, you can monitor the activity of your installed extension, including checks on its health, usage, and logs.