An open API service indexing awesome lists of open source software.

https://github.com/codeekage/firebase-cloud-functions-microservice

Microservice designed with Firebase Cloud Functions and Firestore
https://github.com/codeekage/firebase-cloud-functions-microservice

Last synced: 8 months ago
JSON representation

Microservice designed with Firebase Cloud Functions and Firestore

Awesome Lists containing this project

README

          

# Firestore Bookstore (firebase-cloud-functions-microservice)
Microservice designed with Firebase Cloud Functions and Firestore

## Features

- Authentication
- Email Verification on new sign ups
- Unverified emails should deny read and write access
- Email Notification on new books arrival
- The email should also contain details and a link to view the newly added book

## Setups

### Installations

Ensure you have the following installed before running `npm install`
- Node.js
- NPM
- Firebase Tools

## API_KEY

Obtain **Application API_KEY** from Firebase Configs and create `keys.ts` in the root directory of the `functions` folder

```javascript

export const firebaseConfig = {
apiKey: "AXXXXXXXXXXXXXXXXXXXXXXXQ",
authDomain: ".firebaseapp.com",
databaseURL: "https://.firebaseio.com",
projectId: "",
storageBucket: ".appspot.com",
messagingSenderId: "XXXXXXXXXX",
appId: "XXXXXXXXXXXXXXXXXXXXXXXXX"
}

```

## Upgrade Firebase Account
You'd want to upgrade your Firebase Project from the Free Tier to Blaze. Without the upgrade the application will resolve to a _netwowrk outofbound ERROR_

## Testing Application
- Run `npm run deploy` to Deploy or `npm run serve` to test the Cloud Functions
> NB: If the emulator fails to run please ensure you are running `firebase-tools 6.9.3`

## Setup Twilio SendGrid

To send emails when a new book is added to your users
- Create a Twilio SendGrid Account https://sendgrid.com
- Obtain API_KEY from `sendgrid`
- Update `keys.ts` in the root directory of the `functions` folder

```javascript
......

export const SG_APIKEY = 'SG.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

````

## Existing Functionalities

#### Routes
- **auth** `/auth`
- [POST] `/login` - Assigns User-Token for `firebase security rules`
- [POST] `/signup` - Creates a new user
- [GET] `/logout` - Remove User-Token

- **user** `/user`
- [GET] `/profile` - Retrives currently logged-in user's profile
- [PUT] `/update` - Update Currently logged in user's profile

-**book** `/book`
- [POST] `/add` - Add a new book to Firestore
- [GET] `/fetch` - Retrives all books from Firestors
- [GET] `/fetch/:id` - Retrive book with the `id` of `req.params.id`
- [PUT] `/update/:id`- Update book with the `id` of `req.params.id`
- [DELETE] `/remove/:id` - Delete book with the `id` of `req.params.id`

#### Triggers

- **onCreateUser** - Trigged when a user signsup and sends email using SendGrid
- **onBookArrival** Trigged when a new book is created and sends email using SendGrid

[Read more...](https://medium.com/@codeekage/building-scalable-applications-with-google-cloud-services-part-5-microservices-with-firebase-96819c70574d)