This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is the index.js file in which we write our cloud functions | |
| const https = require('https'); | |
| const functions = require('firebase-functions'); | |
| // Function that listens to a firestore events | |
| exports.messageSniffer = functions.firestore | |
| .document('forms/{userName}') | |
| .onCreate(event => { | |
| var dataWritten = event.data.data(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var provider = new firebase.auth.GoogleAuthProvider(); | |
| document.getElementById('signIn').addEventListener('click', function (e) { | |
| firebase.auth().signInWithRedirect(provider); | |
| }); | |
| document.getElementById('signOut').addEventListener('click', function (e) { | |
| firebase.auth().signOut() | |
| .then(function () { | |
| console.log('User signed out'); | |
| }).catch(function (error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const firestore = firebase.firestore(); | |
| const documentRef = firestore.collection("forms"); | |
| function saveFormToFirestore(name, company, email, phone, message) { | |
| documentRef.doc(name).set({ | |
| name: name, | |
| company: company, | |
| email: email, | |
| phone: phone, | |
| message: message |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var storageRef = firebase.storage().ref('media_content'); | |
| document.getElementById('fileUpload').addEventListener('change', function (e) { | |
| var fileToUpload = e.target.files[0]; | |
| var fileToUploadRef = storageRef.child(fileToUpload.name); | |
| var task = fileToUploadRef.put(fileToUpload); | |
| // The put method returns an observer called state_changed that can raise the events: running / progress / pause. | |
| // We can use these events to manage UI elements like a progress bar. | |
| // A template for that would be: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Credits to the awesome Brad Traversy, check out this video at: https://www.youtube.com/watch?v=PP4Tr0l08NE | |
| var messagesRef = firebase.database().ref('messages'); | |
| document.getElementById('contactForm').addEventListener('submit', submitForm); | |
| function submitForm(e) { | |
| e.preventDefault(); //prevent reloading the html page | |
| var name = getInputVal('name'); |