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 functions = require('firebase-functions'); | |
exports.calculateOrder = functions.firestore | |
.document("orders/{orderId}") | |
.onWrite(async (change, context) => { | |
console.log('begin trigger'); | |
return change.after.ref.update({ | |
orderUpdated: true | |
}); |
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
import { google } from 'googleapis'; | |
app.post('/sendSMS', function (req, res) { | |
const { phoneNumber, recaptchaToken } = req.body; | |
const identityToolkit = google.identitytoolkit({ | |
auth: 'GCP_API_KEY', | |
version: 'v3', | |
}); | |
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
import { google } from 'googleapis'; | |
app.post('/sendSMS', function (req, res) { | |
const { phoneNumber, recaptchaToken } = req.body; | |
const identityToolkit = google.identitytoolkit({ | |
auth: 'GCP_API_KEY', | |
version: 'v3', | |
}); | |
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
// set-up an invisible recaptcha. 'sendCode` is button element id | |
// <button id="sendCode">Send Code</button> | |
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('sendCode', { | |
'size': 'invisible', | |
'callback': function (recapchaToken) { | |
// reCAPTCHA solved, send recapchaToken and phone number to backend. | |
// a REST call to your backend | |
request.post({ | |
url: 'https://your-rest-api', |
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
export const deletePhoto = functions.firestore | |
.document("posts/{postId}") | |
.onUpdate((change, context) => { | |
// Get an object representing the document | |
const updatedPost = change.after.data() as any; | |
// ...or the previous value before this update | |
const oldPost = change.before.data() as any; |
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
import * as functions from "firebase-functions"; | |
import * as admin from "firebase-admin"; | |
const firebase = admin.initializeApp(); | |
export const deletePhotos = functions.firestore | |
.document("posts/{postId}") | |
.onDelete((snap, context) => { | |
const { postId } = context.params; | |
const bucket = firebase.storage().bucket(); |
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
import { combineLatest } from 'rxjs'; | |
var californiaOrColorado$ = combineLatest(california$, colorado$) | |
.pipe( | |
map((cities) => { | |
// Destructure the values to combine a single array. | |
var [californiaCities, coloradoCities] = cities; | |
return [ | |
//spread the arrays out to combine as one array | |
...californiaCities, |
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
import { collection } from 'rxfire/firestore'; | |
import { map } from 'rxjs/operators'; | |
// Query for California | |
var californiaRef = citiesRef.where("state", "==", "CA"); | |
// Query for Colorado | |
var coloradoRef = citiesRef.where("state", "==", "CO"); | |
// Create Observables ready for subscribe(). |
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
<ul> | |
<li *ngFor="let cities of caOrCoCities$ | async as caOrCoCities"> | |
... | |
</li> | |
</ul> |
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
caOrCoCities$: Observable<City[]>; | |
... | |
const californiaRef = this.angularFirestore | |
.collection("cities", ref => ref.where("state","==","CA")); | |
const coloradoRef = this.angularFirestore | |
.collection("cities", ref => ref.where("state","==","CO")); | |
this.caOrCoCities$ = Observable | |
.combineLatest(californiaRef.valueChanges(), | |
coloradoRef.valueChanges()) | |
.switchMap(cities => { |