https://github.com/deanc/buyxiny.com
Repository for buyxiny.com
https://github.com/deanc/buyxiny.com
gatsby
Last synced: 3 months ago
JSON representation
Repository for buyxiny.com
- Host: GitHub
- URL: https://github.com/deanc/buyxiny.com
- Owner: deanc
- License: mit
- Created: 2019-12-15T20:05:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T12:06:14.000Z (over 3 years ago)
- Last Synced: 2025-06-18T00:38:53.457Z (about 1 year ago)
- Topics: gatsby
- Language: JavaScript
- Homepage: https://buyxiny.com
- Size: 2.43 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 2. Firestore collections
Create a project and add three collections:
- `items`
- `countries`
- `locations`
As firestore is schema-less I can't provide a schema, but will add required fields for documents in each
collection in due course.
You will need to set up firebase rules like so:
```
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isPublic() {
return resource.data.active == 1;
}
function isLoggedIn() {
return request.auth.uid != null;
}
function isAuthor() {
return request.auth.uid == request.resource.data.author;
}
function isAdmin() {
return request.auth.uid != null && 'admin' in request.auth.token.roles;
}
function isModerator() {
return request.auth.uid != null && 'moderator' in request.auth.token.roles;
}
function hasRole() {
return isAdmin() || isModerator();
}
match /countries/{country} {
allow read;
allow write,update,delete: if isAdmin();
}
match /locations/{location} {
allow read;
allow create: if isLoggedIn();
allow update: if isAuthor() || hasRole();
allow delete: if hasRole();
}
match /items/{item} {
allow read;
allow create: if isLoggedIn();
allow update: if isAuthor() || hasRole();
allow delete: if hasRole();
}
}
}
```
Add an index to the `items` collection across the following fields: `type Ascending name Ascending`
# 3. Search
We will use Algolia for search. Sign up and get your necessary API keys. Create two indices called `Items` and `Locations`.
# 4. Firebase functions
We will use Firebase functions for two purposes:
- Pinging netlify to rebuild when firestore receives changes
- Syncings firestore data with Algolia's search index
Instructions:
- Make sure you have the `firebase-tools` installed: `npm install -g firebase-tools`
- Navigate to `firebase-functions` and type `firebase init` and authenticate against your account
- `firebase init` and choose `Functions: Configure and deploy Cloud Functions`
- Select the `buyxiny` project
- Follow the necessary instructions
- Set the following env variable to point to your netlify build hook: `firebase functions:config:set netlify.buildhook="https://api.netlify.com/build_hooks/"` and confirm it's set by typing: `firebase functions:config:get`
- Set the following env variable to set your Algolia app id: `firebase functions:config:set algolia.appid="" algolia.apikey=""`
- Run `firebase deploy`
- This should deploy all the firebase functions for Netlify build hooks, and syncings Firestore CRUD operations with the Algolia search index.