Cloud Functions for Firebase
Firebase launched its beta release of Cloud Functions for Firebase which is similar to using of Cloud Functions on Google Cloud Platform.
Send welcome notification emails to the users for subscribing.
Use the GitHub repository to get the entire code: https://github.com/firebase/functions-samples/blob/master/quickstarts/email-users
- Copy or clone the repository in your computer.
Now go to your Firebase Console
- Create a Firebase Project using the Firebase Console.
- Enable the Google Provider in the Auth section.
- Paste the Web initialization snippet from: Firebase Console > Overview > Add Firebase to your web app in the public/index.html where the TODO is located.
Install Firebase CLI in your computer
- If you don't have NodeJS installed already, install it from https://nodejs.org/en/ (Make sure to have the updated version of NodeJS installed on your computer.)
- Open command prompt/terminal and install it with npm install -g firebase-tools and then configure it with firebase login
- To choose your project you created now ==> Configure the CLI locally by using firebase use --add and select your project in the list.
- Install dependencies locally by running: cd functions; npm install; cd -
Set Google Cloud environment variables
Set the gmail.email and gmail.password Google Cloud environment variables to match the email and password of the Gmail account used to send emails. For this open the command prompt or terminal and type the following Firebase CLI command:
firebase functions:config:set gmail.email="email@example.com" gmail.password="secretpassword"
Deploy the project and test
- To deploy the project open the cmd/terminal and use the command firebase deploy to start the deployment.
- Once it gets done, use the command to open the site in browser firebase open hosting:site or manually do it from the url displayed.