From f003ef8c725f0039215badc00f888c41620bb8d2 Mon Sep 17 00:00:00 2001 From: Boda <6238558+bodazhao@users.noreply.github.com> Date: Fri, 5 Jun 2020 18:27:21 +0100 Subject: [PATCH 001/235] Fix field typo to plural (#28) The sample data shows the field is named 'regions', not 'region' --- firestore/test.firestore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index 1ea998a1..9fe4bd4b 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -868,7 +868,7 @@ describe("firestore", () => { // [END in_filter] // [START in_filter_with_array] - citiesRef.where('region', 'in', + citiesRef.where('regions', 'in', [['west_coast', 'east_coast']]); // [END in_filter_with_array] }); From 5bdaa577b964bfa5e987fc1ad5ddc8ce2b48e013 Mon Sep 17 00:00:00 2001 From: Arthur Thompson Date: Mon, 20 Jul 2020 17:42:41 -0700 Subject: [PATCH 002/235] add installation snippets --- installations/index.js | 47 ++++++++++++++++++++++++++++++++++++++ installations/package.json | 11 +++++++++ 2 files changed, 58 insertions(+) create mode 100644 installations/index.js create mode 100644 installations/package.json diff --git a/installations/index.js b/installations/index.js new file mode 100644 index 00000000..e13a2c16 --- /dev/null +++ b/installations/index.js @@ -0,0 +1,47 @@ +const firebase = require("firebase"); + +async function deleteInstallation() { + try { + // [START delete_installation] + await firebase.installations().delete(); + // [END delete_installation] + } catch (err) { + console.error('Unable to delete installation: ', err); + } +} + +async function getInstallationId() { + try { + // [START get_installation_id] + const installationId = await firebase.installations().getId(); + console.log(installationId); + // [END get_installation_id] + } catch (err) { + console.error('Unable to get Installation ID: ', err); + } +} + +async function getAuthenticationToken() { + try { + // [START get_auth_token] + const authToken = await firebase.installations() + .getToken(/* forceRefresh */ true); + console.log(authToken); + // [END get_auth_token] + } catch (err) { + console.error('Unable to get auth token: ', err); + } +} + +async function setOnIdChangeHandler() { + try { + // [START set_id_change_handler] + await firebase.installations().onIdChange((newId) => { + console.log(newId); + // TODO: Handle new installation ID. + }); + // [START set_id_change_handler] + } catch (err) { + console.error('Unable to set ID change handler: ', err); + } +} \ No newline at end of file diff --git a/installations/package.json b/installations/package.json new file mode 100644 index 00000000..f5ffa198 --- /dev/null +++ b/installations/package.json @@ -0,0 +1,11 @@ +{ + "name": "installations", + "version": "1.0.0", + "description": "", + "scripts": {}, + "author": "", + "license": "Apache 2.0", + "dependencies": { + "firebase": "^7.16.1" + } +} From 3eabc6557db7cbc30b12e25dc08ed1a384f04ae1 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Jul 2020 14:48:55 +0100 Subject: [PATCH 003/235] Add package.json files and lerna --- auth/link-multiple-accounts.js | 8 ++++---- auth/package.json | 2 -- firebaseapp/package.json | 7 +------ firestore/emulator-suite.js | 7 ++++--- firestore/package.json | 9 +++++++++ functions/emulator-suite.js | 3 ++- functions/package.json | 9 +++++++++ installations/package.json | 2 -- lerna.json | 12 ++++++++++++ package.json | 11 +++++++++++ 10 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 firestore/package.json create mode 100644 functions/package.json create mode 100644 lerna.json create mode 100644 package.json diff --git a/auth/link-multiple-accounts.js b/auth/link-multiple-accounts.js index b4026d85..1a305b40 100644 --- a/auth/link-multiple-accounts.js +++ b/auth/link-multiple-accounts.js @@ -1,10 +1,10 @@ // These samples are intended for Web so this import would normally be // done in HTML however using modules here is more convenient for // ensuring sample correctness offline. -var firebase = require('firebase'); -var auth = firebase.auth(); +const firebase = require('firebase'); +const auth = firebase.auth(); -var MyUserDataRepo = function() {}; +const MyUserDataRepo = function() {}; MyUserDataRepo.prototype.merge = function(data1, data2) { // TODO(you): How you implement this is specific to your application! @@ -176,4 +176,4 @@ function unlink() { // ... }); // [END auth_unlink_provider] -} \ No newline at end of file +} diff --git a/auth/package.json b/auth/package.json index 3dd4e43d..25ce0f7d 100644 --- a/auth/package.json +++ b/auth/package.json @@ -1,9 +1,7 @@ { "name": "auth", "version": "1.0.0", - "description": "", "scripts": {}, - "author": "", "license": "Apache 2.0", "dependencies": { "firebase": "^7.12.0" diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 92552bbe..d219d4ae 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -1,12 +1,7 @@ { "name": "firebaseapp", "version": "1.0.0", - "description": "", - "main": "firebaseapp.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", + "scripts": {}, "license": "Apache-2.0", "dependencies": { "firebase": "^7.9.2" diff --git a/firestore/emulator-suite.js b/firestore/emulator-suite.js index d50a58ca..87b8f50d 100644 --- a/firestore/emulator-suite.js +++ b/firestore/emulator-suite.js @@ -1,9 +1,10 @@ +const firebase = require('firebase'); +require('firebase/firestore'); function onDocumentReady(firebaseApp) { - //[START fs_emulator_connect] - // firebaseApp previously initialized using firebase.initializeApp(). - var db = firebaseApp.firestore(); + // Firebase previously initialized using firebase.initializeApp(). + var db = firebase.firestore(); if (location.hostname === "localhost") { db.settings({ host: "localhost:8080", diff --git a/firestore/package.json b/firestore/package.json new file mode 100644 index 00000000..3e2d7419 --- /dev/null +++ b/firestore/package.json @@ -0,0 +1,9 @@ +{ + "name": "firestore", + "version": "1.0.0", + "scripts": {}, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^7.17.1" + } +} diff --git a/functions/emulator-suite.js b/functions/emulator-suite.js index dd5456a3..5909b58e 100644 --- a/functions/emulator-suite.js +++ b/functions/emulator-suite.js @@ -1,6 +1,7 @@ +const firebase = require("firebase"); +require("firebase/functions"); function emulatorSettings() { - // [START functions_emulator_connect] firebase.functions().useFunctionsEmulator("http://localhost:5001") // [END functions_emulator_connect] diff --git a/functions/package.json b/functions/package.json new file mode 100644 index 00000000..fbdb2c70 --- /dev/null +++ b/functions/package.json @@ -0,0 +1,9 @@ +{ + "name": "functions", + "version": "1.0.0", + "scripts": {}, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^7.17.1" + } +} diff --git a/installations/package.json b/installations/package.json index f5ffa198..ed890697 100644 --- a/installations/package.json +++ b/installations/package.json @@ -1,9 +1,7 @@ { "name": "installations", "version": "1.0.0", - "description": "", "scripts": {}, - "author": "", "license": "Apache 2.0", "dependencies": { "firebase": "^7.16.1" diff --git a/lerna.json b/lerna.json new file mode 100644 index 00000000..1cf4129b --- /dev/null +++ b/lerna.json @@ -0,0 +1,12 @@ +{ + "lerna": "2.8.0", + "packages": [ + "auth", + "database", + "firebaseapp", + "firestore", + "functions", + "installations" + ], + "version": "1.0.0" +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..c4dda6e8 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "snippets-web", + "version": "1.0.0", + "scripts": { + "lerna-bootstrap": "lerna bootstrap" + }, + "license": "Apache-2.0", + "devDependencies": { + "lerna": "^3.22.1" + } +} From 72feb40f9756bf53b4ab6a7151bc452c2aa87956 Mon Sep 17 00:00:00 2001 From: Arthur Thompson Date: Mon, 24 Aug 2020 16:18:18 -0700 Subject: [PATCH 004/235] Use consistent auth token variable Other snippets for installations auth token is called `installationToken` using that here instead. --- installations/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/installations/index.js b/installations/index.js index e13a2c16..79675e6e 100644 --- a/installations/index.js +++ b/installations/index.js @@ -24,9 +24,9 @@ async function getInstallationId() { async function getAuthenticationToken() { try { // [START get_auth_token] - const authToken = await firebase.installations() + const installationToken = await firebase.installations() .getToken(/* forceRefresh */ true); - console.log(authToken); + console.log(installationToken); // [END get_auth_token] } catch (err) { console.error('Unable to get auth token: ', err); @@ -44,4 +44,4 @@ async function setOnIdChangeHandler() { } catch (err) { console.error('Unable to set ID change handler: ', err); } -} \ No newline at end of file +} From 9dc0d43b06ffe69f2f3a7609fa8203c238ef271d Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Wed, 2 Sep 2020 14:02:48 -0400 Subject: [PATCH 005/235] Add compilation checks (#34) --- .github/workflows/test.yml | 32 +++++++++ .gitignore | 5 +- README.md | 7 ++ auth/link-multiple-accounts.js | 21 ++---- auth/package.json | 4 +- database/emulator-suite.js | 7 +- database/package.json | 11 +++ database/read-and-write.js | 6 ++ firebaseapp/firebaseapp.js | 4 +- firebaseapp/package.json | 4 +- firestore/index.html | 2 +- firestore/package.json | 10 ++- firestore/test.firestore.js | 99 +++++++++++++++----------- firestore/test.solution-aggregation.js | 3 + firestore/test.solution-arrays.js | 3 + firestore/test.solution-counters.js | 3 + functions/emulator-suite.js | 4 +- functions/package.json | 4 +- installations/index.js | 3 +- installations/package.json | 2 +- package.json | 6 +- scripts/test.sh | 11 +++ tsconfig.json.template | 35 +++++++++ 23 files changed, 212 insertions(+), 74 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 database/package.json create mode 100755 scripts/test.sh create mode 100644 tsconfig.json.template diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..3452af7e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +name: CI Tests + +on: + - pull_request + - push + +env: + CI: true + +jobs: + unit: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: + - 10.x + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Cache npm + uses: actions/cache@v1 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }} + + - run: npm install + + - name: "Lint and Test" + run: ./scripts/test.sh diff --git a/.gitignore b/.gitignore index 074ab526..c3bf3b13 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ package-lock.json -node_modules \ No newline at end of file +node_modules + +tsconfig.json +dist/ diff --git a/README.md b/README.md index 75e2c2ac..f0f7a3bc 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,10 @@ on [firebase.google.com](https://firebase.google.com/docs/). ## Contributing We love contributions! See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines. + +## Build Status + +[![Actions Status][gh-actions-badge]][gh-actions] + +[gh-actions]: https://github.com/firebase/snippets-web/actions +[gh-actions-badge]: https://github.com/firebase/snippets-web/workflows/CI%20Tests/badge.svg diff --git a/auth/link-multiple-accounts.js b/auth/link-multiple-accounts.js index 1a305b40..e4888cab 100644 --- a/auth/link-multiple-accounts.js +++ b/auth/link-multiple-accounts.js @@ -36,11 +36,7 @@ function getProviders() { // [END auth_get_providers] } -function simpleLink() { - // This is just a dummy variable for sample purposes, the other - // snippets demonstrate how to get a real credential. - var credential = new firebase.auth.AuthCredential(); - +function simpleLink(credential) { // [START auth_simple_link] auth.currentUser.linkWithCredential(credential) .then(function(usercred) { @@ -52,11 +48,7 @@ function simpleLink() { // [END auth_simple_link] } -function anonymousLink() { - // This is just a dummy variable for sample purposes, the other - // snippets demonstrate how to get a real credential. - var credential = new firebase.auth.AuthCredential(); - +function anonymousLink(credential) { // [START auth_anonymous_link] auth.currentUser.linkWithCredential(credential) .then(function(usercred) { @@ -108,11 +100,7 @@ function linkWithRedirect() { // [END auth_get_redirect_result] } -function mergeAccounts() { - // This is just a dummy variable for sample purposes, the other - // snippets demonstrate how to get a real credential. - var newCredential = new firebase.auth.AuthCredential(); - +function mergeAccounts(newCredential) { // [START auth_merge_accounts] // The implementation of how you store your user data depends on your application var repo = new MyUserDataRepo(); @@ -150,7 +138,6 @@ function mergeAccounts() { // If there are errors we want to undo the data merge/deletion console.log("Sign In Error", error); repo.set(prevUser, prevUserData); - repo.set(currentUser, currentUserData); }); // [END auth_merge_accounts] } @@ -164,7 +151,7 @@ function makeEmailCredential() { // [END auth_make_email_credential] } -function unlink() { +function unlink(providerId) { var user = auth.currentUser; // [START auth_unlink_provider] diff --git a/auth/package.json b/auth/package.json index 25ce0f7d..63a838e7 100644 --- a/auth/package.json +++ b/auth/package.json @@ -1,7 +1,9 @@ { "name": "auth", "version": "1.0.0", - "scripts": {}, + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, "license": "Apache 2.0", "dependencies": { "firebase": "^7.12.0" diff --git a/database/emulator-suite.js b/database/emulator-suite.js index f2ad3366..1987822d 100644 --- a/database/emulator-suite.js +++ b/database/emulator-suite.js @@ -1,6 +1,11 @@ -function onDocumentReady(firebase) { +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +var firebase = require("firebase/app"); +require("firebase/database"); +function onDocumentReady(firebase) { //[START rtdb_emulator_connect] if (location.hostname === "localhost") { diff --git a/database/package.json b/database/package.json new file mode 100644 index 00000000..e3db58fe --- /dev/null +++ b/database/package.json @@ -0,0 +1,11 @@ +{ + "name": "database", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache 2.0", + "dependencies": { + "firebase": "^7.12.0" + } +} diff --git a/database/read-and-write.js b/database/read-and-write.js index 31df7504..9f410f37 100644 --- a/database/read-and-write.js +++ b/database/read-and-write.js @@ -1,3 +1,9 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +var firebase = require("firebase/app"); +require("firebase/database"); + // [START rtdb_write_new_user] function writeUserData(userId, name, email, imageUrl) { firebase.database().ref('users/' + userId).set({ diff --git a/firebaseapp/firebaseapp.js b/firebaseapp/firebaseapp.js index 2932104b..24b68294 100644 --- a/firebaseapp/firebaseapp.js +++ b/firebaseapp/firebaseapp.js @@ -1,4 +1,4 @@ -var firebase = require('@firebase/app'); +var firebase = require('firebase/app'); function multpleFirebaseApps() { // [START firebase_options] @@ -21,4 +21,4 @@ function multpleFirebaseApps() { // Access services, such as the Realtime Database // secondaryApp.database(); // [END firebase_secondary] -} \ No newline at end of file +} diff --git a/firebaseapp/package.json b/firebaseapp/package.json index d219d4ae..3ab5707b 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -1,7 +1,9 @@ { "name": "firebaseapp", "version": "1.0.0", - "scripts": {}, + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, "license": "Apache-2.0", "dependencies": { "firebase": "^7.9.2" diff --git a/firestore/index.html b/firestore/index.html index b3e00c45..adf572a4 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -7,7 +7,7 @@
- + diff --git a/firestore/package.json b/firestore/package.json index 3e2d7419..e2779ec4 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -1,9 +1,17 @@ { "name": "firestore", "version": "1.0.0", - "scripts": {}, + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, "license": "Apache-2.0", "dependencies": { "firebase": "^7.17.1" + }, + "devDependencies": { + "@types/chai": "^4.2.12", + "@types/mocha": "^8.0.3", + "chai": "^4.2.0", + "mocha": "^8.1.3" } } diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index 9fe4bd4b..f5131965 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -1,3 +1,35 @@ +var firebase = require('firebase/app'); +const { expect } = require('chai'); +require('firebase/firestore'); + +// [START city_custom_object] +class City { + constructor (name, state, country ) { + this.name = name; + this.state = state; + this.country = country; + } + toString() { + return this.name + ', ' + this.state + ', ' + this.country; + } +} + +// Firestore data converter +var cityConverter = { + toFirestore: function(city) { + return { + name: city.name, + state: city.state, + country: city.country + } + }, + fromFirestore: function(snapshot, options){ + const data = snapshot.data(options); + return new City(data.name, data.state, data.country) + } +} +// [END city_custom_object] + describe("firestore", () => { var db; before(() => { @@ -87,7 +119,7 @@ describe("firestore", () => { describe("collection('users')", () => { it("should add data to a collection", () => { - return output = + var output = // [START add_ada_lovelace] db.collection("users").add({ first: "Ada", @@ -101,10 +133,11 @@ describe("firestore", () => { console.error("Error adding document: ", error); }); // [END add_ada_lovelace] + return output; }); it("should get all users", () => { - return output = + var output = // [START get_all_users] db.collection("users").get().then((querySnapshot) => { querySnapshot.forEach((doc) => { @@ -112,10 +145,11 @@ describe("firestore", () => { }); }); // [END get_all_users] + return output; }); it("should add data to a collection with new fields", () => { - return output = + var output = // [START add_alan_turing] // Add a second document with a generated ID. db.collection("users").add({ @@ -131,6 +165,7 @@ describe("firestore", () => { console.error("Error adding document: ", error); }); // [END add_alan_turing] + return output; }); it("should loop through a watched collection", (done) => { @@ -180,7 +215,7 @@ describe("firestore", () => { }); it("should set a document", () => { - return output = + var output = // [START set_document] // Add a new document in collection "cities" db.collection("cities").doc("LA").set({ @@ -195,54 +230,29 @@ describe("firestore", () => { console.error("Error writing document: ", error); }); // [END set_document] + return output; }); it("should set document with a custom object converter", () => { - // [START city_custom_object] - class City { - constructor (name, state, country ) { - this.name = name; - this.state = state; - this.country = country; - } - toString() { - return this.name + ', ' + this.state + ', ' + this.country; - } - } - - // Firestore data converter - cityConverter = { - toFirestore: function(city) { - return { - name: city.name, - state: city.state, - country: city.country - } - }, - fromFirestore: function(snapshot, options){ - const data = snapshot.data(options); - return new City(data.name, data.state, data.country) - } - } - // [END city_custom_object] - return output = + var output = // [START set_custom_object] // Set with cityConverter db.collection("cities").doc("LA") .withConverter(cityConverter) .set(new City("Los Angeles", "CA", "USA")); // [END set_custom_object] + return output; }); it("should get document with a custom object converter", () => { - return output = + var output = // [START get_custom_object] db.collection("cities").doc("LA") .withConverter(cityConverter) .get().then(function(doc) { if (doc.exists){ // Convert to City object - city = doc.data(); + var city = doc.data(); // Use a City instance method console.log(city.toString()); } else { @@ -251,6 +261,7 @@ describe("firestore", () => { console.log("Error getting document:", error) }); // [END get_custom_object] + return output; }); it("should support batch writes", (done) => { @@ -413,15 +424,15 @@ describe("firestore", () => { }); it("should set a document", () => { var data = {}; - - return output = + var output = // [START cities_document_set] db.collection("cities").doc("new-city-id").set(data); // [END cities_document_set] + return output; }); it("should add a document", () => { - return output = + var output = // [START add_document] // Add a new document with a generated id. db.collection("cities").add({ @@ -435,6 +446,7 @@ describe("firestore", () => { console.error("Error adding document: ", error); }); // [END add_document] + return output; }); it("should add an empty a document #UNVERIFIED", () => { @@ -495,7 +507,7 @@ describe("firestore", () => { }) it("should delete a document", () => { - return output = + var output = // [START delete_document] db.collection("cities").doc("DC").delete().then(function() { console.log("Document successfully deleted!"); @@ -503,6 +515,7 @@ describe("firestore", () => { console.error("Error removing document: ", error); }); // [END delete_document] + return output; }); it("should handle transactions #FIXME #UNVERIFIED", () => { @@ -653,7 +666,7 @@ describe("firestore", () => { }).timeout(5000); it("should get multiple documents from a collection", () => { - return output = + var output = // [START get_multiple] db.collection("cities").where("capital", "==", true) .get() @@ -667,10 +680,11 @@ describe("firestore", () => { console.log("Error getting documents: ", error); }); // [END get_multiple] + return output; }).timeout(5000); it("should get all documents from a collection", () => { - return output = + var output = // [START get_multiple_all] db.collection("cities").get().then(function(querySnapshot) { querySnapshot.forEach(function(doc) { @@ -679,6 +693,7 @@ describe("firestore", () => { }); }); // [END get_multiple_all] + return output; }) it("should listen on multiple documents #UNVERIFIED", (done) => { @@ -895,7 +910,7 @@ describe("firestore", () => { // [START invalid_range_filters] citiesRef.where("state", ">=", "CA").where("population", ">", 100000); // [END invalid_range_filters] - }).to.throwException(); + }).to.throw(); }); it("should order and limit", () => { @@ -939,7 +954,7 @@ describe("firestore", () => { // [START invalid_filter_and_order] citiesRef.where("population", ">", 100000).orderBy("country") // [END invalid_filter_and_order] - }).to.throwException(); + }).to.throw; }); it("should handle startAt", () => { diff --git a/firestore/test.solution-aggregation.js b/firestore/test.solution-aggregation.js index 024a3a58..6075561d 100644 --- a/firestore/test.solution-aggregation.js +++ b/firestore/test.solution-aggregation.js @@ -1,3 +1,6 @@ +var firebase = require('firebase/app'); +require('firebase/firestore'); + // [START sample_doc] var arinellDoc = { name: 'Arinell Pizza', diff --git a/firestore/test.solution-arrays.js b/firestore/test.solution-arrays.js index d233b0c6..4e1215ae 100644 --- a/firestore/test.solution-arrays.js +++ b/firestore/test.solution-arrays.js @@ -1,3 +1,6 @@ +var firebase = require('firebase/app'); +require('firebase/firestore'); + let postsWithArray = [ // [START post_with_array] // Sample document in the 'posts' collection. diff --git a/firestore/test.solution-counters.js b/firestore/test.solution-counters.js index e831807e..ef0fd3bc 100644 --- a/firestore/test.solution-counters.js +++ b/firestore/test.solution-counters.js @@ -1,3 +1,6 @@ +var firebase = require('firebase/app'); +require('firebase/firestore'); + var db; // [START create_counter] diff --git a/functions/emulator-suite.js b/functions/emulator-suite.js index 5909b58e..87c22b73 100644 --- a/functions/emulator-suite.js +++ b/functions/emulator-suite.js @@ -1,5 +1,5 @@ -const firebase = require("firebase"); -require("firebase/functions"); +var firebase = require('firebase/app'); +require('firebase/functions'); function emulatorSettings() { // [START functions_emulator_connect] diff --git a/functions/package.json b/functions/package.json index fbdb2c70..aecac9f7 100644 --- a/functions/package.json +++ b/functions/package.json @@ -1,7 +1,9 @@ { "name": "functions", "version": "1.0.0", - "scripts": {}, + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, "license": "Apache-2.0", "dependencies": { "firebase": "^7.17.1" diff --git a/installations/index.js b/installations/index.js index 79675e6e..7f021e3f 100644 --- a/installations/index.js +++ b/installations/index.js @@ -1,4 +1,5 @@ -const firebase = require("firebase"); +const firebase = require("firebase/app"); +require("firebase/installations"); async function deleteInstallation() { try { diff --git a/installations/package.json b/installations/package.json index ed890697..78d5f8b4 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.16.1" + "firebase": "^7.19.1" } } diff --git a/package.json b/package.json index c4dda6e8..9d3c88b5 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,12 @@ "name": "snippets-web", "version": "1.0.0", "scripts": { - "lerna-bootstrap": "lerna bootstrap" + "lerna-bootstrap": "lerna bootstrap --no-ci", + "lerna-compile": "lerna run compile" }, "license": "Apache-2.0", "devDependencies": { - "lerna": "^3.22.1" + "lerna": "^3.22.1", + "typescript": "^3.8.3" } } diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 00000000..7527670e --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,11 @@ +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +# 0) Bootstrap +echo "Bootstrapping..." +npm run lerna-bootstrap + +# 1) "Compile" the code +echo "Compiling..." +npm run lerna-compile diff --git a/tsconfig.json.template b/tsconfig.json.template new file mode 100644 index 00000000..072197f8 --- /dev/null +++ b/tsconfig.json.template @@ -0,0 +1,35 @@ +{ + "compilerOptions": { + /* Basic Options */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + "lib": ["dom"], /* Specify library files to be included in the compilation. */ + "allowJs": true, /* Allow javascript files to be compiled. */ + "checkJs": true, /* Report errors in .js files. */ + "outDir": "./dist", /* Redirect output structure to the directory. */ + "noEmit": true, /* Do not emit outputs. */ + "resolveJsonModule": true, + "typeRoots": [ + "./node_modules/@types" + ], + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ + "strictNullChecks": false, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + "noUnusedLocals": false, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} From 0fffbaf7cb323aed4a3899ccd57fbd6391318521 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 14 Sep 2020 09:20:36 -0400 Subject: [PATCH 006/235] Begin snippets for JS SDK vNext (#32) --- .github/workflows/test.yml | 15 +- firestore-next/emulator-suite.js | 17 + firestore-next/package.json | 17 + firestore-next/test.firestore.js | 1191 +++++++++++++++++ firestore-next/test.solution-aggregation.js | 41 + firestore-next/test.solution-arrays.js | 100 ++ firestore-next/test.solution-counters.js | 97 ++ firestore/package.json | 2 +- firestore/test.firestore.js | 5 +- functions-next/.gitignore | 1 + functions-next/emulator-suite.js | 32 + functions-next/package.json | 12 + lerna.json | 2 + package.json | 2 + scripts/checkdirty.sh | 15 + scripts/package.json | 9 + scripts/separate-snippets.ts | 197 +++ scripts/test.sh | 11 - snippets/README.md | 26 + .../emulator-suite/fs_emulator_connect.js | 19 + .../test-firestore/add_ada_lovelace.js | 19 + .../test-firestore/add_alan_turing.js | 22 + .../test-firestore/add_document.js | 15 + .../test-firestore/add_rating_transaction.js | 35 + .../array_contains_any_filter.js | 11 + .../test-firestore/array_contains_filter.js | 9 + .../test-firestore/chain_filters.js | 11 + .../test-firestore/cities_document_set.js | 10 + .../test-firestore/city_custom_object.js | 32 + .../test-firestore/collection_reference.js | 10 + .../test-firestore/data_types.js | 24 + .../test-firestore/delete_collection.js | 48 + .../test-firestore/delete_document.js | 10 + .../test-firestore/detach_listener.js | 18 + .../test-firestore/disable_network.js | 15 + .../test-firestore/doc_reference.js | 10 + .../doc_reference_alternative.js | 10 + .../test-firestore/enable_network.js | 14 + .../test-firestore/example_data.js | 31 + .../test-firestore/example_filters.js | 10 + .../test-firestore/filter_and_order.js | 10 + .../fs_collection_group_query.js | 14 + .../fs_collection_group_query_data_setup.js | 53 + .../test-firestore/fs_setup_cache.js | 12 + .../test-firestore/get_all_users.js | 13 + .../test-firestore/get_custom_object.js | 19 + .../test-firestore/get_document.js | 18 + .../test-firestore/get_document_options.js | 21 + .../test-firestore/get_multiple.js | 16 + .../test-firestore/get_multiple_all.js | 14 + .../test-firestore/handle_listen_errors.js | 17 + .../test-firestore/in_filter.js | 10 + .../test-firestore/in_filter_with_array.js | 10 + .../test-firestore/initialize_persistence.js | 22 + .../invalid_filter_and_order.js | 10 + .../test-firestore/invalid_range_filters.js | 10 + .../test-firestore/listen_diffs.js | 23 + .../test-firestore/listen_document.js | 12 + .../test-firestore/listen_document_local.js | 13 + .../test-firestore/listen_for_users.js | 16 + .../test-firestore/listen_multiple.js | 17 + .../test-firestore/listen_with_metadata.js | 15 + .../test-firestore/new_document.js | 14 + .../test-firestore/order_and_end.js | 10 + .../test-firestore/order_and_limit.js | 10 + .../test-firestore/order_and_limit_desc.js | 10 + .../test-firestore/order_and_start.js | 10 + .../test-firestore/order_multiple.js | 10 + .../firestore-next/test-firestore/paginate.js | 23 + .../server_timestamp_resolution_options.js | 26 + .../test-firestore/set_custom_object.js | 12 + .../test-firestore/set_document.js | 15 + .../test-firestore/set_with_merge.js | 11 + .../test-firestore/simple_queries.js | 13 + .../test-firestore/simple_queries_again.js | 11 + .../test-firestore/start_doc.js | 15 + .../test-firestore/start_multiple_orderby.js | 19 + .../test-firestore/subcollection_reference.js | 10 + .../test-firestore/transaction.js | 23 + .../test-firestore/transaction_promise.js | 32 + .../test-firestore/update_delete_field.js | 15 + .../test-firestore/update_document.js | 15 + .../test-firestore/update_document_array.js | 20 + .../update_document_increment.js | 15 + .../test-firestore/update_document_nested.js | 22 + .../update_with_server_timestamp.js | 15 + .../test-firestore/use_from_cache.js | 20 + .../test-firestore/valid_filter_and_order.js | 10 + .../test-firestore/valid_range_filters.js | 11 + .../test-firestore/write_batch.js | 26 + .../get_collection_ratings.js | 11 + .../test-solution-aggregation/sample_doc.js | 12 + .../test-solution-arrays/post_with_array.js | 16 + .../test-solution-arrays/post_with_map.js | 16 + .../post_with_map_advanced.js | 16 + .../test-solution-arrays/query_in_category.js | 14 + .../query_in_category_timestamp.js | 12 + .../query_in_category_timestamp_invalid.js | 12 + .../test-solution-counters/create_counter.js | 24 + .../test-solution-counters/get_count.js | 20 + .../increment_counter.js | 17 + .../emulator-suite/functions_callable_call.js | 16 + .../functions_emulator_connect.js | 12 + 103 files changed, 3164 insertions(+), 17 deletions(-) create mode 100644 firestore-next/emulator-suite.js create mode 100644 firestore-next/package.json create mode 100644 firestore-next/test.firestore.js create mode 100644 firestore-next/test.solution-aggregation.js create mode 100644 firestore-next/test.solution-arrays.js create mode 100644 firestore-next/test.solution-counters.js create mode 100644 functions-next/.gitignore create mode 100644 functions-next/emulator-suite.js create mode 100644 functions-next/package.json create mode 100755 scripts/checkdirty.sh create mode 100644 scripts/package.json create mode 100644 scripts/separate-snippets.ts delete mode 100755 scripts/test.sh create mode 100644 snippets/README.md create mode 100644 snippets/firestore-next/emulator-suite/fs_emulator_connect.js create mode 100644 snippets/firestore-next/test-firestore/add_ada_lovelace.js create mode 100644 snippets/firestore-next/test-firestore/add_alan_turing.js create mode 100644 snippets/firestore-next/test-firestore/add_document.js create mode 100644 snippets/firestore-next/test-firestore/add_rating_transaction.js create mode 100644 snippets/firestore-next/test-firestore/array_contains_any_filter.js create mode 100644 snippets/firestore-next/test-firestore/array_contains_filter.js create mode 100644 snippets/firestore-next/test-firestore/chain_filters.js create mode 100644 snippets/firestore-next/test-firestore/cities_document_set.js create mode 100644 snippets/firestore-next/test-firestore/city_custom_object.js create mode 100644 snippets/firestore-next/test-firestore/collection_reference.js create mode 100644 snippets/firestore-next/test-firestore/data_types.js create mode 100644 snippets/firestore-next/test-firestore/delete_collection.js create mode 100644 snippets/firestore-next/test-firestore/delete_document.js create mode 100644 snippets/firestore-next/test-firestore/detach_listener.js create mode 100644 snippets/firestore-next/test-firestore/disable_network.js create mode 100644 snippets/firestore-next/test-firestore/doc_reference.js create mode 100644 snippets/firestore-next/test-firestore/doc_reference_alternative.js create mode 100644 snippets/firestore-next/test-firestore/enable_network.js create mode 100644 snippets/firestore-next/test-firestore/example_data.js create mode 100644 snippets/firestore-next/test-firestore/example_filters.js create mode 100644 snippets/firestore-next/test-firestore/filter_and_order.js create mode 100644 snippets/firestore-next/test-firestore/fs_collection_group_query.js create mode 100644 snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js create mode 100644 snippets/firestore-next/test-firestore/fs_setup_cache.js create mode 100644 snippets/firestore-next/test-firestore/get_all_users.js create mode 100644 snippets/firestore-next/test-firestore/get_custom_object.js create mode 100644 snippets/firestore-next/test-firestore/get_document.js create mode 100644 snippets/firestore-next/test-firestore/get_document_options.js create mode 100644 snippets/firestore-next/test-firestore/get_multiple.js create mode 100644 snippets/firestore-next/test-firestore/get_multiple_all.js create mode 100644 snippets/firestore-next/test-firestore/handle_listen_errors.js create mode 100644 snippets/firestore-next/test-firestore/in_filter.js create mode 100644 snippets/firestore-next/test-firestore/in_filter_with_array.js create mode 100644 snippets/firestore-next/test-firestore/initialize_persistence.js create mode 100644 snippets/firestore-next/test-firestore/invalid_filter_and_order.js create mode 100644 snippets/firestore-next/test-firestore/invalid_range_filters.js create mode 100644 snippets/firestore-next/test-firestore/listen_diffs.js create mode 100644 snippets/firestore-next/test-firestore/listen_document.js create mode 100644 snippets/firestore-next/test-firestore/listen_document_local.js create mode 100644 snippets/firestore-next/test-firestore/listen_for_users.js create mode 100644 snippets/firestore-next/test-firestore/listen_multiple.js create mode 100644 snippets/firestore-next/test-firestore/listen_with_metadata.js create mode 100644 snippets/firestore-next/test-firestore/new_document.js create mode 100644 snippets/firestore-next/test-firestore/order_and_end.js create mode 100644 snippets/firestore-next/test-firestore/order_and_limit.js create mode 100644 snippets/firestore-next/test-firestore/order_and_limit_desc.js create mode 100644 snippets/firestore-next/test-firestore/order_and_start.js create mode 100644 snippets/firestore-next/test-firestore/order_multiple.js create mode 100644 snippets/firestore-next/test-firestore/paginate.js create mode 100644 snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js create mode 100644 snippets/firestore-next/test-firestore/set_custom_object.js create mode 100644 snippets/firestore-next/test-firestore/set_document.js create mode 100644 snippets/firestore-next/test-firestore/set_with_merge.js create mode 100644 snippets/firestore-next/test-firestore/simple_queries.js create mode 100644 snippets/firestore-next/test-firestore/simple_queries_again.js create mode 100644 snippets/firestore-next/test-firestore/start_doc.js create mode 100644 snippets/firestore-next/test-firestore/start_multiple_orderby.js create mode 100644 snippets/firestore-next/test-firestore/subcollection_reference.js create mode 100644 snippets/firestore-next/test-firestore/transaction.js create mode 100644 snippets/firestore-next/test-firestore/transaction_promise.js create mode 100644 snippets/firestore-next/test-firestore/update_delete_field.js create mode 100644 snippets/firestore-next/test-firestore/update_document.js create mode 100644 snippets/firestore-next/test-firestore/update_document_array.js create mode 100644 snippets/firestore-next/test-firestore/update_document_increment.js create mode 100644 snippets/firestore-next/test-firestore/update_document_nested.js create mode 100644 snippets/firestore-next/test-firestore/update_with_server_timestamp.js create mode 100644 snippets/firestore-next/test-firestore/use_from_cache.js create mode 100644 snippets/firestore-next/test-firestore/valid_filter_and_order.js create mode 100644 snippets/firestore-next/test-firestore/valid_range_filters.js create mode 100644 snippets/firestore-next/test-firestore/write_batch.js create mode 100644 snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js create mode 100644 snippets/firestore-next/test-solution-aggregation/sample_doc.js create mode 100644 snippets/firestore-next/test-solution-arrays/post_with_array.js create mode 100644 snippets/firestore-next/test-solution-arrays/post_with_map.js create mode 100644 snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js create mode 100644 snippets/firestore-next/test-solution-arrays/query_in_category.js create mode 100644 snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js create mode 100644 snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js create mode 100644 snippets/firestore-next/test-solution-counters/create_counter.js create mode 100644 snippets/firestore-next/test-solution-counters/get_count.js create mode 100644 snippets/firestore-next/test-solution-counters/increment_counter.js create mode 100644 snippets/functions-next/emulator-suite/functions_callable_call.js create mode 100644 snippets/functions-next/emulator-suite/functions_emulator_connect.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3452af7e..f2ac9c9e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,7 +26,16 @@ jobs: path: ~/.npm key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }} - - run: npm install + - name: Install dependencies + run: | + npm install + npm run lerna-bootstrap + + - name: Compile snippets + run: npm run lerna-compile + + - name: Check generated snippets + run: | + npm run snippets + ./scripts/checkdirty.sh - - name: "Lint and Test" - run: ./scripts/test.sh diff --git a/firestore-next/emulator-suite.js b/firestore-next/emulator-suite.js new file mode 100644 index 00000000..6e608dc7 --- /dev/null +++ b/firestore-next/emulator-suite.js @@ -0,0 +1,17 @@ +// [SNIPPETS_SEPARATION enabled] +function onDocumentReady(firebaseApp) { + // [START fs_emulator_connect] + const { initializeFirestore } = require("firebase/firestore"); + + let settings = {}; + if (location.hostname === "localhost") { + settings = { + host: "localhost:8080", + ssl: false + }; + } + + // firebaseApps previously initialized using initializeApp() + const db = initializeFirestore(firebaseApp, settings); + // [END fs_emulator_connect] +} diff --git a/firestore-next/package.json b/firestore-next/package.json new file mode 100644 index 00000000..310f730b --- /dev/null +++ b/firestore-next/package.json @@ -0,0 +1,17 @@ +{ + "name": "firestore-next", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^0.800.7" + }, + "devDependencies": { + "@types/chai": "^4.2.12", + "@types/mocha": "^8.0.3", + "chai": "^4.2.0", + "mocha": "^8.1.3" + } +} diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js new file mode 100644 index 00000000..bcd5e7ef --- /dev/null +++ b/firestore-next/test.firestore.js @@ -0,0 +1,1191 @@ +// [SNIPPETS_SEPARATION enabled] +const { expect } = require('chai'); + +// [START city_custom_object] +class City { + constructor (name, state, country ) { + this.name = name; + this.state = state; + this.country = country; + } + toString() { + return this.name + ', ' + this.state + ', ' + this.country; + } +} + +// Firestore data converter +var cityConverter = { + toFirestore: function(city) { + return { + name: city.name, + state: city.state, + country: city.country + } + }, + fromFirestore: function(snapshot, options){ + const data = snapshot.data(options); + return new City(data.name, data.state, data.country) + } +} +// [END city_custom_object] + +describe("firestore", () => { + const { FirebaseFirestore } = require("firebase/firestore"); + + /** @type {FirebaseFirestore} */ + let db; + let app; + + before(() => { + const { initializeApp } = require("firebase/app"); + const { getFirestore } = require("firebase/firestore"); + + const config = { + apiKey: "AIzaSyCM61mMr_iZnP1DzjT1PMB5vDGxfyWNM64", + authDomain: "firestore-snippets.firebaseapp.com", + projectId: "firestore-snippets" + }; + app = initializeApp(config); + db = getFirestore(app); + }); + + it("should be able to set the cache size", () => { + // [START fs_setup_cache] + const { initializeFirestore, CACHE_SIZE_UNLIMITED } = require("firebase/firestore"); + + const firestoreDb = initializeFirestore(app, { + cacheSizeBytes: CACHE_SIZE_UNLIMITED + }); + // [END fs_setup_cache] + }); + + it("should be initializable with persistence", () => { + const { initializeApp } = require("firebase/app"); + const { getFirestore } = require("firebase/firestore"); + + const app = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', + projectId: '### CLOUD FIRESTORE PROJECT ID ###', + } ,"persisted_app"); + + const db = getFirestore(app); + + // [START initialize_persistence] + const { enableIndexedDbPersistence } = require("firebase/firestore"); + + enableIndexedDbPersistence(db) + .catch((err) => { + if (err.code == 'failed-precondition') { + // Multiple tabs open, persistence can only be enabled + // in one tab at a a time. + // ... + } else if (err.code == 'unimplemented') { + // The current browser does not support all of the + // features required to enable persistence + // ... + } + }); + // Subsequent queries will use persistence, if it was enabled successfully + // [END initialize_persistence] + }); + + it("should be able to enable/disable network", async () => { + // [START disable_network] + const { disableNetwork } = require("firebase/firestore"); + + await disableNetwork(db); + console.log("Network disabled!"); + // Do offline actions + // [START_EXCLUDE] + console.log("Network disabled!"); + // [END_EXCLUDE] + // [END disable_network] + + // [START enable_network] + const { enableNetwork } = require("firebase/firestore"); + + await enableNetwork(db) + // Do online actions + // [START_EXCLUDE] + console.log("Network enabled!"); + // [END_EXCLUDE] + // [END enable_network] + + }); + + it("should reply with .fromCache fields", () => { + // [START use_from_cache] + const { collection, onSnapshot, where, query } = require("firebase/firestore"); + + const q = query(collection(db, "cities"), where("state", "==", "CA")); + onSnapshot(q, { includeMetadataChanges: true }, (snapshot) => { + snapshot.docChanges().forEach((change) => { + if (change.type === "added") { + console.log("New city: ", change.doc.data()); + } + + const source = snapshot.metadata.fromCache ? "local cache" : "server"; + console.log("Data came from " + source); + }); + }); + // [END use_from_cache] + }); + + describe("collection('users')", () => { + it("should add data to a collection", async () => { + // [START add_ada_lovelace] + const { collection, addDoc } = require("firebase/firestore"); + + try { + const docRef = await addDoc(collection(db, "users"), { + first: "Ada", + last: "Lovelace", + born: 1815 + }); + console.log("Document written with ID: ", docRef.id); + } catch (e) { + console.error("Error adding document: ", e); + } + // [END add_ada_lovelace] + }); + + it("should get all users", async () => { + // [START get_all_users] + const { collection, getDocs } = require("firebase/firestore"); + + const querySnapshot = await getDocs(collection(db, "users")); + querySnapshot.forEach((doc) => { + console.log(`${doc.id} => ${doc.data()}`); + }); + // [END get_all_users] + }); + + it("should add data to a collection with new fields", async () => { + // [START add_alan_turing] + // Add a second document with a generated ID. + const { addDoc, collection } = require("firebase/firestore"); + + try { + const docRef = await addDoc(collection(db, "users"), { + first: "Alan", + middle: "Mathison", + last: "Turing", + born: 1912 + }); + + console.log("Document written with ID: ", docRef.id); + } catch (e) { + console.error("Error adding document: ", e); + } + // [END add_alan_turing] + }); + + it("should loop through a watched collection", (done) => { + // [START listen_for_users] + const { collection, where, query, onSnapshot } = require("firebase/firestore"); + + const q = query(collection(db, "users"), where("born", "<", 1900)); + const unsubscribe = onSnapshot(q, (snapshot) => { + console.log("Current users born before 1900:"); + snapshot.forEach(function (userSnapshot) { + console.log(userSnapshot.data()) + }); + }); + // [END listen_for_users] + + setTimeout(() => { + unsubscribe(); + done(); + }, 1500); + }); + + it("should reference a specific document", () => { + // [START doc_reference] + const { collection, doc } = require("firebase/firestore"); + + const alovelaceDocumentRef = doc(collection(db, 'users'), 'alovelace'); + // [END doc_reference] + }); + + it("should reference a specific collection", () => { + // [START collection_reference] + const { collection } = require("firebase/firestore"); + + const usersCollectionRef = collection(db, 'users'); + // [END collection_reference] + }); + + it("should reference a specific document (alternative)", () => { + // [START doc_reference_alternative] + const { doc } = require("firebase/firestore"); + + const alovelaceDocumentRef = doc(db, 'users/alovelace'); + // [END doc_reference_alternative] + }) + + it("should reference a document in a subcollection", () => { + // [START subcollection_reference] + const { doc, collection } = require("firebase/firestore"); + + const messageRef = doc(collection(doc(collection(db, "rooms"), "roomA"), "messages"), "message1"); + // [END subcollection_reference] + }); + + it("should set a document", async () => { + // [START set_document] + const { doc, collection, setDoc } = require("firebase/firestore"); + + // Add a new document in collection "cities" + await setDoc(doc(collection(db, "cities"), "LA"), { + name: "Los Angeles", + state: "CA", + country: "USA" + }); + // [END set_document] + }); + + it("should set document with a custom object converter", async () => { + // [START set_custom_object] + const { doc, collection, setDoc } = require("firebase/firestore"); + + // Set with cityConverter + const ref = doc(collection(db, "cities"), "LA").withConverter(cityConverter); + await setDoc(ref, new City("Los Angeles", "CA", "USA")); + // [END set_custom_object] + }); + + it("should get document with a custom object converter", async () => { + // [START get_custom_object] + const { doc, collection, getDoc} = require("firebase/firestore"); + + const ref = doc(collection(db, "cities"), "LA").withConverter(cityConverter); + const docSnap = await getDoc(ref); + if (docSnap.exists()) { + // Convert to City object + const city = docSnap.data(); + // Use a City instance method + console.log(city.toString()); + } else { + console.log("No such document!") + } + // [END get_custom_object] + }); + + it("should support batch writes", async () => { + // [START write_batch] + const { writeBatch, doc, collection } = require("firebase/firestore"); + + // Get a new write batch + const batch = writeBatch(db); + + // Set the value of 'NYC' + const nycRef = doc(collection(db, "cities"), "NYC"); + batch.set(nycRef, {name: "New York City"}); + + // Update the population of 'SF' + const sfRef = doc(collection(db, "cities"), "SF"); + batch.update(sfRef, {"population": 1000000}); + + // Delete the city 'LA' + const laRef = doc(collection(db, "cities"), "LA"); + batch.delete(laRef); + + // Commit the batch + await batch.commit(); + // [END write_batch] + }); + + it("should set a document with every datatype #UNVERIFIED", async () => { + // [START data_types] + const { doc, collection, setDoc, Timestamp } = require("firebase/firestore"); + + const docData = { + stringExample: "Hello world!", + booleanExample: true, + numberExample: 3.14159265, + dateExample: Timestamp.fromDate(new Date("December 10, 1815")), + arrayExample: [5, true, "hello"], + nullExample: null, + objectExample: { + a: 5, + b: { + nested: "foo" + } + } + }; + await setDoc(doc(collection(db, "data"), "one"), docData); + // [END data_types] + }); + + it("should allow set with merge", async () => { + // [START set_with_merge] + const { doc, collection, setDoc } = require("firebase/firestore"); + + const cityRef = doc(collection(db, 'cities'), 'BJ'); + setDoc(cityRef, { capital: true }, { merge: true }); + // [END set_with_merge] + }); + + it("should update a document's nested fields #UNVERIFIED", async () => { + // [START update_document_nested] + const { doc, collection, setDoc, updateDoc } = require("firebase/firestore"); + + // Create an initial document to update. + const frankDocRef = doc(collection(db, "users"), "frank"); + await setDoc(frankDocRef, { + name: "Frank", + favorites: { food: "Pizza", color: "Blue", subject: "recess" }, + age: 12 + }); + + // To update age and favorite color: + await updateDoc(frankDocRef, { + "age": 13, + "favorites.color": "Red" + }); + // [END update_document_nested] + }); + + it("should delete a collection", () => { + // [START delete_collection] + /** + * Delete a collection, in batches of batchSize. Note that this does + * not recursively delete subcollections of documents in the collection + */ + const { collection, query, orderBy, limit, getDocs, writeBatch } = require("firebase/firestore"); + + function deleteCollection(db, collectionRef, batchSize) { + const q = query(collectionRef, orderBy('__name__'), limit(batchSize)) + + return new Promise(function(resolve) { + deleteQueryBatch(db, q, batchSize, resolve); + }); + } + + async function deleteQueryBatch(db, query, batchSize, resolve) { + const snapshot = await getDocs(query); + + // When there are no documents left, we are done + let numDeleted = 0; + if (snapshot.size > 0) { + // Delete documents in a batch + const batch = writeBatch(db); + snapshot.docs.forEach((doc) => { + batch.delete(doc.ref); + }); + + await batch.commit(); + numDeleted = snapshot.size; + } + + if (numDeleted < batchSize) { + resolve(); + return; + } + + // Recurse on the next process tick, to avoid + // exploding the stack. + setTimeout(() => { + deleteQueryBatch(db, query, batchSize, resolve); + }, 0); + } + // [END delete_collection] + + return deleteCollection(db, collection(db, "users"), 2); + }).timeout(2000); + }); + + describe("collection('cities')", () => { + it("should set documents", async () => { + // [START example_data] + const { collection, doc, setDoc } = require("firebase/firestore"); + + const citiesRef = collection(db, "cities"); + + await setDoc(doc(citiesRef, "SF"), { + name: "San Francisco", state: "CA", country: "USA", + capital: false, population: 860000, + regions: ["west_coast", "norcal"] }); + await setDoc(doc(citiesRef, "LA"), { + name: "Los Angeles", state: "CA", country: "USA", + capital: false, population: 3900000, + regions: ["west_coast", "socal"] }); + await setDoc(doc(citiesRef, "DC"), { + name: "Washington, D.C.", state: null, country: "USA", + capital: true, population: 680000, + regions: ["east_coast"] }); + await setDoc(doc(citiesRef, "TOK"), { + name: "Tokyo", state: null, country: "Japan", + capital: true, population: 9000000, + regions: ["kanto", "honshu"] }); + await setDoc(doc(citiesRef, "BJ"), { + name: "Beijing", state: null, country: "China", + capital: true, population: 21500000, + regions: ["jingjinji", "hebei"] }); + // [END example_data] + }); + it("should set a document", async () => { + const data = {}; + + // [START cities_document_set] + const { collection, doc, setDoc } = require("firebase/firestore"); + + await setDoc(doc(collection(db, "cities"), "new-city-id"), data); + // [END cities_document_set] + }); + + it("should add a document", async () => { + // [START add_document] + const { collection, addDoc } = require("firebase/firestore"); + + // Add a new document with a generated id. + const docRef = await addDoc(collection(db, "cities"), { + name: "Tokyo", + country: "Japan" + }); + console.log("Document written with ID: ", docRef.id); + // [END add_document] + }); + + it("should add an empty a document", async () => { + const data = {}; + // [START new_document] + const { collection, doc, setDoc } = require("firebase/firestore"); + + // Add a new document with a generated id + const newCityRef = doc(collection(db, "cities")); + + // later... + await setDoc(newCityRef, data); + // [END new_document] + }); + + it("should update a document", async () => { + const data = {}; + // [START update_document] + const { collection, doc, updateDoc } = require("firebase/firestore"); + + const washingtonRef = doc(collection(db, "cities"), "DC"); + + // Set the "capital" field of the city 'DC' + await updateDoc(washingtonRef, { + capital: true + }); + // [END update_document] + }); + + it("should update an array field in a document", async () => { + // [START update_document_array] + const { collection, doc, updateDoc, arrayUnion, arrayRemove } = require("firebase/firestore"); + + const washingtonRef = doc(collection(db, "cities"), "DC"); + + // Atomically add a new region to the "regions" array field. + await updateDoc(washingtonRef, { + regions: arrayUnion("greater_virginia") + }); + + // Atomically remove a region from the "regions" array field. + await updateDoc(washingtonRef, { + regions: arrayRemove("east_coast") + }); + // [END update_document_array] + }); + + it("should update a document using numeric transforms", async () => { + // [START update_document_increment] + const { collection, doc, updateDoc, increment } = require("firebase/firestore"); + + const washingtonRef = doc(collection(db, "cities"), "DC"); + + // Atomically increment the population of the city by 50. + await updateDoc(washingtonRef, { + population: increment(50) + }); + // [END update_document_increment] + }) + + it("should delete a document", async () => { + // [START delete_document] + const { collection, doc, deleteDoc } = require("firebase/firestore"); + + await deleteDoc(doc(collection(db, "cities"), "DC")); + // [END delete_document] + }); + + it("should handle transactions", async () => { + const { collection, doc, setDoc } = require("firebase/firestore"); + + const sfDocRef = doc(collection(db, "cities"), "SF"); + await setDoc(sfDocRef, { population: 0 }); + + // [START transaction] + const { runTransaction } = require("firebase/firestore"); + + try { + await runTransaction(db, async (transaction) => { + const sfDoc = await transaction.get(sfDocRef); + if (!sfDoc.exists()) { + throw "Document does not exist!"; + } + + const newPopulation = sfDoc.data().population + 1; + transaction.update(sfDocRef, { population: newPopulation }); + }); + console.log("Transaction successfully committed!"); + } catch (e) { + console.log("Transaction failed: ", e); + } + // [END transaction] + }); + + it("should handle transaction which bubble out data", async () => { + // [START transaction_promise] + const { collection, doc, runTransaction } = require("firebase/firestore"); + + // Create a reference to the SF doc. + const sfDocRef = doc(collection(db, "cities"), "SF"); + + try { + const newPopulation = await runTransaction(db, async (transaction) => { + const sfDoc = await transaction.get(sfDocRef); + if (!sfDoc.exists()) { + throw "Document does not exist!"; + } + + const newPop = sfDoc.data().population + 1; + if (newPop <= 1000000) { + transaction.update(sfDocRef, { population: newPop }); + } else { + return Promise.reject("Sorry! Population is too big"); + } + }); + + console.log("Population increased to ", newPopulation); + } catch (e) { + // This will be a "population is too big" error. + console.error(e); + } + // [END transaction_promise] + }); + + it("should get a single document", async () => { + // [START get_document] + const { collection, doc, getDoc } = require("firebase/firestore"); + + const docRef = doc(collection(db, "cities"), "SF"); + const docSnap = await getDoc(docRef); + + if (docSnap.exists()) { + console.log("Document data:", docSnap.data()); + } else { + // doc.data() will be undefined in this case + console.log("No such document!"); + } + // [END get_document] + }); + + it("should get a document with options", async () => { + // [START get_document_options] + const { collection, doc, getDocFromCache } = require("firebase/firestore"); + + const docRef = doc(collection(db, "cities"), "SF"); + + // Get a document, forcing the SDK to fetch from the offline cache. + try { + const doc = await getDocFromCache(docRef); + + // Document was found in the cache. If no cached document exists, + // an error will be returned to the 'catch' block below. + console.log("Cached document data:", doc.data()); + } catch (e) { + console.log("Error getting cached document:", e); + } + // [END get_document_options] + }); + + it("should listen on a single document", (done) => { + // [START listen_document] + const { collection, doc, onSnapshot } = require("firebase/firestore"); + + const unsub = onSnapshot(doc(collection(db, "cities"), "SF"), (doc) => { + console.log("Current data: ", doc.data()); + }); + // [END listen_document] + + setTimeout(function() { + unsub(); + done(); + }, 3000); + }).timeout(5000); + + it("should listen on a single document with metadata", (done) => { + // [START listen_document_local] + const { collection, doc, onSnapshot } = require("firebase/firestore"); + + const unsub = onSnapshot(doc(collection(db, "cities"), "SF"), (doc) => { + const source = doc.metadata.hasPendingWrites ? "Local" : "Server"; + console.log(source, " data: ", doc.data()); + }); + // [END listen_document_local] + + setTimeout(function() { + unsub(); + done(); + }, 3000); + }).timeout(5000); + + it("should listen on a single document with options #UNVERIFIED", (done) => { + // [START listen_with_metadata] + const { collection, doc, onSnapshot } = require("firebase/firestore"); + + const unsub = onSnapshot( + doc(collection(db, "cities"), "SF"), + { includeMetadataChanges: true }, + (doc) => { + // ... + }); + // [END listen_with_metadata] + + setTimeout(function() { + unsub(); + done(); + }, 3000); + }).timeout(5000); + + it("should get multiple documents from a collection", async () => { + // [START get_multiple] + const { collection, query, where, getDocs } = require("firebase/firestore"); + + const q = query(collection(db, "cities"), where("capital", "==", true)); + + const querySnapshot = await getDocs(q); + querySnapshot.forEach((doc) => { + // doc.data() is never undefined for query doc snapshots + console.log(doc.id, " => ", doc.data()); + }); + // [END get_multiple] + }).timeout(5000); + + it("should get all documents from a collection", async () => { + // [START get_multiple_all] + const { collection, getDocs } = require("firebase/firestore"); + + const querySnapshot = await getDocs(collection(db, "cities")); + querySnapshot.forEach((doc) => { + // doc.data() is never undefined for query doc snapshots + console.log(doc.id, " => ", doc.data()); + }); + // [END get_multiple_all] + }); + + it("should listen on multiple documents #UNVERIFIED", (done) => { + // [START listen_multiple] + const { collection, query, where, onSnapshot } = require("firebase/firestore"); + + const q = query(collection(db, "cities"), where("state", "==", "CA")); + const unsubscribe = onSnapshot(q, (querySnapshot) => { + const cities = []; + querySnapshot.forEach((doc) => { + cities.push(doc.data().name); + }); + console.log("Current cities in CA: ", cities.join(", ")); + }); + // [END listen_multiple] + setTimeout(function() { + unsubscribe(); + done(); + }, 2500); + }).timeout(5000); + + it("should view changes between snapshots #UNVERIFIED", (done) => { + // [START listen_diffs] + const { collection, query, where, onSnapshot } = require("firebase/firestore"); + + const q = query(collection(db, "cities"), where("state", "==", "CA")); + const unsubscribe = onSnapshot(q, (snapshot) => { + snapshot.docChanges().forEach((change) => { + if (change.type === "added") { + console.log("New city: ", change.doc.data()); + } + if (change.type === "modified") { + console.log("Modified city: ", change.doc.data()); + } + if (change.type === "removed") { + console.log("Removed city: ", change.doc.data()); + } + }); + }); + // [END listen_diffs] + setTimeout(function() { + unsubscribe(); + done(); + }, 2500); + }).timeout(5000); + + it("should unsubscribe a listener", () => { + // [START detach_listener] + const { collection, onSnapshot } = require("firebase/firestore"); + + const unsubscribe = onSnapshot(collection(db, "cities"), () => { + // Respond to data + // ... + }); + + // Later ... + + // Stop listening to changes + unsubscribe(); + // [END detach_listener] + }); + + it("should handle listener errors", () => { + // [START handle_listen_errors] + const { collection, onSnapshot } = require("firebase/firestore"); + + const unsubscribe = onSnapshot( + collection(db, "cities"), + (snapshot) => { + // ... + }, + (error) => { + // ... + }); + // [END handle_listen_errors] + unsubscribe(); + }); + + it("should update a document with server timestamp", async () => { + async function update() { + // [START update_with_server_timestamp] + const { collection, updateDoc, serverTimestamp } = require("firebase/firestore"); + + const docRef = doc(collection(db, 'objects'), 'some-id'); + + // Update the timestamp field with the value from the server + const updateTimestamp = await updateDoc(docRef, { + timestamp: serverTimestamp() + }); + // [END update_with_server_timestamp] + + return updateTimestamp; + } + + const { collection, doc, setDoc } = require("firebase/firestore"); + + await setDoc(doc(collection(db, 'objects'), 'some-id'), {}); + await update(); + console.log('Document updated with server timestamp'); + }); + + it("should use options to control server timestamp resolution", async () => { + // [START server_timestamp_resolution_options] + const { collection, doc, updateDoc, serverTimestamp, onSnapshot } = require("firebase/firestore"); + // Perform an update followed by an immediate read without + // waiting for the update to complete. Due to the snapshot + // options we will get two results: one with an estimate + // timestamp and one with the resolved server timestamp. + const docRef = doc(collection(db, 'objects'), 'some-id'); + updateDoc(docRef, { + timestamp: serverTimestamp() + }); + + onSnapshot(docRef, (snapshot) => { + const data = snapshot.data({ + // Options: 'estimate', 'previous', or 'none' + serverTimestamps: "estimate" + }); + console.log( + 'Timestamp: ' + data.timestamp + + ', pending: ' + snapshot.metadata.hasPendingWrites); + }); + // [END server_timestamp_resolution_options] + }); + + it("should delete a document field", async () => { + async function update() { + // [START update_delete_field] + const { doc, collection, updateDoc, deleteField } = require("firebase/firestore"); + + const cityRef = doc(collection(db, 'cities'), 'BJ'); + + // Remove the 'capital' field from the document + await updateDoc(cityRef, { + capital: deleteField() + }); + // [END update_delete_field] + } + + const { doc, collection, setDoc } = require("firebase/firestore"); + + await setDoc(doc(collection(db,'cities'), 'BJ'), { capital: true }); + await update(); + }); + + describe("queries", () => { + it("should handle simple where", () => { + // [START simple_queries] + // Create a reference to the cities collection + const { collection, query, where } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // Create a query against the collection. + const q = query(citiesRef, where("state", "==", "CA")); + // [END simple_queries] + }); + + it("should handle another simple where", () => { + // [START simple_queries_again] + const { collection, query, where } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + const q = query(citiesRef, where("capital", "==", true)); + // [END simple_queries_again] + }); + + it("should handle other wheres", () => { + const { collection, query, where } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START example_filters] + const q1 = query(citiesRef, where("state", "==", "CA")); + const q2 = query(citiesRef, where("population", "<", 100000)); + const q3 = query(citiesRef, where("name", ">=", "San Francisco")); + // [END example_filters] + }); + + it("should handle array-contains where", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START array_contains_filter] + const { query, where } = require("firebase/firestore"); + const q = query(citiesRef, where("regions", "array-contains", "west_coast")); + // [END array_contains_filter] + }); + + it("should handle an array contains any where", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START array_contains_any_filter] + const { query, where } = require("firebase/firestore"); + + const q = query(citiesRef, + where('regions', 'array-contains-any', ['west_coast', 'east_coast'])); + // [END array_contains_any_filter] + }); + + it("should handle an in where", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + function inFilter() { + // [START in_filter] + const { query, where } = require("firebase/firestore"); + + const q = query(citiesRef, where('country', 'in', ['USA', 'Japan'])); + // [END in_filter] + } + + function inFilterWithArray() { + // [START in_filter_with_array] + const { query, where } = require("firebase/firestore"); + + const q = query(citiesRef, where('regions', 'in', [['west_coast', 'east_coast']])); + // [END in_filter_with_array] + } + }); + + it("should handle compound queries", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START chain_filters] + const { query, where } = require("firebase/firestore"); + + const q1 = query(citiesRef, where("state", "==", "CO"), where("name", "==", "Denver")); + const q2 = query(citiesRef, where("state", "==", "CA"), where("population", "<", 1000000)); + // [END chain_filters] + }); + + it("should handle range filters on one field", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START valid_range_filters] + const { query, where } = require("firebase/firestore"); + + const q1 = query(citiesRef, where("state", ">=", "CA"), where("state", "<=", "IN")); + const q2 = query(citiesRef, where("state", "==", "CA"), where("population", ">", 1000000)); + // [END valid_range_filters] + }); + + it("should not handle range filters on multiple field", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + expect(() => { + // [START invalid_range_filters] + const { query, where } = require("firebase/firestore"); + + const q = query(citiesRef, where("state", ">=", "CA"), where("population", ">", 100000)); + // [END invalid_range_filters] + }).to.throw; + }); + + it("should order and limit", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START order_and_limit] + const { query, orderBy, limit } = require("firebase/firestore"); + + const q = query(citiesRef, orderBy("name"), limit(3)); + // [END order_and_limit] + }); + + it("should order descending", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START order_and_limit_desc] + const { query, orderBy, limit } = require("firebase/firestore"); + + const q = query(citiesRef, orderBy("name", "desc"), limit(3)); + // [END order_and_limit_desc] + }); + + it("should order descending by other field", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START order_multiple] + const { query, orderBy } = require("firebase/firestore"); + + const q = query(citiesRef, orderBy("state"), orderBy("population", "desc")); + // [END order_multiple] + }); + + it("should where and order by with limit", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START filter_and_order] + const { query, where, orderBy, limit } = require("firebase/firestore"); + + const q = query(citiesRef, where("population", ">", 100000), orderBy("population"), limit(2)); + // [END filter_and_order] + }); + + it("should where and order on same field", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START valid_filter_and_order] + const { query, where, orderBy } = require("firebase/firestore"); + + const q = query(citiesRef, where("population", ">", 100000), orderBy("population")); + // [END valid_filter_and_order] + }); + + it("should not where and order on same field", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + expect(() => { + // [START invalid_filter_and_order] + const { query, where, orderBy } = require("firebase/firestore"); + + const q = query(citiesRef, where("population", ">", 100000), orderBy("country")); + // [END invalid_filter_and_order] + }).to.throw; + }); + + it("should handle startAt", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START order_and_start] + const { query, orderBy, startAt } = require("firebase/firestore"); + + const q = query(citiesRef, orderBy("population"), startAt(1000000)); + // [END order_and_start] + }); + + it("should handle endAt", () => { + const { collection } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + // [START order_and_end] + const { query, orderBy, endAt } = require("firebase/firestore"); + + const q = query(citiesRef, orderBy("population"), endAt(1000000)); + // [END order_and_end] + }); + + it("should handle startAt(doc) ", async () => { + // [START start_doc] + const { collection, doc, getDoc, query, orderBy, startAt } = require("firebase/firestore"); + const citiesRef = collection(db, "cities"); + + const docSnap = await getDoc(doc(citiesRef, "SF")); + + // Get all cities with a population bigger than San Francisco + const biggerThanSf = query(citiesRef, orderBy("popuation"), startAt(docSnap)); + // ... + // [END start_doc] + }); + + it("should handle multiple orderBy", () => { + // [START start_multiple_orderby] + // Will return all Springfields + const { collection, query, orderBy, startAt } = require("firebase/firestore"); + const q1 = query(collection(db, "cities"), + orderBy("name"), + orderBy("state"), + startAt("Springfield")); + + // Will return "Springfield, Missouri" and "Springfield, Wisconsin" + const q2 = query(collection(db, "cities"), + orderBy("name"), + orderBy("state"), + startAt("Springfield", "Missouri")); + // [END start_multiple_orderby] + }); + + it("should paginate", async () => { + // [START paginate] + const { collection, query, orderBy, startAfter, limit, getDocs } = require("firebase/firestore"); + + // Query the first page of docs + const first = query(collection(db, "cities"), orderBy("population"), limit(25)); + const documentSnapshots = await getDocs(first); + + // Get the last visible document + const lastVisible = documentSnapshots.docs[documentSnapshots.docs.length-1]; + console.log("last", lastVisible); + + // Construct a new query starting at this document, + // get the next 25 cities. + const next = query(collection(db, "cities"), + orderBy("population"), + startAfter(lastVisible), + limit(25)); + // [END paginate] + }); + }); + + describe('collectionGroup(landmarks)', () => { + it("should setup example data", async () => { + // [START fs_collection_group_query_data_setup] + const { collection, doc, setDoc } = require("firebase/firestore"); + + const citiesRef = collection(db, 'cities'); + + await Promise.all([ + setDoc(doc(collection(doc(citiesRef, 'SF'), 'landmarks')), { + name: 'Golden Gate Bridge', + type: 'bridge' + }), + setDoc(doc(collection(doc(citiesRef, 'SF'), 'landmarks')), { + name: 'Legion of Honor', + type: 'museum' + }), + setDoc(doc(collection(doc(citiesRef, 'LA'), 'landmarks')), { + name: 'Griffith Park', + type: 'park' + }), + setDoc(doc(collection(doc(citiesRef, 'LA'), 'landmarks')), { + name: 'The Getty', + type: 'museum' + }), + setDoc(doc(collection(doc(citiesRef, 'DC'), 'landmarks')), { + name: 'Lincoln Memorial', + type: 'memorial' + }), + setDoc(doc(collection(doc(citiesRef, 'DC'), 'landmarks')), { + name: 'National Air and Space Museum', + type: 'museum' + }), + setDoc(doc(collection(doc(citiesRef, 'TOK'), 'landmarks')), { + name: 'Ueno Park', + type: 'park' + }), + setDoc(doc(collection(doc(citiesRef, 'TOK'), 'landmarks')), { + name: 'National Museum of Nature and Science', + type: 'museum' + }), + setDoc(doc(collection(doc(citiesRef, 'BJ'), 'landmarks')), { + name: 'Jingshan Park', + type: 'park' + }), + setDoc(doc(collection(doc(citiesRef, 'BJ'), 'landmarks')), { + name: 'Beijing Ancient Observatory', + type: 'museum' + }) + ]); + // [END fs_collection_group_query_data_setup] + }); + + it("should query a collection group", async () => { + // [START fs_collection_group_query] + const { collectionGroup, query, where, getDocs } = require("firebase/firestore"); + + const museums = query(collectionGroup(db, 'landmarks'), where('type', '==', 'museum')); + const querySnapshot = await getDocs(museums); + querySnapshot.forEach((doc) => { + console.log(doc.id, ' => ', doc.data()); + }); + // [END fs_collection_group_query] + }); + }); + }); + + // TODO: Break out into separate file + describe("solution-aggregation", () => { + it("should update a restaurant in a transaction #UNVERIFIED", async () => { + // [START add_rating_transaction] + const { collection, doc, runTransaction} = require("firebase/firestore"); + + async function addRating(restaurantRef, rating) { + // Create a reference for a new rating, for use inside the transaction + const ratingRef = doc(collection(restaurantRef, 'ratings')); + + // In a transaction, add the new rating and update the aggregate totals + await runTransaction(db, async (transaction) => { + const res = await transaction.get(restaurantRef); + if (!res.exists()) { + throw "Document does not exist!"; + } + + // Compute new number of ratings + const newNumRatings = res.data().numRatings + 1; + + // Compute new average rating + const oldRatingTotal = res.data().avgRating * res.data().numRatings; + const newAvgRating = (oldRatingTotal + rating) / newNumRatings; + + // Commit to Firestore + transaction.update(restaurantRef, { + numRatings: newNumRatings, + avgRating: newAvgRating + }); + transaction.set(ratingRef, { rating: rating }); + }); + } + // [END add_rating_transaction] + + // Create document and add a rating + const { setDoc } = require("firebase/firestore"); + const ref = doc(collection(db, 'restaurants'), ('arinell-pizza')); + await setDoc(ref, { + name: 'Arinell Pizza', + avgRating: 4.63, + numRatings: 683 + }); + await addRating(ref, 5.0); + }); + }); +}); diff --git a/firestore-next/test.solution-aggregation.js b/firestore-next/test.solution-aggregation.js new file mode 100644 index 00000000..a2b8c487 --- /dev/null +++ b/firestore-next/test.solution-aggregation.js @@ -0,0 +1,41 @@ +// [SNIPPETS_SEPARATION enabled] +// [START sample_doc] +const arinellDoc = { + name: 'Arinell Pizza', + avgRating: 4.65, + numRatings: 683 +} +// [END sample_doc] + +describe("firestore-solution-arrays", () => { + const { FirebaseFirestore } = require("firebase/firestore"); + + /** @type {FirebaseFirestore} */ + let db; + + before(async () => { + const { initializeApp } = require("firebase/app"); + const { getFirestore, collection, doc, setDoc } = require("firebase/firestore"); + + const config = { + apiKey: "AIzaSyArvVh6VSdXicubcvIyuB-GZs8ua0m0DTI", + authDomain: "firestorequickstarts.firebaseapp.com", + projectId: "firestorequickstarts", + }; + const app = initializeApp(config, "solution-arrays"); + db = getFirestore(app); + + await setDoc(doc(collection(db, "restaurants"), "arinell-pizza"), arinellDoc); + }); + + describe("solution-arrays", () => { + it("should get a collection of ratings", async () => { + // [START get_collection_ratings] + const { collection, doc, getDocs } = require("firebase/firestore"); + + const ratingsRef = collection(doc(collection(db, "restaurants"), "arinell-pizza"), "ratings"); + const ratingsDocs = await getDocs(ratingsRef); + // [END get_collection_ratings] + }) + }); +}); diff --git a/firestore-next/test.solution-arrays.js b/firestore-next/test.solution-arrays.js new file mode 100644 index 00000000..7c2ee04d --- /dev/null +++ b/firestore-next/test.solution-arrays.js @@ -0,0 +1,100 @@ +// [SNIPPETS_SEPARATION enabled] +const postsWithArray = [ + // [START post_with_array] + // Sample document in the 'posts' collection. + { + title: "My great post", + categories: [ + "technology", + "opinion", + "cats" + ] + } + // [END post_with_array] +]; + +const postsWithMap = [ + // [START post_with_map] + // Sample document in the 'posts' collection + { + title: "My great post", + categories: { + "technology": true, + "opinion": true, + "cats": true + } + } + // [END post_with_map] +]; + +const postsWithMapAdvanced = [ + // [START post_with_map_advanced] + // The value of each entry in 'categories' is a unix timestamp + { + title: "My great post", + categories: { + technology: 1502144665, + opinion: 1502144665, + cats: 1502144665 + } + } + // [END post_with_map_advanced] +] + +describe("firestore-solution-arrays", () => { + const { FirebaseFirestore } = require("firebase/firestore"); + + /** @type {FirebaseFirestore} */ + let db; + + before(() => { + const { initializeApp } = require("firebase/app"); + const { getFirestore } = require("firebase/firestore"); + + const config = { + apiKey: "AIzaSyArvVh6VSdXicubcvIyuB-GZs8ua0m0DTI", + authDomain: "firestorequickstarts.firebaseapp.com", + projectId: "firestorequickstarts", + }; + const app = initializeApp(config, "solution-arrays"); + db = getFirestore(app); + }); + + describe("solution-arrays", () => { + it("should query in a category", async () => { + // [START query_in_category] + const { collection, getDocs, query, where } = require("firebase/firestore"); + + // Find all documents in the 'posts' collection that are + // in the 'cats' category. + const q = query(collection(db, "posts"), where("categories.cats", "==", true)); + const docs = await getDocs(q); + // ... + // [END query_in_category] + }); + + it("should query in a category by timestamp", () => { + function queryOne() { + // [START query_in_category_timestamp_invalid] + const { collection, query, where, orderBy, FirebaseFirestore } = require("@firebase/firestore"); + + const q = query(collection(db, "posts"), + where("categories.cats", "==", true), + orderBy("timestamp")); + // [END query_in_category_timestamp_invalid] + } + + + function queryTwo() { + // [START query_in_category_timestamp] + const { collection, query, where, orderBy } = require("@firebase/firestore"); + + const q = query(collection(db, "posts"), + where("categories.cats", ">", 0), + orderBy("categories.cats")); + // [END query_in_category_timestamp] + } + + }); + }); +}); diff --git a/firestore-next/test.solution-counters.js b/firestore-next/test.solution-counters.js new file mode 100644 index 00000000..ab9eae36 --- /dev/null +++ b/firestore-next/test.solution-counters.js @@ -0,0 +1,97 @@ +// [SNIPPETS_SEPARATION enabled] +const { FirebaseFirestore } = require('firebase/firestore'); + +/** @type {FirebaseFirestore} */ +let db; + +// [START create_counter] +function createCounter(ref, num_shards) { + const { collection, doc, writeBatch } = require("firebase/firestore"); + + const batch = writeBatch(db); + + // Initialize the counter document + batch.set(ref, { num_shards: num_shards }); + + // Initialize each shard with count=0 + for (let i = 0; i < num_shards; i++) { + const shardRef = doc(collection(ref, 'shards'), i.toString()); + batch.set(shardRef, { count: 0 }); + } + + // Commit the write batch + return batch.commit(); +} +// [END create_counter] + +// [START increment_counter] +function incrementCounter(db, ref, num_shards) { + const { collection, doc, updateDoc, increment, FirebaseFirestore } = require("@firebase/firestore"); + + // Select a shard of the counter at random + const shardId = Math.floor(Math.random() * num_shards).toString(); + const shardRef = doc(collection(ref, 'shards'), shardId); + + // Update count + return updateDoc(shardRef, "count", increment(1)); +} +// [END increment_counter] + +// [START get_count] +async function getCount(ref) { + const { collection, getDocs } = require("@firebase/firestore"); + + // Sum the count of each shard in the subcollection + const snapshot = await getDocs(collection(ref, 'shards')); + + let totalCount = 0; + snapshot.forEach(doc => { + totalCount += doc.data().count; + }); + + return totalCount; +} +// [END get_count] + +describe("firestore-solution-counters", () => { + before(() => { + const { initializeApp } = require("firebase/app"); + const { getFirestore } = require("firebase/firestore"); + + const config = { + apiKey: "AIzaSyArvVh6VSdXicubcvIyuB-GZs8ua0m0DTI", + authDomain: "firestorequickstarts.firebaseapp.com", + projectId: "firestorequickstarts", + }; + const app = initializeApp(config, "solution-arrays"); + db = getFirestore(app); + }); + + describe("solution-counters", () => { + it("should create a counter", () => { + // Create a counter with 10 shards + const { collection, doc } = require("firebase/firestore"); + + return createCounter(doc(collection(db, 'counters')), 10); + }); + + it("should increment a counter", async () => { + // Create a counter, then increment it + const { collection, doc } = require("firebase/firestore"); + + const ref = doc(collection(db, 'counters')); + await createCounter(ref, 10) + await incrementCounter(db, ref, 10); + }); + + it("should get the count of a counter", async () => { + // Create a counter, increment it, then get the count + const { collection, doc } = require("firebase/firestore"); + + const ref = doc(collection(db, 'counters')); + await createCounter(ref, 10); + await incrementCounter(db, ref, 10); + await getCount(ref); + }); + }); +}); diff --git a/firestore/package.json b/firestore/package.json index e2779ec4..d9e1b2d6 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.17.1" + "firebase": "^7.20.0" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index f5131965..b0dedce8 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -1,7 +1,8 @@ -var firebase = require('firebase/app'); -const { expect } = require('chai'); +const firebase = require('firebase/app'); require('firebase/firestore'); +const { expect } = require('chai'); + // [START city_custom_object] class City { constructor (name, state, country ) { diff --git a/functions-next/.gitignore b/functions-next/.gitignore new file mode 100644 index 00000000..1521c8b7 --- /dev/null +++ b/functions-next/.gitignore @@ -0,0 +1 @@ +dist diff --git a/functions-next/emulator-suite.js b/functions-next/emulator-suite.js new file mode 100644 index 00000000..c2e1b535 --- /dev/null +++ b/functions-next/emulator-suite.js @@ -0,0 +1,32 @@ +// [SNIPPETS_SEPARATION enabled] +import { initializeApp } from "firebase/app"; + +initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +export function emulatorSettings() { + // [START functions_emulator_connect] + const { getApp } = require("firebase/app"); + const { getFunctions, useFunctionsEmulator } = require( "firebase/functions"); + + const functions = getFunctions(getApp()); + useFunctionsEmulator(functions, "http://localhost:5001"); + // [END functions_emulator_connect] +} + +export async function callFunction() { + // [START functions_callable_call] + const { getApp } = require("firebase/app"); + const { getFunctions, httpsCallable } = require( "firebase/functions"); + + const functions = getFunctions(getApp()); + const addMessage = httpsCallable(functions, 'addMessage'); + + const result = await addMessage({ text: ''}); + const sanitizedMessage = result.data.text; + // ... + // [END functions_callable_call] +} diff --git a/functions-next/package.json b/functions-next/package.json new file mode 100644 index 00000000..cb5ad467 --- /dev/null +++ b/functions-next/package.json @@ -0,0 +1,12 @@ +{ + "name": "functions-next", + "version": "1.0.0", + "scripts": { + "build": "webpack", + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^0.800.3" + } +} diff --git a/lerna.json b/lerna.json index 1cf4129b..bf6d962e 100644 --- a/lerna.json +++ b/lerna.json @@ -5,7 +5,9 @@ "database", "firebaseapp", "firestore", + "firestore-next", "functions", + "functions-next", "installations" ], "version": "1.0.0" diff --git a/package.json b/package.json index 9d3c88b5..641918cb 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,14 @@ "name": "snippets-web", "version": "1.0.0", "scripts": { + "snippets": "npx ts-node scripts/separate-snippets.ts", "lerna-bootstrap": "lerna bootstrap --no-ci", "lerna-compile": "lerna run compile" }, "license": "Apache-2.0", "devDependencies": { "lerna": "^3.22.1", + "ts-node": "^9.0.0", "typescript": "^3.8.3" } } diff --git a/scripts/checkdirty.sh b/scripts/checkdirty.sh new file mode 100755 index 00000000..5d3c8bea --- /dev/null +++ b/scripts/checkdirty.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +git add . + +if [[ $(git diff --stat HEAD) != '' ]]; then + git diff --stat HEAD + echo + echo 'Error: git diff is dirty ... did you forget to run "npm run snippets" after adding snippets?' + exit 1 +else + echo 'Succes: git diff is clean' +fi diff --git a/scripts/package.json b/scripts/package.json new file mode 100644 index 00000000..72b9bf11 --- /dev/null +++ b/scripts/package.json @@ -0,0 +1,9 @@ +{ + "name": "scripts", + "version": "1.0.0", + "description": "Internal repo scripts", + "scripts": { + }, + "author": "samstern@google.com", + "license": "Apache-2.0" +} diff --git a/scripts/separate-snippets.ts b/scripts/separate-snippets.ts new file mode 100644 index 00000000..b5d5d9d1 --- /dev/null +++ b/scripts/separate-snippets.ts @@ -0,0 +1,197 @@ +import * as cp from "child_process"; +import * as fs from "fs"; +import * as path from "path"; + +// Regex for comment which must be included in a file for it to be separated +const RE_SNIPPETS_SEPARATION = /\[SNIPPETS_SEPARATION\s+enabled\]/; + +// Regex for comment to control the separator prefix +const RE_SNIPPETS_PREFIX = /\[SNIPPETS_PREFIX\s+([A-Za-z0-9_]+)\]/; + +// Regex for [START] and [END] snippet tags. +const RE_START_SNIPPET = /\[START\s+([A-Za-z_]+)\s*\]/; +const RE_END_SNIPPET = /\[END\s+([A-Za-z_]+)\s*\]/; + +// Regex for const = require statements +// TODO: Handle multiline imports? +const RE_REQUIRE = /const {(.+?)} = require\((.+?)\)/; + +type SnippetsConfig = { + enabled: boolean; + prefix: string; + map: Record; +}; + +const DEFAULT_PREFIX = "modular_"; + +function isBlank(line: string) { + return line.trim().length === 0; +} + +/** + * Turns a series of source lines into a standalone snippet file by: + * - Converting require statements into top-level imports. + * - Adjusting indentation to left-align all content + * - Removing any blank lines at the starts + * - Adding a prefix to snippet names + * + * @param lines the lines containing the snippet (including START/END comments) + * @param sourceFile the source file where the original snippet lives + * @param snippetPrefix the prefix (such as modular_) + */ +function processSnippet( + lines: string[], + sourceFile: string, + snippetPrefix: string +): string { + const outputLines: string[] = []; + + for (const line of lines) { + if (line.match(RE_REQUIRE)) { + outputLines.push(line.replace(RE_REQUIRE, `import {$1} from $2`)); + } else if (line.match(RE_START_SNIPPET)) { + outputLines.push(line.replace(RE_START_SNIPPET, `[START ${snippetPrefix}$1]`)); + } else if (line.match(RE_END_SNIPPET)) { + outputLines.push( + line.replace(RE_END_SNIPPET, `[END ${snippetPrefix}$1]`) + ); + } else { + outputLines.push(line); + } + } + + // Adjust indentation of the otherLines so that they're left aligned + const nonBlankLines = outputLines.filter((l) => !isBlank(l)); + const indentSizes = nonBlankLines.map((l) => l.length - l.trimLeft().length); + const minIndent = Math.min(...indentSizes); + + const adjustedOutputLines: string[] = []; + for (const line of outputLines) { + if (isBlank(line)) { + adjustedOutputLines.push(""); + } else { + adjustedOutputLines.push(line.substr(minIndent)); + } + } + + // Special case: if the first line after the comments is blank we want to remove it + const firstNonComment = adjustedOutputLines.findIndex( + (l) => !l.startsWith("//") + ); + if (isBlank(outputLines[firstNonComment])) { + adjustedOutputLines.splice(firstNonComment, 1); + } + + const preambleLines = [ + `// This snippet file was generated by processing the source file:`, + `// ${sourceFile}`, + `//`, + `// To make edits to the snippets in this file, please edit the source`, + ``, + ]; + const content = [...preambleLines, ...adjustedOutputLines].join("\n"); + return content; +} + +/** + * Lists all the files in this repository that should be checked for snippets + */ +function listSnippetFiles(): string[] { + const output = cp + .execSync( + 'find . -type f -name "*.js" -not -path "*node_modules*" -not -path "./snippets*"' + ) + .toString(); + return output.split("\n").filter((x) => !isBlank(x)); +} + +/** + * Collect all the snippets from a file into a map of snippet name to lines. + * @param filePath the file path to read. + */ +function collectSnippets(filePath: string): SnippetsConfig { + const fileContents = fs.readFileSync(filePath).toString(); + const lines = fileContents.split("\n"); + + const config: SnippetsConfig = { + enabled: false, + prefix: DEFAULT_PREFIX, + map: {}, + }; + + config.enabled = lines.some((l) => !!l.match(RE_SNIPPETS_SEPARATION)); + if (!config.enabled) { + return config; + } + + const prefixLine = lines.find((l) => !!l.match(RE_SNIPPETS_PREFIX)); + if (prefixLine) { + const m = prefixLine.match(RE_SNIPPETS_PREFIX); + config.prefix = m[1]; + } + + let currSnippetName = ""; + let inSnippet = false; + for (const line of lines) { + const startMatch = line.match(RE_START_SNIPPET); + const endMatch = line.match(RE_END_SNIPPET); + + if (startMatch) { + inSnippet = true; + currSnippetName = startMatch[1]; + config.map[currSnippetName] = []; + } + + if (inSnippet) { + config.map[currSnippetName].push(line); + } + + if (endMatch) { + if (endMatch[1] !== currSnippetName) { + throw new Error( + `Snippet ${currSnippetName} in ${filePath} has unmatched START/END tags` + ); + } + inSnippet = false; + } + } + + return config; +} + +async function main() { + const fileNames = listSnippetFiles(); + + for (const filePath of fileNames) { + const config = collectSnippets(filePath); + if (!config.enabled) { + continue; + } + + const fileSlug = filePath + .replace(".js", "") + .replace("./", "") + .replace(/\./g, "-"); + const snippetDir = path.join("./snippets", fileSlug); + + console.log( + `Processing: ${filePath} --> ${snippetDir} (prefix=${config.prefix})` + ); + + if (!fs.existsSync(snippetDir)) { + fs.mkdirSync(snippetDir, { recursive: true }); + } + + for (const snippetName in config.map) { + const newFilePath = path.join(snippetDir, `${snippetName}.js`); + const content = processSnippet( + config.map[snippetName], + filePath, + config.prefix + ); + fs.writeFileSync(newFilePath, content); + } + } +} + +main(); diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100755 index 7527670e..00000000 --- a/scripts/test.sh +++ /dev/null @@ -1,11 +0,0 @@ -set -e - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -# 0) Bootstrap -echo "Bootstrapping..." -npm run lerna-bootstrap - -# 1) "Compile" the code -echo "Compiling..." -npm run lerna-compile diff --git a/snippets/README.md b/snippets/README.md new file mode 100644 index 00000000..3819e7cf --- /dev/null +++ b/snippets/README.md @@ -0,0 +1,26 @@ +# Generated Snippets + +## Overview + +This directory contains snippets generated by the `separate-snippets` script. +Snippets in this folder should **never** be updated directly instead please +edit the source file (indicated by a comment at the top). + +## Regenerating the Snippets + +Run `npm run snippets` from the root of this repository. + +## Using the Separator + +For a file to be included in the separator script it must contain a comment like this: + +```js +// [SNIPPETS_SEPARATION enabled] +``` + +By default separated snippets will have their name prefixed with `modular_` +but you can override this with a commment: + +```js +// [SNIPPETS_PREFIX banana] +``` diff --git a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js new file mode 100644 index 00000000..6b587d39 --- /dev/null +++ b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/emulator-suite.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_fs_emulator_connect] +import { initializeFirestore } from "firebase/firestore"; + +let settings = {}; +if (location.hostname === "localhost") { + settings = { + host: "localhost:8080", + ssl: false + }; +} + +// firebaseApps previously initialized using initializeApp() +const db = initializeFirestore(firebaseApp, settings); +// [END modular_fs_emulator_connect] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/add_ada_lovelace.js b/snippets/firestore-next/test-firestore/add_ada_lovelace.js new file mode 100644 index 00000000..5fa87298 --- /dev/null +++ b/snippets/firestore-next/test-firestore/add_ada_lovelace.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_add_ada_lovelace] +import { collection, addDoc } from "firebase/firestore"; + +try { + const docRef = await addDoc(collection(db, "users"), { + first: "Ada", + last: "Lovelace", + born: 1815 + }); + console.log("Document written with ID: ", docRef.id); +} catch (e) { + console.error("Error adding document: ", e); +} +// [END modular_add_ada_lovelace] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/add_alan_turing.js b/snippets/firestore-next/test-firestore/add_alan_turing.js new file mode 100644 index 00000000..300eaa00 --- /dev/null +++ b/snippets/firestore-next/test-firestore/add_alan_turing.js @@ -0,0 +1,22 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_add_alan_turing] +// Add a second document with a generated ID. +import { addDoc, collection } from "firebase/firestore"; + +try { + const docRef = await addDoc(collection(db, "users"), { + first: "Alan", + middle: "Mathison", + last: "Turing", + born: 1912 + }); + + console.log("Document written with ID: ", docRef.id); +} catch (e) { + console.error("Error adding document: ", e); +} +// [END modular_add_alan_turing] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/add_document.js b/snippets/firestore-next/test-firestore/add_document.js new file mode 100644 index 00000000..4f01313c --- /dev/null +++ b/snippets/firestore-next/test-firestore/add_document.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_add_document] +import { collection, addDoc } from "firebase/firestore"; + +// Add a new document with a generated id. +const docRef = await addDoc(collection(db, "cities"), { + name: "Tokyo", + country: "Japan" +}); +console.log("Document written with ID: ", docRef.id); +// [END modular_add_document] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/add_rating_transaction.js b/snippets/firestore-next/test-firestore/add_rating_transaction.js new file mode 100644 index 00000000..0c3a4281 --- /dev/null +++ b/snippets/firestore-next/test-firestore/add_rating_transaction.js @@ -0,0 +1,35 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_add_rating_transaction] +import { collection, doc, runTransaction} from "firebase/firestore"; + +async function addRating(restaurantRef, rating) { + // Create a reference for a new rating, for use inside the transaction + const ratingRef = doc(collection(restaurantRef, 'ratings')); + + // In a transaction, add the new rating and update the aggregate totals + await runTransaction(db, async (transaction) => { + const res = await transaction.get(restaurantRef); + if (!res.exists()) { + throw "Document does not exist!"; + } + + // Compute new number of ratings + const newNumRatings = res.data().numRatings + 1; + + // Compute new average rating + const oldRatingTotal = res.data().avgRating * res.data().numRatings; + const newAvgRating = (oldRatingTotal + rating) / newNumRatings; + + // Commit to Firestore + transaction.update(restaurantRef, { + numRatings: newNumRatings, + avgRating: newAvgRating + }); + transaction.set(ratingRef, { rating: rating }); + }); +} +// [END modular_add_rating_transaction] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/array_contains_any_filter.js b/snippets/firestore-next/test-firestore/array_contains_any_filter.js new file mode 100644 index 00000000..79046a5a --- /dev/null +++ b/snippets/firestore-next/test-firestore/array_contains_any_filter.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_array_contains_any_filter] +import { query, where } from "firebase/firestore"; + +const q = query(citiesRef, + where('regions', 'array-contains-any', ['west_coast', 'east_coast'])); +// [END modular_array_contains_any_filter] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/array_contains_filter.js b/snippets/firestore-next/test-firestore/array_contains_filter.js new file mode 100644 index 00000000..0771fc7a --- /dev/null +++ b/snippets/firestore-next/test-firestore/array_contains_filter.js @@ -0,0 +1,9 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_array_contains_filter] +import { query, where } from "firebase/firestore"; +const q = query(citiesRef, where("regions", "array-contains", "west_coast")); +// [END modular_array_contains_filter] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/chain_filters.js b/snippets/firestore-next/test-firestore/chain_filters.js new file mode 100644 index 00000000..993d7229 --- /dev/null +++ b/snippets/firestore-next/test-firestore/chain_filters.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_chain_filters] +import { query, where } from "firebase/firestore"; + +const q1 = query(citiesRef, where("state", "==", "CO"), where("name", "==", "Denver")); +const q2 = query(citiesRef, where("state", "==", "CA"), where("population", "<", 1000000)); +// [END modular_chain_filters] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/cities_document_set.js b/snippets/firestore-next/test-firestore/cities_document_set.js new file mode 100644 index 00000000..0950a138 --- /dev/null +++ b/snippets/firestore-next/test-firestore/cities_document_set.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_cities_document_set] +import { collection, doc, setDoc } from "firebase/firestore"; + +await setDoc(doc(collection(db, "cities"), "new-city-id"), data); +// [END modular_cities_document_set] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/city_custom_object.js b/snippets/firestore-next/test-firestore/city_custom_object.js new file mode 100644 index 00000000..c12b5c64 --- /dev/null +++ b/snippets/firestore-next/test-firestore/city_custom_object.js @@ -0,0 +1,32 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_city_custom_object] +class City { + constructor (name, state, country ) { + this.name = name; + this.state = state; + this.country = country; + } + toString() { + return this.name + ', ' + this.state + ', ' + this.country; + } +} + +// Firestore data converter +var cityConverter = { + toFirestore: function(city) { + return { + name: city.name, + state: city.state, + country: city.country + } + }, + fromFirestore: function(snapshot, options){ + const data = snapshot.data(options); + return new City(data.name, data.state, data.country) + } +} +// [END modular_city_custom_object] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/collection_reference.js b/snippets/firestore-next/test-firestore/collection_reference.js new file mode 100644 index 00000000..fb848405 --- /dev/null +++ b/snippets/firestore-next/test-firestore/collection_reference.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_collection_reference] +import { collection } from "firebase/firestore"; + +const usersCollectionRef = collection(db, 'users'); +// [END modular_collection_reference] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/data_types.js b/snippets/firestore-next/test-firestore/data_types.js new file mode 100644 index 00000000..e783c429 --- /dev/null +++ b/snippets/firestore-next/test-firestore/data_types.js @@ -0,0 +1,24 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_data_types] +import { doc, collection, setDoc, Timestamp } from "firebase/firestore"; + +const docData = { + stringExample: "Hello world!", + booleanExample: true, + numberExample: 3.14159265, + dateExample: Timestamp.fromDate(new Date("December 10, 1815")), + arrayExample: [5, true, "hello"], + nullExample: null, + objectExample: { + a: 5, + b: { + nested: "foo" + } + } +}; +await setDoc(doc(collection(db, "data"), "one"), docData); +// [END modular_data_types] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/delete_collection.js b/snippets/firestore-next/test-firestore/delete_collection.js new file mode 100644 index 00000000..78c73bbb --- /dev/null +++ b/snippets/firestore-next/test-firestore/delete_collection.js @@ -0,0 +1,48 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_delete_collection] +/** + * Delete a collection, in batches of batchSize. Note that this does + * not recursively delete subcollections of documents in the collection + */ +import { collection, query, orderBy, limit, getDocs, writeBatch } from "firebase/firestore"; + +function deleteCollection(db, collectionRef, batchSize) { + const q = query(collectionRef, orderBy('__name__'), limit(batchSize)) + + return new Promise(function(resolve) { + deleteQueryBatch(db, q, batchSize, resolve); + }); +} + +async function deleteQueryBatch(db, query, batchSize, resolve) { + const snapshot = await getDocs(query); + + // When there are no documents left, we are done + let numDeleted = 0; + if (snapshot.size > 0) { + // Delete documents in a batch + const batch = writeBatch(db); + snapshot.docs.forEach((doc) => { + batch.delete(doc.ref); + }); + + await batch.commit(); + numDeleted = snapshot.size; + } + + if (numDeleted < batchSize) { + resolve(); + return; + } + + // Recurse on the next process tick, to avoid + // exploding the stack. + setTimeout(() => { + deleteQueryBatch(db, query, batchSize, resolve); + }, 0); +} +// [END modular_delete_collection] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/delete_document.js b/snippets/firestore-next/test-firestore/delete_document.js new file mode 100644 index 00000000..aaa79012 --- /dev/null +++ b/snippets/firestore-next/test-firestore/delete_document.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_delete_document] +import { collection, doc, deleteDoc } from "firebase/firestore"; + +await deleteDoc(doc(collection(db, "cities"), "DC")); +// [END modular_delete_document] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/detach_listener.js b/snippets/firestore-next/test-firestore/detach_listener.js new file mode 100644 index 00000000..c22470cd --- /dev/null +++ b/snippets/firestore-next/test-firestore/detach_listener.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_detach_listener] +import { collection, onSnapshot } from "firebase/firestore"; + +const unsubscribe = onSnapshot(collection(db, "cities"), () => { + // Respond to data + // ... +}); + +// Later ... + +// Stop listening to changes +unsubscribe(); +// [END modular_detach_listener] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/disable_network.js b/snippets/firestore-next/test-firestore/disable_network.js new file mode 100644 index 00000000..ad9a62fb --- /dev/null +++ b/snippets/firestore-next/test-firestore/disable_network.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_disable_network] +import { disableNetwork } from "firebase/firestore"; + +await disableNetwork(db); +console.log("Network disabled!"); +// Do offline actions +// [START_EXCLUDE] +console.log("Network disabled!"); +// [END_EXCLUDE] +// [END modular_disable_network] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/doc_reference.js b/snippets/firestore-next/test-firestore/doc_reference.js new file mode 100644 index 00000000..ce16a0cb --- /dev/null +++ b/snippets/firestore-next/test-firestore/doc_reference.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_doc_reference] +import { collection, doc } from "firebase/firestore"; + +const alovelaceDocumentRef = doc(collection(db, 'users'), 'alovelace'); +// [END modular_doc_reference] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/doc_reference_alternative.js b/snippets/firestore-next/test-firestore/doc_reference_alternative.js new file mode 100644 index 00000000..fcef2915 --- /dev/null +++ b/snippets/firestore-next/test-firestore/doc_reference_alternative.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_doc_reference_alternative] +import { doc } from "firebase/firestore"; + +const alovelaceDocumentRef = doc(db, 'users/alovelace'); +// [END modular_doc_reference_alternative] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/enable_network.js b/snippets/firestore-next/test-firestore/enable_network.js new file mode 100644 index 00000000..031f90ab --- /dev/null +++ b/snippets/firestore-next/test-firestore/enable_network.js @@ -0,0 +1,14 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_enable_network] +import { enableNetwork } from "firebase/firestore"; + +await enableNetwork(db) +// Do online actions +// [START_EXCLUDE] +console.log("Network enabled!"); +// [END_EXCLUDE] +// [END modular_enable_network] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/example_data.js b/snippets/firestore-next/test-firestore/example_data.js new file mode 100644 index 00000000..1b1512c7 --- /dev/null +++ b/snippets/firestore-next/test-firestore/example_data.js @@ -0,0 +1,31 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_example_data] +import { collection, doc, setDoc } from "firebase/firestore"; + +const citiesRef = collection(db, "cities"); + +await setDoc(doc(citiesRef, "SF"), { + name: "San Francisco", state: "CA", country: "USA", + capital: false, population: 860000, + regions: ["west_coast", "norcal"] }); +await setDoc(doc(citiesRef, "LA"), { + name: "Los Angeles", state: "CA", country: "USA", + capital: false, population: 3900000, + regions: ["west_coast", "socal"] }); +await setDoc(doc(citiesRef, "DC"), { + name: "Washington, D.C.", state: null, country: "USA", + capital: true, population: 680000, + regions: ["east_coast"] }); +await setDoc(doc(citiesRef, "TOK"), { + name: "Tokyo", state: null, country: "Japan", + capital: true, population: 9000000, + regions: ["kanto", "honshu"] }); +await setDoc(doc(citiesRef, "BJ"), { + name: "Beijing", state: null, country: "China", + capital: true, population: 21500000, + regions: ["jingjinji", "hebei"] }); +// [END modular_example_data] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/example_filters.js b/snippets/firestore-next/test-firestore/example_filters.js new file mode 100644 index 00000000..c0a5eb05 --- /dev/null +++ b/snippets/firestore-next/test-firestore/example_filters.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_example_filters] +const q1 = query(citiesRef, where("state", "==", "CA")); +const q2 = query(citiesRef, where("population", "<", 100000)); +const q3 = query(citiesRef, where("name", ">=", "San Francisco")); +// [END modular_example_filters] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/filter_and_order.js b/snippets/firestore-next/test-firestore/filter_and_order.js new file mode 100644 index 00000000..2b4c7751 --- /dev/null +++ b/snippets/firestore-next/test-firestore/filter_and_order.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_filter_and_order] +import { query, where, orderBy, limit } from "firebase/firestore"; + +const q = query(citiesRef, where("population", ">", 100000), orderBy("population"), limit(2)); +// [END modular_filter_and_order] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/fs_collection_group_query.js b/snippets/firestore-next/test-firestore/fs_collection_group_query.js new file mode 100644 index 00000000..0fcf2d4e --- /dev/null +++ b/snippets/firestore-next/test-firestore/fs_collection_group_query.js @@ -0,0 +1,14 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_fs_collection_group_query] +import { collectionGroup, query, where, getDocs } from "firebase/firestore"; + +const museums = query(collectionGroup(db, 'landmarks'), where('type', '==', 'museum')); +const querySnapshot = await getDocs(museums); +querySnapshot.forEach((doc) => { + console.log(doc.id, ' => ', doc.data()); +}); +// [END modular_fs_collection_group_query] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js b/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js new file mode 100644 index 00000000..47fd6a4b --- /dev/null +++ b/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js @@ -0,0 +1,53 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_fs_collection_group_query_data_setup] +import { collection, doc, setDoc } from "firebase/firestore"; + +const citiesRef = collection(db, 'cities'); + +await Promise.all([ + setDoc(doc(collection(doc(citiesRef, 'SF'), 'landmarks')), { + name: 'Golden Gate Bridge', + type: 'bridge' + }), + setDoc(doc(collection(doc(citiesRef, 'SF'), 'landmarks')), { + name: 'Legion of Honor', + type: 'museum' + }), + setDoc(doc(collection(doc(citiesRef, 'LA'), 'landmarks')), { + name: 'Griffith Park', + type: 'park' + }), + setDoc(doc(collection(doc(citiesRef, 'LA'), 'landmarks')), { + name: 'The Getty', + type: 'museum' + }), + setDoc(doc(collection(doc(citiesRef, 'DC'), 'landmarks')), { + name: 'Lincoln Memorial', + type: 'memorial' + }), + setDoc(doc(collection(doc(citiesRef, 'DC'), 'landmarks')), { + name: 'National Air and Space Museum', + type: 'museum' + }), + setDoc(doc(collection(doc(citiesRef, 'TOK'), 'landmarks')), { + name: 'Ueno Park', + type: 'park' + }), + setDoc(doc(collection(doc(citiesRef, 'TOK'), 'landmarks')), { + name: 'National Museum of Nature and Science', + type: 'museum' + }), + setDoc(doc(collection(doc(citiesRef, 'BJ'), 'landmarks')), { + name: 'Jingshan Park', + type: 'park' + }), + setDoc(doc(collection(doc(citiesRef, 'BJ'), 'landmarks')), { + name: 'Beijing Ancient Observatory', + type: 'museum' + }) +]); +// [END modular_fs_collection_group_query_data_setup] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/fs_setup_cache.js b/snippets/firestore-next/test-firestore/fs_setup_cache.js new file mode 100644 index 00000000..4960b369 --- /dev/null +++ b/snippets/firestore-next/test-firestore/fs_setup_cache.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_fs_setup_cache] +import { initializeFirestore, CACHE_SIZE_UNLIMITED } from "firebase/firestore"; + +const firestoreDb = initializeFirestore(app, { + cacheSizeBytes: CACHE_SIZE_UNLIMITED +}); +// [END modular_fs_setup_cache] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_all_users.js b/snippets/firestore-next/test-firestore/get_all_users.js new file mode 100644 index 00000000..57585bda --- /dev/null +++ b/snippets/firestore-next/test-firestore/get_all_users.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_get_all_users] +import { collection, getDocs } from "firebase/firestore"; + +const querySnapshot = await getDocs(collection(db, "users")); +querySnapshot.forEach((doc) => { + console.log(`${doc.id} => ${doc.data()}`); +}); +// [END modular_get_all_users] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_custom_object.js b/snippets/firestore-next/test-firestore/get_custom_object.js new file mode 100644 index 00000000..abbf98eb --- /dev/null +++ b/snippets/firestore-next/test-firestore/get_custom_object.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_get_custom_object] +import { doc, collection, getDoc} from "firebase/firestore"; + +const ref = doc(collection(db, "cities"), "LA").withConverter(cityConverter); +const docSnap = await getDoc(ref); +if (docSnap.exists()) { + // Convert to City object + const city = docSnap.data(); + // Use a City instance method + console.log(city.toString()); +} else { + console.log("No such document!") +} +// [END modular_get_custom_object] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_document.js b/snippets/firestore-next/test-firestore/get_document.js new file mode 100644 index 00000000..9ff21ba6 --- /dev/null +++ b/snippets/firestore-next/test-firestore/get_document.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_get_document] +import { collection, doc, getDoc } from "firebase/firestore"; + +const docRef = doc(collection(db, "cities"), "SF"); +const docSnap = await getDoc(docRef); + +if (docSnap.exists()) { + console.log("Document data:", docSnap.data()); +} else { + // doc.data() will be undefined in this case + console.log("No such document!"); +} +// [END modular_get_document] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_document_options.js b/snippets/firestore-next/test-firestore/get_document_options.js new file mode 100644 index 00000000..30c0202a --- /dev/null +++ b/snippets/firestore-next/test-firestore/get_document_options.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_get_document_options] +import { collection, doc, getDocFromCache } from "firebase/firestore"; + +const docRef = doc(collection(db, "cities"), "SF"); + +// Get a document, forcing the SDK to fetch from the offline cache. +try { + const doc = await getDocFromCache(docRef); + + // Document was found in the cache. If no cached document exists, + // an error will be returned to the 'catch' block below. + console.log("Cached document data:", doc.data()); +} catch (e) { + console.log("Error getting cached document:", e); +} +// [END modular_get_document_options] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_multiple.js b/snippets/firestore-next/test-firestore/get_multiple.js new file mode 100644 index 00000000..520765cf --- /dev/null +++ b/snippets/firestore-next/test-firestore/get_multiple.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_get_multiple] +import { collection, query, where, getDocs } from "firebase/firestore"; + +const q = query(collection(db, "cities"), where("capital", "==", true)); + +const querySnapshot = await getDocs(q); +querySnapshot.forEach((doc) => { + // doc.data() is never undefined for query doc snapshots + console.log(doc.id, " => ", doc.data()); +}); +// [END modular_get_multiple] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_multiple_all.js b/snippets/firestore-next/test-firestore/get_multiple_all.js new file mode 100644 index 00000000..b306e657 --- /dev/null +++ b/snippets/firestore-next/test-firestore/get_multiple_all.js @@ -0,0 +1,14 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_get_multiple_all] +import { collection, getDocs } from "firebase/firestore"; + +const querySnapshot = await getDocs(collection(db, "cities")); +querySnapshot.forEach((doc) => { + // doc.data() is never undefined for query doc snapshots + console.log(doc.id, " => ", doc.data()); +}); +// [END modular_get_multiple_all] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/handle_listen_errors.js b/snippets/firestore-next/test-firestore/handle_listen_errors.js new file mode 100644 index 00000000..76012826 --- /dev/null +++ b/snippets/firestore-next/test-firestore/handle_listen_errors.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_handle_listen_errors] +import { collection, onSnapshot } from "firebase/firestore"; + +const unsubscribe = onSnapshot( + collection(db, "cities"), + (snapshot) => { + // ... + }, + (error) => { + // ... + }); +// [END modular_handle_listen_errors] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/in_filter.js b/snippets/firestore-next/test-firestore/in_filter.js new file mode 100644 index 00000000..4e752152 --- /dev/null +++ b/snippets/firestore-next/test-firestore/in_filter.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_in_filter] +import { query, where } from "firebase/firestore"; + +const q = query(citiesRef, where('country', 'in', ['USA', 'Japan'])); +// [END modular_in_filter] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/in_filter_with_array.js b/snippets/firestore-next/test-firestore/in_filter_with_array.js new file mode 100644 index 00000000..b3f1574c --- /dev/null +++ b/snippets/firestore-next/test-firestore/in_filter_with_array.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_in_filter_with_array] +import { query, where } from "firebase/firestore"; + +const q = query(citiesRef, where('regions', 'in', [['west_coast', 'east_coast']])); +// [END modular_in_filter_with_array] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/initialize_persistence.js b/snippets/firestore-next/test-firestore/initialize_persistence.js new file mode 100644 index 00000000..174539a1 --- /dev/null +++ b/snippets/firestore-next/test-firestore/initialize_persistence.js @@ -0,0 +1,22 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_initialize_persistence] +import { enableIndexedDbPersistence } from "firebase/firestore"; + +enableIndexedDbPersistence(db) + .catch((err) => { + if (err.code == 'failed-precondition') { + // Multiple tabs open, persistence can only be enabled + // in one tab at a a time. + // ... + } else if (err.code == 'unimplemented') { + // The current browser does not support all of the + // features required to enable persistence + // ... + } + }); +// Subsequent queries will use persistence, if it was enabled successfully +// [END modular_initialize_persistence] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/invalid_filter_and_order.js b/snippets/firestore-next/test-firestore/invalid_filter_and_order.js new file mode 100644 index 00000000..f24b3766 --- /dev/null +++ b/snippets/firestore-next/test-firestore/invalid_filter_and_order.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_invalid_filter_and_order] +import { query, where, orderBy } from "firebase/firestore"; + +const q = query(citiesRef, where("population", ">", 100000), orderBy("country")); +// [END modular_invalid_filter_and_order] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/invalid_range_filters.js b/snippets/firestore-next/test-firestore/invalid_range_filters.js new file mode 100644 index 00000000..d622ec8f --- /dev/null +++ b/snippets/firestore-next/test-firestore/invalid_range_filters.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_invalid_range_filters] +import { query, where } from "firebase/firestore"; + +const q = query(citiesRef, where("state", ">=", "CA"), where("population", ">", 100000)); +// [END modular_invalid_range_filters] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_diffs.js b/snippets/firestore-next/test-firestore/listen_diffs.js new file mode 100644 index 00000000..96fba665 --- /dev/null +++ b/snippets/firestore-next/test-firestore/listen_diffs.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_listen_diffs] +import { collection, query, where, onSnapshot } from "firebase/firestore"; + +const q = query(collection(db, "cities"), where("state", "==", "CA")); +const unsubscribe = onSnapshot(q, (snapshot) => { + snapshot.docChanges().forEach((change) => { + if (change.type === "added") { + console.log("New city: ", change.doc.data()); + } + if (change.type === "modified") { + console.log("Modified city: ", change.doc.data()); + } + if (change.type === "removed") { + console.log("Removed city: ", change.doc.data()); + } + }); +}); +// [END modular_listen_diffs] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_document.js b/snippets/firestore-next/test-firestore/listen_document.js new file mode 100644 index 00000000..3900cba7 --- /dev/null +++ b/snippets/firestore-next/test-firestore/listen_document.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_listen_document] +import { collection, doc, onSnapshot } from "firebase/firestore"; + +const unsub = onSnapshot(doc(collection(db, "cities"), "SF"), (doc) => { + console.log("Current data: ", doc.data()); +}); +// [END modular_listen_document] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_document_local.js b/snippets/firestore-next/test-firestore/listen_document_local.js new file mode 100644 index 00000000..09e3b56d --- /dev/null +++ b/snippets/firestore-next/test-firestore/listen_document_local.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_listen_document_local] +import { collection, doc, onSnapshot } from "firebase/firestore"; + +const unsub = onSnapshot(doc(collection(db, "cities"), "SF"), (doc) => { + const source = doc.metadata.hasPendingWrites ? "Local" : "Server"; + console.log(source, " data: ", doc.data()); +}); +// [END modular_listen_document_local] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_for_users.js b/snippets/firestore-next/test-firestore/listen_for_users.js new file mode 100644 index 00000000..32c9a602 --- /dev/null +++ b/snippets/firestore-next/test-firestore/listen_for_users.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_listen_for_users] +import { collection, where, query, onSnapshot } from "firebase/firestore"; + +const q = query(collection(db, "users"), where("born", "<", 1900)); +const unsubscribe = onSnapshot(q, (snapshot) => { + console.log("Current users born before 1900:"); + snapshot.forEach(function (userSnapshot) { + console.log(userSnapshot.data()) + }); +}); +// [END modular_listen_for_users] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_multiple.js b/snippets/firestore-next/test-firestore/listen_multiple.js new file mode 100644 index 00000000..a5377c57 --- /dev/null +++ b/snippets/firestore-next/test-firestore/listen_multiple.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_listen_multiple] +import { collection, query, where, onSnapshot } from "firebase/firestore"; + +const q = query(collection(db, "cities"), where("state", "==", "CA")); +const unsubscribe = onSnapshot(q, (querySnapshot) => { + const cities = []; + querySnapshot.forEach((doc) => { + cities.push(doc.data().name); + }); + console.log("Current cities in CA: ", cities.join(", ")); +}); +// [END modular_listen_multiple] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_with_metadata.js b/snippets/firestore-next/test-firestore/listen_with_metadata.js new file mode 100644 index 00000000..93fc59b1 --- /dev/null +++ b/snippets/firestore-next/test-firestore/listen_with_metadata.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_listen_with_metadata] +import { collection, doc, onSnapshot } from "firebase/firestore"; + +const unsub = onSnapshot( + doc(collection(db, "cities"), "SF"), + { includeMetadataChanges: true }, + (doc) => { + // ... + }); +// [END modular_listen_with_metadata] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/new_document.js b/snippets/firestore-next/test-firestore/new_document.js new file mode 100644 index 00000000..c854d854 --- /dev/null +++ b/snippets/firestore-next/test-firestore/new_document.js @@ -0,0 +1,14 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_new_document] +import { collection, doc, setDoc } from "firebase/firestore"; + +// Add a new document with a generated id +const newCityRef = doc(collection(db, "cities")); + +// later... +await setDoc(newCityRef, data); +// [END modular_new_document] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/order_and_end.js b/snippets/firestore-next/test-firestore/order_and_end.js new file mode 100644 index 00000000..23184342 --- /dev/null +++ b/snippets/firestore-next/test-firestore/order_and_end.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_order_and_end] +import { query, orderBy, endAt } from "firebase/firestore"; + +const q = query(citiesRef, orderBy("population"), endAt(1000000)); +// [END modular_order_and_end] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/order_and_limit.js b/snippets/firestore-next/test-firestore/order_and_limit.js new file mode 100644 index 00000000..344e231d --- /dev/null +++ b/snippets/firestore-next/test-firestore/order_and_limit.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_order_and_limit] +import { query, orderBy, limit } from "firebase/firestore"; + +const q = query(citiesRef, orderBy("name"), limit(3)); +// [END modular_order_and_limit] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/order_and_limit_desc.js b/snippets/firestore-next/test-firestore/order_and_limit_desc.js new file mode 100644 index 00000000..13dee6bc --- /dev/null +++ b/snippets/firestore-next/test-firestore/order_and_limit_desc.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_order_and_limit_desc] +import { query, orderBy, limit } from "firebase/firestore"; + +const q = query(citiesRef, orderBy("name", "desc"), limit(3)); +// [END modular_order_and_limit_desc] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/order_and_start.js b/snippets/firestore-next/test-firestore/order_and_start.js new file mode 100644 index 00000000..76c73863 --- /dev/null +++ b/snippets/firestore-next/test-firestore/order_and_start.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_order_and_start] +import { query, orderBy, startAt } from "firebase/firestore"; + +const q = query(citiesRef, orderBy("population"), startAt(1000000)); +// [END modular_order_and_start] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/order_multiple.js b/snippets/firestore-next/test-firestore/order_multiple.js new file mode 100644 index 00000000..984b4c9a --- /dev/null +++ b/snippets/firestore-next/test-firestore/order_multiple.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_order_multiple] +import { query, orderBy } from "firebase/firestore"; + +const q = query(citiesRef, orderBy("state"), orderBy("population", "desc")); +// [END modular_order_multiple] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/paginate.js b/snippets/firestore-next/test-firestore/paginate.js new file mode 100644 index 00000000..bded9e4e --- /dev/null +++ b/snippets/firestore-next/test-firestore/paginate.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_paginate] +import { collection, query, orderBy, startAfter, limit, getDocs } from "firebase/firestore"; + +// Query the first page of docs +const first = query(collection(db, "cities"), orderBy("population"), limit(25)); +const documentSnapshots = await getDocs(first); + +// Get the last visible document +const lastVisible = documentSnapshots.docs[documentSnapshots.docs.length-1]; +console.log("last", lastVisible); + +// Construct a new query starting at this document, +// get the next 25 cities. +const next = query(collection(db, "cities"), + orderBy("population"), + startAfter(lastVisible), + limit(25)); +// [END modular_paginate] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js b/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js new file mode 100644 index 00000000..fcc8fbdd --- /dev/null +++ b/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js @@ -0,0 +1,26 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_server_timestamp_resolution_options] +import { collection, doc, updateDoc, serverTimestamp, onSnapshot } from "firebase/firestore"; +// Perform an update followed by an immediate read without +// waiting for the update to complete. Due to the snapshot +// options we will get two results: one with an estimate +// timestamp and one with the resolved server timestamp. +const docRef = doc(collection(db, 'objects'), 'some-id'); +updateDoc(docRef, { + timestamp: serverTimestamp() +}); + +onSnapshot(docRef, (snapshot) => { + const data = snapshot.data({ + // Options: 'estimate', 'previous', or 'none' + serverTimestamps: "estimate" + }); + console.log( + 'Timestamp: ' + data.timestamp + + ', pending: ' + snapshot.metadata.hasPendingWrites); +}); +// [END modular_server_timestamp_resolution_options] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/set_custom_object.js b/snippets/firestore-next/test-firestore/set_custom_object.js new file mode 100644 index 00000000..e76639b7 --- /dev/null +++ b/snippets/firestore-next/test-firestore/set_custom_object.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_set_custom_object] +import { doc, collection, setDoc } from "firebase/firestore"; + +// Set with cityConverter +const ref = doc(collection(db, "cities"), "LA").withConverter(cityConverter); +await setDoc(ref, new City("Los Angeles", "CA", "USA")); +// [END modular_set_custom_object] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/set_document.js b/snippets/firestore-next/test-firestore/set_document.js new file mode 100644 index 00000000..e6c7040b --- /dev/null +++ b/snippets/firestore-next/test-firestore/set_document.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_set_document] +import { doc, collection, setDoc } from "firebase/firestore"; + +// Add a new document in collection "cities" +await setDoc(doc(collection(db, "cities"), "LA"), { + name: "Los Angeles", + state: "CA", + country: "USA" +}); +// [END modular_set_document] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/set_with_merge.js b/snippets/firestore-next/test-firestore/set_with_merge.js new file mode 100644 index 00000000..8957fe29 --- /dev/null +++ b/snippets/firestore-next/test-firestore/set_with_merge.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_set_with_merge] +import { doc, collection, setDoc } from "firebase/firestore"; + +const cityRef = doc(collection(db, 'cities'), 'BJ'); +setDoc(cityRef, { capital: true }, { merge: true }); +// [END modular_set_with_merge] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/simple_queries.js b/snippets/firestore-next/test-firestore/simple_queries.js new file mode 100644 index 00000000..90449071 --- /dev/null +++ b/snippets/firestore-next/test-firestore/simple_queries.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_simple_queries] +// Create a reference to the cities collection +import { collection, query, where } from "firebase/firestore"; +const citiesRef = collection(db, "cities"); + +// Create a query against the collection. +const q = query(citiesRef, where("state", "==", "CA")); +// [END modular_simple_queries] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/simple_queries_again.js b/snippets/firestore-next/test-firestore/simple_queries_again.js new file mode 100644 index 00000000..41616318 --- /dev/null +++ b/snippets/firestore-next/test-firestore/simple_queries_again.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_simple_queries_again] +import { collection, query, where } from "firebase/firestore"; +const citiesRef = collection(db, "cities"); + +const q = query(citiesRef, where("capital", "==", true)); +// [END modular_simple_queries_again] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/start_doc.js b/snippets/firestore-next/test-firestore/start_doc.js new file mode 100644 index 00000000..853a75ed --- /dev/null +++ b/snippets/firestore-next/test-firestore/start_doc.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_start_doc] +import { collection, doc, getDoc, query, orderBy, startAt } from "firebase/firestore"; +const citiesRef = collection(db, "cities"); + +const docSnap = await getDoc(doc(citiesRef, "SF")); + +// Get all cities with a population bigger than San Francisco +const biggerThanSf = query(citiesRef, orderBy("popuation"), startAt(docSnap)); +// ... +// [END modular_start_doc] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/start_multiple_orderby.js b/snippets/firestore-next/test-firestore/start_multiple_orderby.js new file mode 100644 index 00000000..a2782678 --- /dev/null +++ b/snippets/firestore-next/test-firestore/start_multiple_orderby.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_start_multiple_orderby] +// Will return all Springfields +import { collection, query, orderBy, startAt } from "firebase/firestore"; +const q1 = query(collection(db, "cities"), + orderBy("name"), + orderBy("state"), + startAt("Springfield")); + +// Will return "Springfield, Missouri" and "Springfield, Wisconsin" +const q2 = query(collection(db, "cities"), + orderBy("name"), + orderBy("state"), + startAt("Springfield", "Missouri")); +// [END modular_start_multiple_orderby] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/subcollection_reference.js b/snippets/firestore-next/test-firestore/subcollection_reference.js new file mode 100644 index 00000000..5ea77ae4 --- /dev/null +++ b/snippets/firestore-next/test-firestore/subcollection_reference.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_subcollection_reference] +import { doc, collection } from "firebase/firestore"; + +const messageRef = doc(collection(doc(collection(db, "rooms"), "roomA"), "messages"), "message1"); +// [END modular_subcollection_reference] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/transaction.js b/snippets/firestore-next/test-firestore/transaction.js new file mode 100644 index 00000000..0591ade9 --- /dev/null +++ b/snippets/firestore-next/test-firestore/transaction.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_transaction] +import { runTransaction } from "firebase/firestore"; + +try { + await runTransaction(db, async (transaction) => { + const sfDoc = await transaction.get(sfDocRef); + if (!sfDoc.exists()) { + throw "Document does not exist!"; + } + + const newPopulation = sfDoc.data().population + 1; + transaction.update(sfDocRef, { population: newPopulation }); + }); + console.log("Transaction successfully committed!"); +} catch (e) { + console.log("Transaction failed: ", e); +} +// [END modular_transaction] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/transaction_promise.js b/snippets/firestore-next/test-firestore/transaction_promise.js new file mode 100644 index 00000000..9d76243f --- /dev/null +++ b/snippets/firestore-next/test-firestore/transaction_promise.js @@ -0,0 +1,32 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_transaction_promise] +import { collection, doc, runTransaction } from "firebase/firestore"; + +// Create a reference to the SF doc. +const sfDocRef = doc(collection(db, "cities"), "SF"); + +try { + const newPopulation = await runTransaction(db, async (transaction) => { + const sfDoc = await transaction.get(sfDocRef); + if (!sfDoc.exists()) { + throw "Document does not exist!"; + } + + const newPop = sfDoc.data().population + 1; + if (newPop <= 1000000) { + transaction.update(sfDocRef, { population: newPop }); + } else { + return Promise.reject("Sorry! Population is too big"); + } + }); + + console.log("Population increased to ", newPopulation); +} catch (e) { + // This will be a "population is too big" error. + console.error(e); +} +// [END modular_transaction_promise] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_delete_field.js b/snippets/firestore-next/test-firestore/update_delete_field.js new file mode 100644 index 00000000..007db2d3 --- /dev/null +++ b/snippets/firestore-next/test-firestore/update_delete_field.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_update_delete_field] +import { doc, collection, updateDoc, deleteField } from "firebase/firestore"; + +const cityRef = doc(collection(db, 'cities'), 'BJ'); + +// Remove the 'capital' field from the document +await updateDoc(cityRef, { + capital: deleteField() +}); +// [END modular_update_delete_field] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_document.js b/snippets/firestore-next/test-firestore/update_document.js new file mode 100644 index 00000000..eb17b744 --- /dev/null +++ b/snippets/firestore-next/test-firestore/update_document.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_update_document] +import { collection, doc, updateDoc } from "firebase/firestore"; + +const washingtonRef = doc(collection(db, "cities"), "DC"); + +// Set the "capital" field of the city 'DC' +await updateDoc(washingtonRef, { + capital: true +}); +// [END modular_update_document] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_document_array.js b/snippets/firestore-next/test-firestore/update_document_array.js new file mode 100644 index 00000000..39c59bdb --- /dev/null +++ b/snippets/firestore-next/test-firestore/update_document_array.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_update_document_array] +import { collection, doc, updateDoc, arrayUnion, arrayRemove } from "firebase/firestore"; + +const washingtonRef = doc(collection(db, "cities"), "DC"); + +// Atomically add a new region to the "regions" array field. +await updateDoc(washingtonRef, { + regions: arrayUnion("greater_virginia") +}); + +// Atomically remove a region from the "regions" array field. +await updateDoc(washingtonRef, { + regions: arrayRemove("east_coast") +}); +// [END modular_update_document_array] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_document_increment.js b/snippets/firestore-next/test-firestore/update_document_increment.js new file mode 100644 index 00000000..05ff44eb --- /dev/null +++ b/snippets/firestore-next/test-firestore/update_document_increment.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_update_document_increment] +import { collection, doc, updateDoc, increment } from "firebase/firestore"; + +const washingtonRef = doc(collection(db, "cities"), "DC"); + +// Atomically increment the population of the city by 50. +await updateDoc(washingtonRef, { + population: increment(50) +}); +// [END modular_update_document_increment] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_document_nested.js b/snippets/firestore-next/test-firestore/update_document_nested.js new file mode 100644 index 00000000..0efd286c --- /dev/null +++ b/snippets/firestore-next/test-firestore/update_document_nested.js @@ -0,0 +1,22 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_update_document_nested] +import { doc, collection, setDoc, updateDoc } from "firebase/firestore"; + +// Create an initial document to update. +const frankDocRef = doc(collection(db, "users"), "frank"); +await setDoc(frankDocRef, { + name: "Frank", + favorites: { food: "Pizza", color: "Blue", subject: "recess" }, + age: 12 +}); + +// To update age and favorite color: +await updateDoc(frankDocRef, { + "age": 13, + "favorites.color": "Red" +}); +// [END modular_update_document_nested] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_with_server_timestamp.js b/snippets/firestore-next/test-firestore/update_with_server_timestamp.js new file mode 100644 index 00000000..3fa9febc --- /dev/null +++ b/snippets/firestore-next/test-firestore/update_with_server_timestamp.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_update_with_server_timestamp] +import { collection, updateDoc, serverTimestamp } from "firebase/firestore"; + +const docRef = doc(collection(db, 'objects'), 'some-id'); + +// Update the timestamp field with the value from the server +const updateTimestamp = await updateDoc(docRef, { + timestamp: serverTimestamp() +}); +// [END modular_update_with_server_timestamp] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/use_from_cache.js b/snippets/firestore-next/test-firestore/use_from_cache.js new file mode 100644 index 00000000..dc689d8a --- /dev/null +++ b/snippets/firestore-next/test-firestore/use_from_cache.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_use_from_cache] +import { collection, onSnapshot, where, query } from "firebase/firestore"; + +const q = query(collection(db, "cities"), where("state", "==", "CA")); +onSnapshot(q, { includeMetadataChanges: true }, (snapshot) => { + snapshot.docChanges().forEach((change) => { + if (change.type === "added") { + console.log("New city: ", change.doc.data()); + } + + const source = snapshot.metadata.fromCache ? "local cache" : "server"; + console.log("Data came from " + source); + }); +}); +// [END modular_use_from_cache] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/valid_filter_and_order.js b/snippets/firestore-next/test-firestore/valid_filter_and_order.js new file mode 100644 index 00000000..fc4d54f0 --- /dev/null +++ b/snippets/firestore-next/test-firestore/valid_filter_and_order.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_valid_filter_and_order] +import { query, where, orderBy } from "firebase/firestore"; + +const q = query(citiesRef, where("population", ">", 100000), orderBy("population")); +// [END modular_valid_filter_and_order] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/valid_range_filters.js b/snippets/firestore-next/test-firestore/valid_range_filters.js new file mode 100644 index 00000000..bd39bac2 --- /dev/null +++ b/snippets/firestore-next/test-firestore/valid_range_filters.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_valid_range_filters] +import { query, where } from "firebase/firestore"; + +const q1 = query(citiesRef, where("state", ">=", "CA"), where("state", "<=", "IN")); +const q2 = query(citiesRef, where("state", "==", "CA"), where("population", ">", 1000000)); +// [END modular_valid_range_filters] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/write_batch.js b/snippets/firestore-next/test-firestore/write_batch.js new file mode 100644 index 00000000..605cdbb7 --- /dev/null +++ b/snippets/firestore-next/test-firestore/write_batch.js @@ -0,0 +1,26 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_write_batch] +import { writeBatch, doc, collection } from "firebase/firestore"; + +// Get a new write batch +const batch = writeBatch(db); + +// Set the value of 'NYC' +const nycRef = doc(collection(db, "cities"), "NYC"); +batch.set(nycRef, {name: "New York City"}); + +// Update the population of 'SF' +const sfRef = doc(collection(db, "cities"), "SF"); +batch.update(sfRef, {"population": 1000000}); + +// Delete the city 'LA' +const laRef = doc(collection(db, "cities"), "LA"); +batch.delete(laRef); + +// Commit the batch +await batch.commit(); +// [END modular_write_batch] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js b/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js new file mode 100644 index 00000000..2b690134 --- /dev/null +++ b/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-aggregation.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_get_collection_ratings] +import { collection, doc, getDocs } from "firebase/firestore"; + +const ratingsRef = collection(doc(collection(db, "restaurants"), "arinell-pizza"), "ratings"); +const ratingsDocs = await getDocs(ratingsRef); +// [END modular_get_collection_ratings] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-aggregation/sample_doc.js b/snippets/firestore-next/test-solution-aggregation/sample_doc.js new file mode 100644 index 00000000..2c25bc70 --- /dev/null +++ b/snippets/firestore-next/test-solution-aggregation/sample_doc.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-aggregation.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_sample_doc] +const arinellDoc = { + name: 'Arinell Pizza', + avgRating: 4.65, + numRatings: 683 +} +// [END modular_sample_doc] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/post_with_array.js b/snippets/firestore-next/test-solution-arrays/post_with_array.js new file mode 100644 index 00000000..2c3e5985 --- /dev/null +++ b/snippets/firestore-next/test-solution-arrays/post_with_array.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-arrays.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_post_with_array] +// Sample document in the 'posts' collection. +{ + title: "My great post", + categories: [ + "technology", + "opinion", + "cats" + ] +} +// [END modular_post_with_array] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/post_with_map.js b/snippets/firestore-next/test-solution-arrays/post_with_map.js new file mode 100644 index 00000000..59286b89 --- /dev/null +++ b/snippets/firestore-next/test-solution-arrays/post_with_map.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-arrays.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_post_with_map] +// Sample document in the 'posts' collection +{ + title: "My great post", + categories: { + "technology": true, + "opinion": true, + "cats": true + } +} +// [END modular_post_with_map] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js b/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js new file mode 100644 index 00000000..3553248c --- /dev/null +++ b/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-arrays.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_post_with_map_advanced] +// The value of each entry in 'categories' is a unix timestamp +{ + title: "My great post", + categories: { + technology: 1502144665, + opinion: 1502144665, + cats: 1502144665 + } +} +// [END modular_post_with_map_advanced] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category.js b/snippets/firestore-next/test-solution-arrays/query_in_category.js new file mode 100644 index 00000000..3388cdb5 --- /dev/null +++ b/snippets/firestore-next/test-solution-arrays/query_in_category.js @@ -0,0 +1,14 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-arrays.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_query_in_category] +import { collection, getDocs, query, where } from "firebase/firestore"; + +// Find all documents in the 'posts' collection that are +// in the 'cats' category. +const q = query(collection(db, "posts"), where("categories.cats", "==", true)); +const docs = await getDocs(q); +// ... +// [END modular_query_in_category] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js new file mode 100644 index 00000000..6c6c0726 --- /dev/null +++ b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-arrays.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_query_in_category_timestamp] +import { collection, query, where, orderBy } from "@firebase/firestore"; + +const q = query(collection(db, "posts"), + where("categories.cats", ">", 0), + orderBy("categories.cats")); +// [END modular_query_in_category_timestamp] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js new file mode 100644 index 00000000..511acbfd --- /dev/null +++ b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-arrays.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_query_in_category_timestamp_invalid] +import { collection, query, where, orderBy, FirebaseFirestore } from "@firebase/firestore"; + +const q = query(collection(db, "posts"), + where("categories.cats", "==", true), + orderBy("timestamp")); +// [END modular_query_in_category_timestamp_invalid] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-counters/create_counter.js b/snippets/firestore-next/test-solution-counters/create_counter.js new file mode 100644 index 00000000..4cc05cb9 --- /dev/null +++ b/snippets/firestore-next/test-solution-counters/create_counter.js @@ -0,0 +1,24 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-counters.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_create_counter] +function createCounter(ref, num_shards) { + import { collection, doc, writeBatch } from "firebase/firestore"; + + const batch = writeBatch(db); + + // Initialize the counter document + batch.set(ref, { num_shards: num_shards }); + + // Initialize each shard with count=0 + for (let i = 0; i < num_shards; i++) { + const shardRef = doc(collection(ref, 'shards'), i.toString()); + batch.set(shardRef, { count: 0 }); + } + + // Commit the write batch + return batch.commit(); +} +// [END modular_create_counter] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-counters/get_count.js b/snippets/firestore-next/test-solution-counters/get_count.js new file mode 100644 index 00000000..dcf61f55 --- /dev/null +++ b/snippets/firestore-next/test-solution-counters/get_count.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-counters.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_get_count] +async function getCount(ref) { + import { collection, getDocs } from "@firebase/firestore"; + + // Sum the count of each shard in the subcollection + const snapshot = await getDocs(collection(ref, 'shards')); + + let totalCount = 0; + snapshot.forEach(doc => { + totalCount += doc.data().count; + }); + + return totalCount; +} +// [END modular_get_count] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-counters/increment_counter.js b/snippets/firestore-next/test-solution-counters/increment_counter.js new file mode 100644 index 00000000..53f5f28a --- /dev/null +++ b/snippets/firestore-next/test-solution-counters/increment_counter.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-counters.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_increment_counter] +function incrementCounter(db, ref, num_shards) { + import { collection, doc, updateDoc, increment, FirebaseFirestore } from "@firebase/firestore"; + + // Select a shard of the counter at random + const shardId = Math.floor(Math.random() * num_shards).toString(); + const shardRef = doc(collection(ref, 'shards'), shardId); + + // Update count + return updateDoc(shardRef, "count", increment(1)); +} +// [END modular_increment_counter] \ No newline at end of file diff --git a/snippets/functions-next/emulator-suite/functions_callable_call.js b/snippets/functions-next/emulator-suite/functions_callable_call.js new file mode 100644 index 00000000..ad4a3bdb --- /dev/null +++ b/snippets/functions-next/emulator-suite/functions_callable_call.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./functions-next/emulator-suite.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_functions_callable_call] +import { getApp } from "firebase/app"; +import { getFunctions, httpsCallable } from "firebase/functions"; + +const functions = getFunctions(getApp()); +const addMessage = httpsCallable(functions, 'addMessage'); + +const result = await addMessage({ text: ''}); +const sanitizedMessage = result.data.text; +// ... +// [END modular_functions_callable_call] \ No newline at end of file diff --git a/snippets/functions-next/emulator-suite/functions_emulator_connect.js b/snippets/functions-next/emulator-suite/functions_emulator_connect.js new file mode 100644 index 00000000..3ac3bfc8 --- /dev/null +++ b/snippets/functions-next/emulator-suite/functions_emulator_connect.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./functions-next/emulator-suite.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_functions_emulator_connect] +import { getApp } from "firebase/app"; +import { getFunctions, useFunctionsEmulator } from "firebase/functions"; + +const functions = getFunctions(getApp()); +useFunctionsEmulator(functions, "http://localhost:5001"); +// [END modular_functions_emulator_connect] \ No newline at end of file From 81c77f1feda043e958af5d538fc18fea87ed2410 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 28 Sep 2020 09:18:24 -0700 Subject: [PATCH 007/235] Auto-update dependencies. (#38) Co-authored-by: Sam --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore-next/package.json | 2 +- firestore/package.json | 2 +- functions-next/emulator-suite.js | 8 ++++---- functions-next/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- .../emulator-suite/functions_callable_call.js | 4 ++-- .../emulator-suite/functions_emulator_connect.js | 4 ++-- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/auth/package.json b/auth/package.json index 63a838e7..4f6dd1a1 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.12.0" + "firebase": "^7.21.1" } } diff --git a/database/package.json b/database/package.json index e3db58fe..e88e4724 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.12.0" + "firebase": "^7.21.1" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 3ab5707b..3339c55e 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.9.2" + "firebase": "^7.21.1" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 310f730b..3f3c7e5e 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^0.800.7" + "firebase": "^7.21.1" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/firestore/package.json b/firestore/package.json index d9e1b2d6..605c66af 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.20.0" + "firebase": "^7.21.1" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/functions-next/emulator-suite.js b/functions-next/emulator-suite.js index c2e1b535..1a210072 100644 --- a/functions-next/emulator-suite.js +++ b/functions-next/emulator-suite.js @@ -9,20 +9,20 @@ initializeApp({ export function emulatorSettings() { // [START functions_emulator_connect] - const { getApp } = require("firebase/app"); + const { app } = require("firebase/app"); const { getFunctions, useFunctionsEmulator } = require( "firebase/functions"); - const functions = getFunctions(getApp()); + const functions = getFunctions(app()); useFunctionsEmulator(functions, "http://localhost:5001"); // [END functions_emulator_connect] } export async function callFunction() { // [START functions_callable_call] - const { getApp } = require("firebase/app"); + const { app } = require("firebase/app"); const { getFunctions, httpsCallable } = require( "firebase/functions"); - const functions = getFunctions(getApp()); + const functions = getFunctions(app()); const addMessage = httpsCallable(functions, 'addMessage'); const result = await addMessage({ text: ''}); diff --git a/functions-next/package.json b/functions-next/package.json index cb5ad467..dfab6e62 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -7,6 +7,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^0.800.3" + "firebase": "^7.21.1" } } diff --git a/functions/package.json b/functions/package.json index aecac9f7..12c119ed 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.17.1" + "firebase": "^7.21.1" } } diff --git a/installations/package.json b/installations/package.json index 78d5f8b4..86d78339 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.19.1" + "firebase": "^7.21.1" } } diff --git a/snippets/functions-next/emulator-suite/functions_callable_call.js b/snippets/functions-next/emulator-suite/functions_callable_call.js index ad4a3bdb..f18d3056 100644 --- a/snippets/functions-next/emulator-suite/functions_callable_call.js +++ b/snippets/functions-next/emulator-suite/functions_callable_call.js @@ -4,10 +4,10 @@ // To make edits to the snippets in this file, please edit the source // [START modular_functions_callable_call] -import { getApp } from "firebase/app"; +import { app } from "firebase/app"; import { getFunctions, httpsCallable } from "firebase/functions"; -const functions = getFunctions(getApp()); +const functions = getFunctions(app()); const addMessage = httpsCallable(functions, 'addMessage'); const result = await addMessage({ text: ''}); diff --git a/snippets/functions-next/emulator-suite/functions_emulator_connect.js b/snippets/functions-next/emulator-suite/functions_emulator_connect.js index 3ac3bfc8..effc3fbc 100644 --- a/snippets/functions-next/emulator-suite/functions_emulator_connect.js +++ b/snippets/functions-next/emulator-suite/functions_emulator_connect.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START modular_functions_emulator_connect] -import { getApp } from "firebase/app"; +import { app } from "firebase/app"; import { getFunctions, useFunctionsEmulator } from "firebase/functions"; -const functions = getFunctions(getApp()); +const functions = getFunctions(app()); useFunctionsEmulator(functions, "http://localhost:5001"); // [END modular_functions_emulator_connect] \ No newline at end of file From a1c3fdeca7a5b5bafb579c4c5c0c36324a926b78 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 28 Sep 2020 12:23:19 -0400 Subject: [PATCH 008/235] Not equal queries (#37) --- firestore-next/test.firestore.js | 12 ++++++++++++ firestore/test.firestore.js | 8 ++++++++ .../firestore-next/test-firestore/not_in_filter.js | 10 ++++++++++ .../test-firestore/simple_query_not_equal.js | 8 ++++++++ 4 files changed, 38 insertions(+) create mode 100644 snippets/firestore-next/test-firestore/not_in_filter.js create mode 100644 snippets/firestore-next/test-firestore/simple_query_not_equal.js diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index bcd5e7ef..09189eb2 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -853,6 +853,10 @@ describe("firestore", () => { const q2 = query(citiesRef, where("population", "<", 100000)); const q3 = query(citiesRef, where("name", ">=", "San Francisco")); // [END example_filters] + + // [START simple_query_not_equal] + const q4 = query(citiesRef, where("capital", "!=", false)); + // [END simple_query_not_equal] }); it("should handle array-contains where", () => { @@ -889,6 +893,14 @@ describe("firestore", () => { // [END in_filter] } + function notInFilter() { + // [START not_in_filter] + const { query, where } = require("firebase/firestore"); + + const q = query(citiesRef, where('country', 'not-in', ['USA', 'Japan'])); + // [END not_in_filter] + } + function inFilterWithArray() { // [START in_filter_with_array] const { query, where } = require("firebase/firestore"); diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index b0dedce8..1a0fbb7b 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -860,6 +860,10 @@ describe("firestore", () => { citiesRef.where("population", "<", 100000) citiesRef.where("name", ">=", "San Francisco") // [END example_filters] + + // [START simple_query_not_equal] + citiesRef.where("capital", "!=", false); + // [END simple_query_not_equal] }); it("should handle array-contains where", () => { @@ -883,6 +887,10 @@ describe("firestore", () => { citiesRef.where('country', 'in', ['USA', 'Japan']); // [END in_filter] + // [START not_in_filter] + citiesRef.where('country', 'not-in', ['USA', 'Japan']); + // [END not_in_filter] + // [START in_filter_with_array] citiesRef.where('regions', 'in', [['west_coast', 'east_coast']]); diff --git a/snippets/firestore-next/test-firestore/not_in_filter.js b/snippets/firestore-next/test-firestore/not_in_filter.js new file mode 100644 index 00000000..614ade15 --- /dev/null +++ b/snippets/firestore-next/test-firestore/not_in_filter.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_not_in_filter] +import { query, where } from "firebase/firestore"; + +const q = query(citiesRef, where('country', 'not-in', ['USA', 'Japan'])); +// [END modular_not_in_filter] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/simple_query_not_equal.js b/snippets/firestore-next/test-firestore/simple_query_not_equal.js new file mode 100644 index 00000000..12154706 --- /dev/null +++ b/snippets/firestore-next/test-firestore/simple_query_not_equal.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To make edits to the snippets in this file, please edit the source + +// [START modular_simple_query_not_equal] +const q4 = query(citiesRef, where("capital", "!=", false)); +// [END modular_simple_query_not_equal] \ No newline at end of file From d30dc92f4cf0e0a3439ce94f3518288dc3c53c3f Mon Sep 17 00:00:00 2001 From: DPEBot Date: Tue, 29 Sep 2020 06:11:23 -0700 Subject: [PATCH 009/235] Auto-update dependencies. (#39) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index adf572a4..01265e34 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From 1794d10fcc19ca6014c865794feff380730e9571 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 2 Oct 2020 04:42:05 -0700 Subject: [PATCH 010/235] Auto-update dependencies. (#40) --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore-next/package.json | 2 +- firestore/package.json | 2 +- functions-next/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/auth/package.json b/auth/package.json index 4f6dd1a1..db91743d 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.21.1" + "firebase": "^7.22.0" } } diff --git a/database/package.json b/database/package.json index e88e4724..47742271 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.21.1" + "firebase": "^7.22.0" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 3339c55e..652913bd 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.21.1" + "firebase": "^7.22.0" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 3f3c7e5e..9576ae58 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.21.1" + "firebase": "^7.22.0" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/firestore/package.json b/firestore/package.json index 605c66af..5b330b86 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.21.1" + "firebase": "^7.22.0" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/functions-next/package.json b/functions-next/package.json index dfab6e62..ee85cc01 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -7,6 +7,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.21.1" + "firebase": "^7.22.0" } } diff --git a/functions/package.json b/functions/package.json index 12c119ed..0cb2f52e 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.21.1" + "firebase": "^7.22.0" } } diff --git a/installations/package.json b/installations/package.json index 86d78339..61833f1f 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.21.1" + "firebase": "^7.22.0" } } From 9beef5613e72b8c32f365c1871f2ed350de152ce Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 2 Oct 2020 05:24:47 -0700 Subject: [PATCH 011/235] Auto-update dependencies. (#41) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 01265e34..7fe6d56e 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From e144d01df8f4fc65a7b873b84664590a295bc593 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Wed, 7 Oct 2020 02:38:58 -0700 Subject: [PATCH 012/235] Auto-update dependencies. (#42) --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore-next/package.json | 2 +- firestore/package.json | 2 +- functions-next/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/auth/package.json b/auth/package.json index db91743d..5cfd77b3 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.22.0" + "firebase": "^7.22.1" } } diff --git a/database/package.json b/database/package.json index 47742271..c92d8df6 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.22.0" + "firebase": "^7.22.1" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 652913bd..1898f6dc 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.22.0" + "firebase": "^7.22.1" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 9576ae58..8c8b4c63 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.22.0" + "firebase": "^7.22.1" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/firestore/package.json b/firestore/package.json index 5b330b86..c3dbffdb 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.22.0" + "firebase": "^7.22.1" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/functions-next/package.json b/functions-next/package.json index ee85cc01..211f25a9 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -7,6 +7,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.22.0" + "firebase": "^7.22.1" } } diff --git a/functions/package.json b/functions/package.json index 0cb2f52e..246c46c6 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.22.0" + "firebase": "^7.22.1" } } diff --git a/installations/package.json b/installations/package.json index 61833f1f..8c56c60d 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.22.0" + "firebase": "^7.22.1" } } From ef0c53a437c3101845f95c61e31bb98b61bd601c Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 8 Oct 2020 05:18:43 -0700 Subject: [PATCH 013/235] Auto-update dependencies. (#43) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 7fe6d56e..101f7b67 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From 770c6e89f233b1f68497e489df68f5b72f6d7e9c Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 9 Oct 2020 01:56:46 -0700 Subject: [PATCH 014/235] Auto-update dependencies. (#44) --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore-next/package.json | 2 +- firestore/package.json | 2 +- functions-next/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/auth/package.json b/auth/package.json index 5cfd77b3..4f134201 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.22.1" + "firebase": "^7.23.0" } } diff --git a/database/package.json b/database/package.json index c92d8df6..81ed71e9 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.22.1" + "firebase": "^7.23.0" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 1898f6dc..96948c8b 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.22.1" + "firebase": "^7.23.0" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 8c8b4c63..325295fa 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.22.1" + "firebase": "^7.23.0" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/firestore/package.json b/firestore/package.json index c3dbffdb..b3b667fc 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.22.1" + "firebase": "^7.23.0" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/functions-next/package.json b/functions-next/package.json index 211f25a9..1f89bb31 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -7,6 +7,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.22.1" + "firebase": "^7.23.0" } } diff --git a/functions/package.json b/functions/package.json index 246c46c6..f1a655c4 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.22.1" + "firebase": "^7.23.0" } } diff --git a/installations/package.json b/installations/package.json index 8c56c60d..7ca6c86e 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.22.1" + "firebase": "^7.23.0" } } From e3b7348041895546b2d0a5e09566f564b5271de9 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 9 Oct 2020 05:36:48 -0700 Subject: [PATCH 015/235] Auto-update dependencies. (#45) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 101f7b67..879b5513 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From cdda4983440e4eeedb365d2bd4140ad2a4375507 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 16 Oct 2020 03:32:10 -0700 Subject: [PATCH 016/235] Auto-update dependencies. (#46) --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore-next/package.json | 2 +- firestore/package.json | 2 +- functions-next/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/auth/package.json b/auth/package.json index 4f134201..4f3e6d4d 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.23.0" + "firebase": "^7.24.0" } } diff --git a/database/package.json b/database/package.json index 81ed71e9..de424fea 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.23.0" + "firebase": "^7.24.0" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 96948c8b..78dd34a0 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.23.0" + "firebase": "^7.24.0" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 325295fa..1f6f47f0 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.23.0" + "firebase": "^7.24.0" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/firestore/package.json b/firestore/package.json index b3b667fc..9d44eea1 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.23.0" + "firebase": "^7.24.0" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/functions-next/package.json b/functions-next/package.json index 1f89bb31..f13890ec 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -7,6 +7,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.23.0" + "firebase": "^7.24.0" } } diff --git a/functions/package.json b/functions/package.json index f1a655c4..6dc59261 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.23.0" + "firebase": "^7.24.0" } } diff --git a/installations/package.json b/installations/package.json index 7ca6c86e..f4d8059a 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.23.0" + "firebase": "^7.24.0" } } From bd8330577c2ad7272163b8d74c20770e8179e267 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 16 Oct 2020 05:25:24 -0700 Subject: [PATCH 017/235] Auto-update dependencies. (#47) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 879b5513..0c49200c 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From 9be72129777a0b270bb5f4611dbda068c2732605 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Tue, 27 Oct 2020 09:38:58 -0700 Subject: [PATCH 018/235] Auto-update dependencies. (#48) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 0c49200c..0e44455f 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From 043cc5ac8786854e3db878b514bc45f02a49ff5b Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 27 Oct 2020 16:53:45 -0400 Subject: [PATCH 019/235] Update dependencies (#49) Co-authored-by: DPE bot --- auth/link-multiple-accounts.js | 4 +++- auth/package.json | 2 +- database/emulator-suite.js | 21 +++++++------------ database/package.json | 2 +- database/read-and-write.js | 4 ++-- firebaseapp/firebaseapp.js | 2 +- firebaseapp/package.json | 2 +- firestore-next/package.json | 2 +- firestore/emulator-suite.js | 11 ++++------ firestore/package.json | 2 +- firestore/test.firestore.js | 4 ++-- firestore/test.solution-aggregation.js | 4 ++-- firestore/test.solution-arrays.js | 4 ++-- firestore/test.solution-counters.js | 4 ++-- functions-next/emulator-suite.js | 12 +++++------ functions-next/package.json | 2 +- functions/emulator-suite.js | 6 +++--- functions/package.json | 2 +- installations/index.js | 4 ++-- installations/package.json | 2 +- .../emulator-suite/functions_callable_call.js | 6 +++--- .../functions_emulator_connect.js | 6 +++--- 22 files changed, 50 insertions(+), 58 deletions(-) diff --git a/auth/link-multiple-accounts.js b/auth/link-multiple-accounts.js index e4888cab..a0a53f70 100644 --- a/auth/link-multiple-accounts.js +++ b/auth/link-multiple-accounts.js @@ -1,7 +1,9 @@ // These samples are intended for Web so this import would normally be // done in HTML however using modules here is more convenient for // ensuring sample correctness offline. -const firebase = require('firebase'); +import firebase from "firebase/app"; +import "firebase/auth"; + const auth = firebase.auth(); const MyUserDataRepo = function() {}; diff --git a/auth/package.json b/auth/package.json index 4f3e6d4d..f4589364 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.24.0" + "firebase": "^8.0.0" } } diff --git a/database/emulator-suite.js b/database/emulator-suite.js index 1987822d..a900cb6e 100644 --- a/database/emulator-suite.js +++ b/database/emulator-suite.js @@ -2,27 +2,20 @@ // These samples are intended for Web so this import would normally be // done in HTML however using modules here is more convenient for // ensuring sample correctness offline. -var firebase = require("firebase/app"); -require("firebase/database"); +import firebase from "firebase/app"; +import "firebase/database"; -function onDocumentReady(firebase) { +function onDocumentReady() { //[START rtdb_emulator_connect] + var db = firebase.database(); if (location.hostname === "localhost") { - - var firebaseConfig = { - // Point to the RTDB emulator running on localhost. - // In almost all cases the ns (namespace) is your project ID. - databaseURL: "http://localhost:9000?ns=YOUR_DATABASE_NAMESPACE" - } - - var myApp = firebase.initializeApp(firebaseConfig); - var db = myApp.database(); + // Point to the RTDB emulator running on localhost. + db.useEmulator("localhost", 9000); } // [END rtdb_emulator_connect] } -function flushRealtimeDatabase(firebase) { - +function flushRealtimeDatabase() { //[START rtdb_emulator_flush] // With a database Reference, write null to clear the database. firebase.database().ref().set(null); diff --git a/database/package.json b/database/package.json index de424fea..691cd82d 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.24.0" + "firebase": "^8.0.0" } } diff --git a/database/read-and-write.js b/database/read-and-write.js index 9f410f37..e18ae42a 100644 --- a/database/read-and-write.js +++ b/database/read-and-write.js @@ -1,8 +1,8 @@ // These samples are intended for Web so this import would normally be // done in HTML however using modules here is more convenient for // ensuring sample correctness offline. -var firebase = require("firebase/app"); -require("firebase/database"); +import firebase from "firebase/app"; +import "firebase/database"; // [START rtdb_write_new_user] function writeUserData(userId, name, email, imageUrl) { diff --git a/firebaseapp/firebaseapp.js b/firebaseapp/firebaseapp.js index 24b68294..88eedd46 100644 --- a/firebaseapp/firebaseapp.js +++ b/firebaseapp/firebaseapp.js @@ -1,4 +1,4 @@ -var firebase = require('firebase/app'); +import firebase from 'firebase/app'; function multpleFirebaseApps() { // [START firebase_options] diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 78dd34a0..e9d70521 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.24.0" + "firebase": "^8.0.0" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 1f6f47f0..9537996c 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.24.0" + "firebase": "exp" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/firestore/emulator-suite.js b/firestore/emulator-suite.js index 87b8f50d..49d0ae5c 100644 --- a/firestore/emulator-suite.js +++ b/firestore/emulator-suite.js @@ -1,15 +1,12 @@ -const firebase = require('firebase'); -require('firebase/firestore'); +import firebase from "firebase/app"; +import 'firebase/firestore'; -function onDocumentReady(firebaseApp) { +function onDocumentReady() { //[START fs_emulator_connect] // Firebase previously initialized using firebase.initializeApp(). var db = firebase.firestore(); if (location.hostname === "localhost") { - db.settings({ - host: "localhost:8080", - ssl: false - }); + db.useEmulator("localhost", 8080); } // [END fs_emulator_connect] } diff --git a/firestore/package.json b/firestore/package.json index 9d44eea1..39515e79 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.24.0" + "firebase": "^8.0.0" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index 1a0fbb7b..66ade99b 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -1,5 +1,5 @@ -const firebase = require('firebase/app'); -require('firebase/firestore'); +import firebase from 'firebase/app'; +import 'firebase/firestore'; const { expect } = require('chai'); diff --git a/firestore/test.solution-aggregation.js b/firestore/test.solution-aggregation.js index 6075561d..4895e8ff 100644 --- a/firestore/test.solution-aggregation.js +++ b/firestore/test.solution-aggregation.js @@ -1,5 +1,5 @@ -var firebase = require('firebase/app'); -require('firebase/firestore'); +import firebase from 'firebase/app'; +import 'firebase/firestore'; // [START sample_doc] var arinellDoc = { diff --git a/firestore/test.solution-arrays.js b/firestore/test.solution-arrays.js index 4e1215ae..74bf17c7 100644 --- a/firestore/test.solution-arrays.js +++ b/firestore/test.solution-arrays.js @@ -1,5 +1,5 @@ -var firebase = require('firebase/app'); -require('firebase/firestore'); +import firebase from 'firebase/app'; +import 'firebase/firestore'; let postsWithArray = [ // [START post_with_array] diff --git a/firestore/test.solution-counters.js b/firestore/test.solution-counters.js index ef0fd3bc..c9eed2c4 100644 --- a/firestore/test.solution-counters.js +++ b/firestore/test.solution-counters.js @@ -1,5 +1,5 @@ -var firebase = require('firebase/app'); -require('firebase/firestore'); +import firebase from 'firebase/app'; +import 'firebase/firestore'; var db; diff --git a/functions-next/emulator-suite.js b/functions-next/emulator-suite.js index 1a210072..ec7eddb8 100644 --- a/functions-next/emulator-suite.js +++ b/functions-next/emulator-suite.js @@ -9,20 +9,20 @@ initializeApp({ export function emulatorSettings() { // [START functions_emulator_connect] - const { app } = require("firebase/app"); - const { getFunctions, useFunctionsEmulator } = require( "firebase/functions"); + const { getApp } = require("firebase/app"); + const { getFunctions, useFunctionsEmulator } = require("firebase/functions"); - const functions = getFunctions(app()); + const functions = getFunctions(getApp()); useFunctionsEmulator(functions, "http://localhost:5001"); // [END functions_emulator_connect] } export async function callFunction() { // [START functions_callable_call] - const { app } = require("firebase/app"); - const { getFunctions, httpsCallable } = require( "firebase/functions"); + const { getApp } = require("firebase/app"); + const { getFunctions, httpsCallable } = require("firebase/functions"); - const functions = getFunctions(app()); + const functions = getFunctions(getApp()); const addMessage = httpsCallable(functions, 'addMessage'); const result = await addMessage({ text: ''}); diff --git a/functions-next/package.json b/functions-next/package.json index f13890ec..b5c9c6df 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -7,6 +7,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.24.0" + "firebase": "exp" } } diff --git a/functions/emulator-suite.js b/functions/emulator-suite.js index 87c22b73..e2c244ca 100644 --- a/functions/emulator-suite.js +++ b/functions/emulator-suite.js @@ -1,8 +1,8 @@ -var firebase = require('firebase/app'); -require('firebase/functions'); +import firebase from "firebase/app"; +import "firebase/functions"; function emulatorSettings() { // [START functions_emulator_connect] - firebase.functions().useFunctionsEmulator("http://localhost:5001") + firebase.functions().useEmulator("localhost", 5001); // [END functions_emulator_connect] } diff --git a/functions/package.json b/functions/package.json index 6dc59261..87065032 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^7.24.0" + "firebase": "^8.0.0" } } diff --git a/installations/index.js b/installations/index.js index 7f021e3f..35daae92 100644 --- a/installations/index.js +++ b/installations/index.js @@ -1,5 +1,5 @@ -const firebase = require("firebase/app"); -require("firebase/installations"); +import firebase from "firebase/app"; +import "firebase/installations"; async function deleteInstallation() { try { diff --git a/installations/package.json b/installations/package.json index f4d8059a..cddcb587 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^7.24.0" + "firebase": "^8.0.0" } } diff --git a/snippets/functions-next/emulator-suite/functions_callable_call.js b/snippets/functions-next/emulator-suite/functions_callable_call.js index f18d3056..31a244c7 100644 --- a/snippets/functions-next/emulator-suite/functions_callable_call.js +++ b/snippets/functions-next/emulator-suite/functions_callable_call.js @@ -4,10 +4,10 @@ // To make edits to the snippets in this file, please edit the source // [START modular_functions_callable_call] -import { app } from "firebase/app"; -import { getFunctions, httpsCallable } from "firebase/functions"; +import { getApp } from "firebase/app"; +import { getFunctions, httpsCallable } from "firebase/functions"; -const functions = getFunctions(app()); +const functions = getFunctions(getApp()); const addMessage = httpsCallable(functions, 'addMessage'); const result = await addMessage({ text: ''}); diff --git a/snippets/functions-next/emulator-suite/functions_emulator_connect.js b/snippets/functions-next/emulator-suite/functions_emulator_connect.js index effc3fbc..04957e67 100644 --- a/snippets/functions-next/emulator-suite/functions_emulator_connect.js +++ b/snippets/functions-next/emulator-suite/functions_emulator_connect.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START modular_functions_emulator_connect] -import { app } from "firebase/app"; -import { getFunctions, useFunctionsEmulator } from "firebase/functions"; +import { getApp } from "firebase/app"; +import { getFunctions, useFunctionsEmulator } from "firebase/functions"; -const functions = getFunctions(app()); +const functions = getFunctions(getApp()); useFunctionsEmulator(functions, "http://localhost:5001"); // [END modular_functions_emulator_connect] \ No newline at end of file From 1d60ce0eb0411783917420cc5314584094f2bf5f Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 2 Nov 2020 12:46:19 -0500 Subject: [PATCH 020/235] Move to a snippets suffix instead of a prefix (#36) Co-authored-by: egilmorez --- scripts/separate-snippets.ts | 32 +++++++++---------- snippets/README.md | 4 +-- .../emulator-suite/fs_emulator_connect.js | 4 +-- .../test-firestore/add_ada_lovelace.js | 4 +-- .../test-firestore/add_alan_turing.js | 4 +-- .../test-firestore/add_document.js | 4 +-- .../test-firestore/add_rating_transaction.js | 4 +-- .../array_contains_any_filter.js | 4 +-- .../test-firestore/array_contains_filter.js | 4 +-- .../test-firestore/chain_filters.js | 4 +-- .../test-firestore/cities_document_set.js | 4 +-- .../test-firestore/city_custom_object.js | 4 +-- .../test-firestore/collection_reference.js | 4 +-- .../test-firestore/data_types.js | 4 +-- .../test-firestore/delete_collection.js | 4 +-- .../test-firestore/delete_document.js | 4 +-- .../test-firestore/detach_listener.js | 4 +-- .../test-firestore/disable_network.js | 4 +-- .../test-firestore/doc_reference.js | 4 +-- .../doc_reference_alternative.js | 4 +-- .../test-firestore/enable_network.js | 4 +-- .../test-firestore/example_data.js | 4 +-- .../test-firestore/example_filters.js | 4 +-- .../test-firestore/filter_and_order.js | 4 +-- .../fs_collection_group_query.js | 4 +-- .../fs_collection_group_query_data_setup.js | 4 +-- .../test-firestore/fs_setup_cache.js | 4 +-- .../test-firestore/get_all_users.js | 4 +-- .../test-firestore/get_custom_object.js | 4 +-- .../test-firestore/get_document.js | 4 +-- .../test-firestore/get_document_options.js | 4 +-- .../test-firestore/get_multiple.js | 4 +-- .../test-firestore/get_multiple_all.js | 4 +-- .../test-firestore/handle_listen_errors.js | 4 +-- .../test-firestore/in_filter.js | 4 +-- .../test-firestore/in_filter_with_array.js | 4 +-- .../test-firestore/initialize_persistence.js | 4 +-- .../invalid_filter_and_order.js | 4 +-- .../test-firestore/invalid_range_filters.js | 4 +-- .../test-firestore/listen_diffs.js | 4 +-- .../test-firestore/listen_document.js | 4 +-- .../test-firestore/listen_document_local.js | 4 +-- .../test-firestore/listen_for_users.js | 4 +-- .../test-firestore/listen_multiple.js | 4 +-- .../test-firestore/listen_with_metadata.js | 4 +-- .../test-firestore/new_document.js | 4 +-- .../test-firestore/not_in_filter.js | 4 +-- .../test-firestore/order_and_end.js | 4 +-- .../test-firestore/order_and_limit.js | 4 +-- .../test-firestore/order_and_limit_desc.js | 4 +-- .../test-firestore/order_and_start.js | 4 +-- .../test-firestore/order_multiple.js | 4 +-- .../firestore-next/test-firestore/paginate.js | 4 +-- .../server_timestamp_resolution_options.js | 4 +-- .../test-firestore/set_custom_object.js | 4 +-- .../test-firestore/set_document.js | 4 +-- .../test-firestore/set_with_merge.js | 4 +-- .../test-firestore/simple_queries.js | 4 +-- .../test-firestore/simple_queries_again.js | 4 +-- .../test-firestore/simple_query_not_equal.js | 4 +-- .../test-firestore/start_doc.js | 4 +-- .../test-firestore/start_multiple_orderby.js | 4 +-- .../test-firestore/subcollection_reference.js | 4 +-- .../test-firestore/transaction.js | 4 +-- .../test-firestore/transaction_promise.js | 4 +-- .../test-firestore/update_delete_field.js | 4 +-- .../test-firestore/update_document.js | 4 +-- .../test-firestore/update_document_array.js | 4 +-- .../update_document_increment.js | 4 +-- .../test-firestore/update_document_nested.js | 4 +-- .../update_with_server_timestamp.js | 4 +-- .../test-firestore/use_from_cache.js | 4 +-- .../test-firestore/valid_filter_and_order.js | 4 +-- .../test-firestore/valid_range_filters.js | 4 +-- .../test-firestore/write_batch.js | 4 +-- .../get_collection_ratings.js | 4 +-- .../test-solution-aggregation/sample_doc.js | 4 +-- .../test-solution-arrays/post_with_array.js | 4 +-- .../test-solution-arrays/post_with_map.js | 4 +-- .../post_with_map_advanced.js | 4 +-- .../test-solution-arrays/query_in_category.js | 4 +-- .../query_in_category_timestamp.js | 4 +-- .../query_in_category_timestamp_invalid.js | 4 +-- .../test-solution-counters/create_counter.js | 4 +-- .../test-solution-counters/get_count.js | 4 +-- .../increment_counter.js | 4 +-- .../emulator-suite/functions_callable_call.js | 4 +-- .../functions_emulator_connect.js | 4 +-- 88 files changed, 190 insertions(+), 190 deletions(-) diff --git a/scripts/separate-snippets.ts b/scripts/separate-snippets.ts index b5d5d9d1..e449ad8b 100644 --- a/scripts/separate-snippets.ts +++ b/scripts/separate-snippets.ts @@ -5,8 +5,8 @@ import * as path from "path"; // Regex for comment which must be included in a file for it to be separated const RE_SNIPPETS_SEPARATION = /\[SNIPPETS_SEPARATION\s+enabled\]/; -// Regex for comment to control the separator prefix -const RE_SNIPPETS_PREFIX = /\[SNIPPETS_PREFIX\s+([A-Za-z0-9_]+)\]/; +// Regex for comment to control the separator suffix +const RE_SNIPPETS_SUFFIX = /\[SNIPPETS_SUFFIX\s+([A-Za-z0-9_]+)\]/; // Regex for [START] and [END] snippet tags. const RE_START_SNIPPET = /\[START\s+([A-Za-z_]+)\s*\]/; @@ -18,11 +18,11 @@ const RE_REQUIRE = /const {(.+?)} = require\((.+?)\)/; type SnippetsConfig = { enabled: boolean; - prefix: string; + suffix: string; map: Record; }; -const DEFAULT_PREFIX = "modular_"; +const DEFAULT_SUFFIX = "_modular"; function isBlank(line: string) { return line.trim().length === 0; @@ -33,16 +33,16 @@ function isBlank(line: string) { * - Converting require statements into top-level imports. * - Adjusting indentation to left-align all content * - Removing any blank lines at the starts - * - Adding a prefix to snippet names + * - Adding a suffix to snippet names * * @param lines the lines containing the snippet (including START/END comments) * @param sourceFile the source file where the original snippet lives - * @param snippetPrefix the prefix (such as modular_) + * @param snippetSuffix the suffix (such as _modular) */ function processSnippet( lines: string[], sourceFile: string, - snippetPrefix: string + snippetSuffix: string ): string { const outputLines: string[] = []; @@ -50,10 +50,10 @@ function processSnippet( if (line.match(RE_REQUIRE)) { outputLines.push(line.replace(RE_REQUIRE, `import {$1} from $2`)); } else if (line.match(RE_START_SNIPPET)) { - outputLines.push(line.replace(RE_START_SNIPPET, `[START ${snippetPrefix}$1]`)); + outputLines.push(line.replace(RE_START_SNIPPET, `[START $1${snippetSuffix}]`)); } else if (line.match(RE_END_SNIPPET)) { outputLines.push( - line.replace(RE_END_SNIPPET, `[END ${snippetPrefix}$1]`) + line.replace(RE_END_SNIPPET, `[END $1${snippetSuffix}]`) ); } else { outputLines.push(line); @@ -115,7 +115,7 @@ function collectSnippets(filePath: string): SnippetsConfig { const config: SnippetsConfig = { enabled: false, - prefix: DEFAULT_PREFIX, + suffix: DEFAULT_SUFFIX, map: {}, }; @@ -124,10 +124,10 @@ function collectSnippets(filePath: string): SnippetsConfig { return config; } - const prefixLine = lines.find((l) => !!l.match(RE_SNIPPETS_PREFIX)); - if (prefixLine) { - const m = prefixLine.match(RE_SNIPPETS_PREFIX); - config.prefix = m[1]; + const suffixLine = lines.find((l) => !!l.match(RE_SNIPPETS_SUFFIX)); + if (suffixLine) { + const m = suffixLine.match(RE_SNIPPETS_SUFFIX); + config.suffix = m[1]; } let currSnippetName = ""; @@ -175,7 +175,7 @@ async function main() { const snippetDir = path.join("./snippets", fileSlug); console.log( - `Processing: ${filePath} --> ${snippetDir} (prefix=${config.prefix})` + `Processing: ${filePath} --> ${snippetDir} (suffix=${config.suffix})` ); if (!fs.existsSync(snippetDir)) { @@ -187,7 +187,7 @@ async function main() { const content = processSnippet( config.map[snippetName], filePath, - config.prefix + config.suffix ); fs.writeFileSync(newFilePath, content); } diff --git a/snippets/README.md b/snippets/README.md index 3819e7cf..8c1d1139 100644 --- a/snippets/README.md +++ b/snippets/README.md @@ -18,9 +18,9 @@ For a file to be included in the separator script it must contain a comment like // [SNIPPETS_SEPARATION enabled] ``` -By default separated snippets will have their name prefixed with `modular_` +By default separated snippets will have their name suffixed with `_modular` but you can override this with a commment: ```js -// [SNIPPETS_PREFIX banana] +// [SNIPPETS_SUFFIX _banana] ``` diff --git a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js index 6b587d39..9824a297 100644 --- a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js +++ b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_fs_emulator_connect] +// [START fs_emulator_connect_modular] import { initializeFirestore } from "firebase/firestore"; let settings = {}; @@ -16,4 +16,4 @@ if (location.hostname === "localhost") { // firebaseApps previously initialized using initializeApp() const db = initializeFirestore(firebaseApp, settings); -// [END modular_fs_emulator_connect] \ No newline at end of file +// [END fs_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/add_ada_lovelace.js b/snippets/firestore-next/test-firestore/add_ada_lovelace.js index 5fa87298..7e9a0516 100644 --- a/snippets/firestore-next/test-firestore/add_ada_lovelace.js +++ b/snippets/firestore-next/test-firestore/add_ada_lovelace.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_add_ada_lovelace] +// [START add_ada_lovelace_modular] import { collection, addDoc } from "firebase/firestore"; try { @@ -16,4 +16,4 @@ try { } catch (e) { console.error("Error adding document: ", e); } -// [END modular_add_ada_lovelace] \ No newline at end of file +// [END add_ada_lovelace_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/add_alan_turing.js b/snippets/firestore-next/test-firestore/add_alan_turing.js index 300eaa00..6ea96265 100644 --- a/snippets/firestore-next/test-firestore/add_alan_turing.js +++ b/snippets/firestore-next/test-firestore/add_alan_turing.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_add_alan_turing] +// [START add_alan_turing_modular] // Add a second document with a generated ID. import { addDoc, collection } from "firebase/firestore"; @@ -19,4 +19,4 @@ try { } catch (e) { console.error("Error adding document: ", e); } -// [END modular_add_alan_turing] \ No newline at end of file +// [END add_alan_turing_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/add_document.js b/snippets/firestore-next/test-firestore/add_document.js index 4f01313c..2ecb5c36 100644 --- a/snippets/firestore-next/test-firestore/add_document.js +++ b/snippets/firestore-next/test-firestore/add_document.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_add_document] +// [START add_document_modular] import { collection, addDoc } from "firebase/firestore"; // Add a new document with a generated id. @@ -12,4 +12,4 @@ const docRef = await addDoc(collection(db, "cities"), { country: "Japan" }); console.log("Document written with ID: ", docRef.id); -// [END modular_add_document] \ No newline at end of file +// [END add_document_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/add_rating_transaction.js b/snippets/firestore-next/test-firestore/add_rating_transaction.js index 0c3a4281..248f5e54 100644 --- a/snippets/firestore-next/test-firestore/add_rating_transaction.js +++ b/snippets/firestore-next/test-firestore/add_rating_transaction.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_add_rating_transaction] +// [START add_rating_transaction_modular] import { collection, doc, runTransaction} from "firebase/firestore"; async function addRating(restaurantRef, rating) { @@ -32,4 +32,4 @@ async function addRating(restaurantRef, rating) { transaction.set(ratingRef, { rating: rating }); }); } -// [END modular_add_rating_transaction] \ No newline at end of file +// [END add_rating_transaction_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/array_contains_any_filter.js b/snippets/firestore-next/test-firestore/array_contains_any_filter.js index 79046a5a..72c550f8 100644 --- a/snippets/firestore-next/test-firestore/array_contains_any_filter.js +++ b/snippets/firestore-next/test-firestore/array_contains_any_filter.js @@ -3,9 +3,9 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_array_contains_any_filter] +// [START array_contains_any_filter_modular] import { query, where } from "firebase/firestore"; const q = query(citiesRef, where('regions', 'array-contains-any', ['west_coast', 'east_coast'])); -// [END modular_array_contains_any_filter] \ No newline at end of file +// [END array_contains_any_filter_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/array_contains_filter.js b/snippets/firestore-next/test-firestore/array_contains_filter.js index 0771fc7a..9a9fcdb3 100644 --- a/snippets/firestore-next/test-firestore/array_contains_filter.js +++ b/snippets/firestore-next/test-firestore/array_contains_filter.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_array_contains_filter] +// [START array_contains_filter_modular] import { query, where } from "firebase/firestore"; const q = query(citiesRef, where("regions", "array-contains", "west_coast")); -// [END modular_array_contains_filter] \ No newline at end of file +// [END array_contains_filter_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/chain_filters.js b/snippets/firestore-next/test-firestore/chain_filters.js index 993d7229..b13640b4 100644 --- a/snippets/firestore-next/test-firestore/chain_filters.js +++ b/snippets/firestore-next/test-firestore/chain_filters.js @@ -3,9 +3,9 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_chain_filters] +// [START chain_filters_modular] import { query, where } from "firebase/firestore"; const q1 = query(citiesRef, where("state", "==", "CO"), where("name", "==", "Denver")); const q2 = query(citiesRef, where("state", "==", "CA"), where("population", "<", 1000000)); -// [END modular_chain_filters] \ No newline at end of file +// [END chain_filters_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/cities_document_set.js b/snippets/firestore-next/test-firestore/cities_document_set.js index 0950a138..edebdc0c 100644 --- a/snippets/firestore-next/test-firestore/cities_document_set.js +++ b/snippets/firestore-next/test-firestore/cities_document_set.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_cities_document_set] +// [START cities_document_set_modular] import { collection, doc, setDoc } from "firebase/firestore"; await setDoc(doc(collection(db, "cities"), "new-city-id"), data); -// [END modular_cities_document_set] \ No newline at end of file +// [END cities_document_set_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/city_custom_object.js b/snippets/firestore-next/test-firestore/city_custom_object.js index c12b5c64..72e0ac32 100644 --- a/snippets/firestore-next/test-firestore/city_custom_object.js +++ b/snippets/firestore-next/test-firestore/city_custom_object.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_city_custom_object] +// [START city_custom_object_modular] class City { constructor (name, state, country ) { this.name = name; @@ -29,4 +29,4 @@ var cityConverter = { return new City(data.name, data.state, data.country) } } -// [END modular_city_custom_object] \ No newline at end of file +// [END city_custom_object_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/collection_reference.js b/snippets/firestore-next/test-firestore/collection_reference.js index fb848405..2b43362d 100644 --- a/snippets/firestore-next/test-firestore/collection_reference.js +++ b/snippets/firestore-next/test-firestore/collection_reference.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_collection_reference] +// [START collection_reference_modular] import { collection } from "firebase/firestore"; const usersCollectionRef = collection(db, 'users'); -// [END modular_collection_reference] \ No newline at end of file +// [END collection_reference_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/data_types.js b/snippets/firestore-next/test-firestore/data_types.js index e783c429..faace529 100644 --- a/snippets/firestore-next/test-firestore/data_types.js +++ b/snippets/firestore-next/test-firestore/data_types.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_data_types] +// [START data_types_modular] import { doc, collection, setDoc, Timestamp } from "firebase/firestore"; const docData = { @@ -21,4 +21,4 @@ const docData = { } }; await setDoc(doc(collection(db, "data"), "one"), docData); -// [END modular_data_types] \ No newline at end of file +// [END data_types_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/delete_collection.js b/snippets/firestore-next/test-firestore/delete_collection.js index 78c73bbb..44768293 100644 --- a/snippets/firestore-next/test-firestore/delete_collection.js +++ b/snippets/firestore-next/test-firestore/delete_collection.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_delete_collection] +// [START delete_collection_modular] /** * Delete a collection, in batches of batchSize. Note that this does * not recursively delete subcollections of documents in the collection @@ -45,4 +45,4 @@ async function deleteQueryBatch(db, query, batchSize, resolve) { deleteQueryBatch(db, query, batchSize, resolve); }, 0); } -// [END modular_delete_collection] \ No newline at end of file +// [END delete_collection_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/delete_document.js b/snippets/firestore-next/test-firestore/delete_document.js index aaa79012..27c0bec9 100644 --- a/snippets/firestore-next/test-firestore/delete_document.js +++ b/snippets/firestore-next/test-firestore/delete_document.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_delete_document] +// [START delete_document_modular] import { collection, doc, deleteDoc } from "firebase/firestore"; await deleteDoc(doc(collection(db, "cities"), "DC")); -// [END modular_delete_document] \ No newline at end of file +// [END delete_document_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/detach_listener.js b/snippets/firestore-next/test-firestore/detach_listener.js index c22470cd..24848db2 100644 --- a/snippets/firestore-next/test-firestore/detach_listener.js +++ b/snippets/firestore-next/test-firestore/detach_listener.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_detach_listener] +// [START detach_listener_modular] import { collection, onSnapshot } from "firebase/firestore"; const unsubscribe = onSnapshot(collection(db, "cities"), () => { @@ -15,4 +15,4 @@ const unsubscribe = onSnapshot(collection(db, "cities"), () => { // Stop listening to changes unsubscribe(); -// [END modular_detach_listener] \ No newline at end of file +// [END detach_listener_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/disable_network.js b/snippets/firestore-next/test-firestore/disable_network.js index ad9a62fb..095e6090 100644 --- a/snippets/firestore-next/test-firestore/disable_network.js +++ b/snippets/firestore-next/test-firestore/disable_network.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_disable_network] +// [START disable_network_modular] import { disableNetwork } from "firebase/firestore"; await disableNetwork(db); @@ -12,4 +12,4 @@ console.log("Network disabled!"); // [START_EXCLUDE] console.log("Network disabled!"); // [END_EXCLUDE] -// [END modular_disable_network] \ No newline at end of file +// [END disable_network_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/doc_reference.js b/snippets/firestore-next/test-firestore/doc_reference.js index ce16a0cb..4f3fc134 100644 --- a/snippets/firestore-next/test-firestore/doc_reference.js +++ b/snippets/firestore-next/test-firestore/doc_reference.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_doc_reference] +// [START doc_reference_modular] import { collection, doc } from "firebase/firestore"; const alovelaceDocumentRef = doc(collection(db, 'users'), 'alovelace'); -// [END modular_doc_reference] \ No newline at end of file +// [END doc_reference_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/doc_reference_alternative.js b/snippets/firestore-next/test-firestore/doc_reference_alternative.js index fcef2915..8b60f4de 100644 --- a/snippets/firestore-next/test-firestore/doc_reference_alternative.js +++ b/snippets/firestore-next/test-firestore/doc_reference_alternative.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_doc_reference_alternative] +// [START doc_reference_alternative_modular] import { doc } from "firebase/firestore"; const alovelaceDocumentRef = doc(db, 'users/alovelace'); -// [END modular_doc_reference_alternative] \ No newline at end of file +// [END doc_reference_alternative_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/enable_network.js b/snippets/firestore-next/test-firestore/enable_network.js index 031f90ab..7530c318 100644 --- a/snippets/firestore-next/test-firestore/enable_network.js +++ b/snippets/firestore-next/test-firestore/enable_network.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_enable_network] +// [START enable_network_modular] import { enableNetwork } from "firebase/firestore"; await enableNetwork(db) @@ -11,4 +11,4 @@ await enableNetwork(db) // [START_EXCLUDE] console.log("Network enabled!"); // [END_EXCLUDE] -// [END modular_enable_network] \ No newline at end of file +// [END enable_network_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/example_data.js b/snippets/firestore-next/test-firestore/example_data.js index 1b1512c7..52204078 100644 --- a/snippets/firestore-next/test-firestore/example_data.js +++ b/snippets/firestore-next/test-firestore/example_data.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_example_data] +// [START example_data_modular] import { collection, doc, setDoc } from "firebase/firestore"; const citiesRef = collection(db, "cities"); @@ -28,4 +28,4 @@ await setDoc(doc(citiesRef, "BJ"), { name: "Beijing", state: null, country: "China", capital: true, population: 21500000, regions: ["jingjinji", "hebei"] }); -// [END modular_example_data] \ No newline at end of file +// [END example_data_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/example_filters.js b/snippets/firestore-next/test-firestore/example_filters.js index c0a5eb05..ccadb811 100644 --- a/snippets/firestore-next/test-firestore/example_filters.js +++ b/snippets/firestore-next/test-firestore/example_filters.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_example_filters] +// [START example_filters_modular] const q1 = query(citiesRef, where("state", "==", "CA")); const q2 = query(citiesRef, where("population", "<", 100000)); const q3 = query(citiesRef, where("name", ">=", "San Francisco")); -// [END modular_example_filters] \ No newline at end of file +// [END example_filters_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/filter_and_order.js b/snippets/firestore-next/test-firestore/filter_and_order.js index 2b4c7751..13e31c0a 100644 --- a/snippets/firestore-next/test-firestore/filter_and_order.js +++ b/snippets/firestore-next/test-firestore/filter_and_order.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_filter_and_order] +// [START filter_and_order_modular] import { query, where, orderBy, limit } from "firebase/firestore"; const q = query(citiesRef, where("population", ">", 100000), orderBy("population"), limit(2)); -// [END modular_filter_and_order] \ No newline at end of file +// [END filter_and_order_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/fs_collection_group_query.js b/snippets/firestore-next/test-firestore/fs_collection_group_query.js index 0fcf2d4e..96a2d735 100644 --- a/snippets/firestore-next/test-firestore/fs_collection_group_query.js +++ b/snippets/firestore-next/test-firestore/fs_collection_group_query.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_fs_collection_group_query] +// [START fs_collection_group_query_modular] import { collectionGroup, query, where, getDocs } from "firebase/firestore"; const museums = query(collectionGroup(db, 'landmarks'), where('type', '==', 'museum')); @@ -11,4 +11,4 @@ const querySnapshot = await getDocs(museums); querySnapshot.forEach((doc) => { console.log(doc.id, ' => ', doc.data()); }); -// [END modular_fs_collection_group_query] \ No newline at end of file +// [END fs_collection_group_query_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js b/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js index 47fd6a4b..ab8964f1 100644 --- a/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js +++ b/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_fs_collection_group_query_data_setup] +// [START fs_collection_group_query_data_setup_modular] import { collection, doc, setDoc } from "firebase/firestore"; const citiesRef = collection(db, 'cities'); @@ -50,4 +50,4 @@ await Promise.all([ type: 'museum' }) ]); -// [END modular_fs_collection_group_query_data_setup] \ No newline at end of file +// [END fs_collection_group_query_data_setup_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/fs_setup_cache.js b/snippets/firestore-next/test-firestore/fs_setup_cache.js index 4960b369..3085eb65 100644 --- a/snippets/firestore-next/test-firestore/fs_setup_cache.js +++ b/snippets/firestore-next/test-firestore/fs_setup_cache.js @@ -3,10 +3,10 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_fs_setup_cache] +// [START fs_setup_cache_modular] import { initializeFirestore, CACHE_SIZE_UNLIMITED } from "firebase/firestore"; const firestoreDb = initializeFirestore(app, { cacheSizeBytes: CACHE_SIZE_UNLIMITED }); -// [END modular_fs_setup_cache] \ No newline at end of file +// [END fs_setup_cache_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_all_users.js b/snippets/firestore-next/test-firestore/get_all_users.js index 57585bda..c8c86b5d 100644 --- a/snippets/firestore-next/test-firestore/get_all_users.js +++ b/snippets/firestore-next/test-firestore/get_all_users.js @@ -3,11 +3,11 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_get_all_users] +// [START get_all_users_modular] import { collection, getDocs } from "firebase/firestore"; const querySnapshot = await getDocs(collection(db, "users")); querySnapshot.forEach((doc) => { console.log(`${doc.id} => ${doc.data()}`); }); -// [END modular_get_all_users] \ No newline at end of file +// [END get_all_users_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_custom_object.js b/snippets/firestore-next/test-firestore/get_custom_object.js index abbf98eb..3ec28381 100644 --- a/snippets/firestore-next/test-firestore/get_custom_object.js +++ b/snippets/firestore-next/test-firestore/get_custom_object.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_get_custom_object] +// [START get_custom_object_modular] import { doc, collection, getDoc} from "firebase/firestore"; const ref = doc(collection(db, "cities"), "LA").withConverter(cityConverter); @@ -16,4 +16,4 @@ if (docSnap.exists()) { } else { console.log("No such document!") } -// [END modular_get_custom_object] \ No newline at end of file +// [END get_custom_object_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_document.js b/snippets/firestore-next/test-firestore/get_document.js index 9ff21ba6..79886025 100644 --- a/snippets/firestore-next/test-firestore/get_document.js +++ b/snippets/firestore-next/test-firestore/get_document.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_get_document] +// [START get_document_modular] import { collection, doc, getDoc } from "firebase/firestore"; const docRef = doc(collection(db, "cities"), "SF"); @@ -15,4 +15,4 @@ if (docSnap.exists()) { // doc.data() will be undefined in this case console.log("No such document!"); } -// [END modular_get_document] \ No newline at end of file +// [END get_document_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_document_options.js b/snippets/firestore-next/test-firestore/get_document_options.js index 30c0202a..ecaf4b55 100644 --- a/snippets/firestore-next/test-firestore/get_document_options.js +++ b/snippets/firestore-next/test-firestore/get_document_options.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_get_document_options] +// [START get_document_options_modular] import { collection, doc, getDocFromCache } from "firebase/firestore"; const docRef = doc(collection(db, "cities"), "SF"); @@ -18,4 +18,4 @@ try { } catch (e) { console.log("Error getting cached document:", e); } -// [END modular_get_document_options] \ No newline at end of file +// [END get_document_options_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_multiple.js b/snippets/firestore-next/test-firestore/get_multiple.js index 520765cf..9b1616c2 100644 --- a/snippets/firestore-next/test-firestore/get_multiple.js +++ b/snippets/firestore-next/test-firestore/get_multiple.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_get_multiple] +// [START get_multiple_modular] import { collection, query, where, getDocs } from "firebase/firestore"; const q = query(collection(db, "cities"), where("capital", "==", true)); @@ -13,4 +13,4 @@ querySnapshot.forEach((doc) => { // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); }); -// [END modular_get_multiple] \ No newline at end of file +// [END get_multiple_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/get_multiple_all.js b/snippets/firestore-next/test-firestore/get_multiple_all.js index b306e657..c61ec1ad 100644 --- a/snippets/firestore-next/test-firestore/get_multiple_all.js +++ b/snippets/firestore-next/test-firestore/get_multiple_all.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_get_multiple_all] +// [START get_multiple_all_modular] import { collection, getDocs } from "firebase/firestore"; const querySnapshot = await getDocs(collection(db, "cities")); @@ -11,4 +11,4 @@ querySnapshot.forEach((doc) => { // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); }); -// [END modular_get_multiple_all] \ No newline at end of file +// [END get_multiple_all_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/handle_listen_errors.js b/snippets/firestore-next/test-firestore/handle_listen_errors.js index 76012826..bb59c7d5 100644 --- a/snippets/firestore-next/test-firestore/handle_listen_errors.js +++ b/snippets/firestore-next/test-firestore/handle_listen_errors.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_handle_listen_errors] +// [START handle_listen_errors_modular] import { collection, onSnapshot } from "firebase/firestore"; const unsubscribe = onSnapshot( @@ -14,4 +14,4 @@ const unsubscribe = onSnapshot( (error) => { // ... }); -// [END modular_handle_listen_errors] \ No newline at end of file +// [END handle_listen_errors_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/in_filter.js b/snippets/firestore-next/test-firestore/in_filter.js index 4e752152..55f0a0a7 100644 --- a/snippets/firestore-next/test-firestore/in_filter.js +++ b/snippets/firestore-next/test-firestore/in_filter.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_in_filter] +// [START in_filter_modular] import { query, where } from "firebase/firestore"; const q = query(citiesRef, where('country', 'in', ['USA', 'Japan'])); -// [END modular_in_filter] \ No newline at end of file +// [END in_filter_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/in_filter_with_array.js b/snippets/firestore-next/test-firestore/in_filter_with_array.js index b3f1574c..722b11aa 100644 --- a/snippets/firestore-next/test-firestore/in_filter_with_array.js +++ b/snippets/firestore-next/test-firestore/in_filter_with_array.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_in_filter_with_array] +// [START in_filter_with_array_modular] import { query, where } from "firebase/firestore"; const q = query(citiesRef, where('regions', 'in', [['west_coast', 'east_coast']])); -// [END modular_in_filter_with_array] \ No newline at end of file +// [END in_filter_with_array_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/initialize_persistence.js b/snippets/firestore-next/test-firestore/initialize_persistence.js index 174539a1..97936466 100644 --- a/snippets/firestore-next/test-firestore/initialize_persistence.js +++ b/snippets/firestore-next/test-firestore/initialize_persistence.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_initialize_persistence] +// [START initialize_persistence_modular] import { enableIndexedDbPersistence } from "firebase/firestore"; enableIndexedDbPersistence(db) @@ -19,4 +19,4 @@ enableIndexedDbPersistence(db) } }); // Subsequent queries will use persistence, if it was enabled successfully -// [END modular_initialize_persistence] \ No newline at end of file +// [END initialize_persistence_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/invalid_filter_and_order.js b/snippets/firestore-next/test-firestore/invalid_filter_and_order.js index f24b3766..5d8e73e6 100644 --- a/snippets/firestore-next/test-firestore/invalid_filter_and_order.js +++ b/snippets/firestore-next/test-firestore/invalid_filter_and_order.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_invalid_filter_and_order] +// [START invalid_filter_and_order_modular] import { query, where, orderBy } from "firebase/firestore"; const q = query(citiesRef, where("population", ">", 100000), orderBy("country")); -// [END modular_invalid_filter_and_order] \ No newline at end of file +// [END invalid_filter_and_order_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/invalid_range_filters.js b/snippets/firestore-next/test-firestore/invalid_range_filters.js index d622ec8f..9ebde4ef 100644 --- a/snippets/firestore-next/test-firestore/invalid_range_filters.js +++ b/snippets/firestore-next/test-firestore/invalid_range_filters.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_invalid_range_filters] +// [START invalid_range_filters_modular] import { query, where } from "firebase/firestore"; const q = query(citiesRef, where("state", ">=", "CA"), where("population", ">", 100000)); -// [END modular_invalid_range_filters] \ No newline at end of file +// [END invalid_range_filters_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_diffs.js b/snippets/firestore-next/test-firestore/listen_diffs.js index 96fba665..0ef32dff 100644 --- a/snippets/firestore-next/test-firestore/listen_diffs.js +++ b/snippets/firestore-next/test-firestore/listen_diffs.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_listen_diffs] +// [START listen_diffs_modular] import { collection, query, where, onSnapshot } from "firebase/firestore"; const q = query(collection(db, "cities"), where("state", "==", "CA")); @@ -20,4 +20,4 @@ const unsubscribe = onSnapshot(q, (snapshot) => { } }); }); -// [END modular_listen_diffs] \ No newline at end of file +// [END listen_diffs_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_document.js b/snippets/firestore-next/test-firestore/listen_document.js index 3900cba7..54affb09 100644 --- a/snippets/firestore-next/test-firestore/listen_document.js +++ b/snippets/firestore-next/test-firestore/listen_document.js @@ -3,10 +3,10 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_listen_document] +// [START listen_document_modular] import { collection, doc, onSnapshot } from "firebase/firestore"; const unsub = onSnapshot(doc(collection(db, "cities"), "SF"), (doc) => { console.log("Current data: ", doc.data()); }); -// [END modular_listen_document] \ No newline at end of file +// [END listen_document_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_document_local.js b/snippets/firestore-next/test-firestore/listen_document_local.js index 09e3b56d..63a70475 100644 --- a/snippets/firestore-next/test-firestore/listen_document_local.js +++ b/snippets/firestore-next/test-firestore/listen_document_local.js @@ -3,11 +3,11 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_listen_document_local] +// [START listen_document_local_modular] import { collection, doc, onSnapshot } from "firebase/firestore"; const unsub = onSnapshot(doc(collection(db, "cities"), "SF"), (doc) => { const source = doc.metadata.hasPendingWrites ? "Local" : "Server"; console.log(source, " data: ", doc.data()); }); -// [END modular_listen_document_local] \ No newline at end of file +// [END listen_document_local_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_for_users.js b/snippets/firestore-next/test-firestore/listen_for_users.js index 32c9a602..0e3ede36 100644 --- a/snippets/firestore-next/test-firestore/listen_for_users.js +++ b/snippets/firestore-next/test-firestore/listen_for_users.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_listen_for_users] +// [START listen_for_users_modular] import { collection, where, query, onSnapshot } from "firebase/firestore"; const q = query(collection(db, "users"), where("born", "<", 1900)); @@ -13,4 +13,4 @@ const unsubscribe = onSnapshot(q, (snapshot) => { console.log(userSnapshot.data()) }); }); -// [END modular_listen_for_users] \ No newline at end of file +// [END listen_for_users_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_multiple.js b/snippets/firestore-next/test-firestore/listen_multiple.js index a5377c57..0c7f9d46 100644 --- a/snippets/firestore-next/test-firestore/listen_multiple.js +++ b/snippets/firestore-next/test-firestore/listen_multiple.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_listen_multiple] +// [START listen_multiple_modular] import { collection, query, where, onSnapshot } from "firebase/firestore"; const q = query(collection(db, "cities"), where("state", "==", "CA")); @@ -14,4 +14,4 @@ const unsubscribe = onSnapshot(q, (querySnapshot) => { }); console.log("Current cities in CA: ", cities.join(", ")); }); -// [END modular_listen_multiple] \ No newline at end of file +// [END listen_multiple_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_with_metadata.js b/snippets/firestore-next/test-firestore/listen_with_metadata.js index 93fc59b1..c40746b9 100644 --- a/snippets/firestore-next/test-firestore/listen_with_metadata.js +++ b/snippets/firestore-next/test-firestore/listen_with_metadata.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_listen_with_metadata] +// [START listen_with_metadata_modular] import { collection, doc, onSnapshot } from "firebase/firestore"; const unsub = onSnapshot( @@ -12,4 +12,4 @@ const unsub = onSnapshot( (doc) => { // ... }); -// [END modular_listen_with_metadata] \ No newline at end of file +// [END listen_with_metadata_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/new_document.js b/snippets/firestore-next/test-firestore/new_document.js index c854d854..c83e4aa6 100644 --- a/snippets/firestore-next/test-firestore/new_document.js +++ b/snippets/firestore-next/test-firestore/new_document.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_new_document] +// [START new_document_modular] import { collection, doc, setDoc } from "firebase/firestore"; // Add a new document with a generated id @@ -11,4 +11,4 @@ const newCityRef = doc(collection(db, "cities")); // later... await setDoc(newCityRef, data); -// [END modular_new_document] \ No newline at end of file +// [END new_document_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/not_in_filter.js b/snippets/firestore-next/test-firestore/not_in_filter.js index 614ade15..c880cb02 100644 --- a/snippets/firestore-next/test-firestore/not_in_filter.js +++ b/snippets/firestore-next/test-firestore/not_in_filter.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_not_in_filter] +// [START not_in_filter_modular] import { query, where } from "firebase/firestore"; const q = query(citiesRef, where('country', 'not-in', ['USA', 'Japan'])); -// [END modular_not_in_filter] \ No newline at end of file +// [END not_in_filter_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/order_and_end.js b/snippets/firestore-next/test-firestore/order_and_end.js index 23184342..d543ea06 100644 --- a/snippets/firestore-next/test-firestore/order_and_end.js +++ b/snippets/firestore-next/test-firestore/order_and_end.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_order_and_end] +// [START order_and_end_modular] import { query, orderBy, endAt } from "firebase/firestore"; const q = query(citiesRef, orderBy("population"), endAt(1000000)); -// [END modular_order_and_end] \ No newline at end of file +// [END order_and_end_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/order_and_limit.js b/snippets/firestore-next/test-firestore/order_and_limit.js index 344e231d..6979b518 100644 --- a/snippets/firestore-next/test-firestore/order_and_limit.js +++ b/snippets/firestore-next/test-firestore/order_and_limit.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_order_and_limit] +// [START order_and_limit_modular] import { query, orderBy, limit } from "firebase/firestore"; const q = query(citiesRef, orderBy("name"), limit(3)); -// [END modular_order_and_limit] \ No newline at end of file +// [END order_and_limit_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/order_and_limit_desc.js b/snippets/firestore-next/test-firestore/order_and_limit_desc.js index 13dee6bc..ed61d2ab 100644 --- a/snippets/firestore-next/test-firestore/order_and_limit_desc.js +++ b/snippets/firestore-next/test-firestore/order_and_limit_desc.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_order_and_limit_desc] +// [START order_and_limit_desc_modular] import { query, orderBy, limit } from "firebase/firestore"; const q = query(citiesRef, orderBy("name", "desc"), limit(3)); -// [END modular_order_and_limit_desc] \ No newline at end of file +// [END order_and_limit_desc_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/order_and_start.js b/snippets/firestore-next/test-firestore/order_and_start.js index 76c73863..20587a90 100644 --- a/snippets/firestore-next/test-firestore/order_and_start.js +++ b/snippets/firestore-next/test-firestore/order_and_start.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_order_and_start] +// [START order_and_start_modular] import { query, orderBy, startAt } from "firebase/firestore"; const q = query(citiesRef, orderBy("population"), startAt(1000000)); -// [END modular_order_and_start] \ No newline at end of file +// [END order_and_start_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/order_multiple.js b/snippets/firestore-next/test-firestore/order_multiple.js index 984b4c9a..c0991c8c 100644 --- a/snippets/firestore-next/test-firestore/order_multiple.js +++ b/snippets/firestore-next/test-firestore/order_multiple.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_order_multiple] +// [START order_multiple_modular] import { query, orderBy } from "firebase/firestore"; const q = query(citiesRef, orderBy("state"), orderBy("population", "desc")); -// [END modular_order_multiple] \ No newline at end of file +// [END order_multiple_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/paginate.js b/snippets/firestore-next/test-firestore/paginate.js index bded9e4e..26a7325b 100644 --- a/snippets/firestore-next/test-firestore/paginate.js +++ b/snippets/firestore-next/test-firestore/paginate.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_paginate] +// [START paginate_modular] import { collection, query, orderBy, startAfter, limit, getDocs } from "firebase/firestore"; // Query the first page of docs @@ -20,4 +20,4 @@ const next = query(collection(db, "cities"), orderBy("population"), startAfter(lastVisible), limit(25)); -// [END modular_paginate] \ No newline at end of file +// [END paginate_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js b/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js index fcc8fbdd..f59048e2 100644 --- a/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js +++ b/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_server_timestamp_resolution_options] +// [START server_timestamp_resolution_options_modular] import { collection, doc, updateDoc, serverTimestamp, onSnapshot } from "firebase/firestore"; // Perform an update followed by an immediate read without // waiting for the update to complete. Due to the snapshot @@ -23,4 +23,4 @@ onSnapshot(docRef, (snapshot) => { 'Timestamp: ' + data.timestamp + ', pending: ' + snapshot.metadata.hasPendingWrites); }); -// [END modular_server_timestamp_resolution_options] \ No newline at end of file +// [END server_timestamp_resolution_options_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/set_custom_object.js b/snippets/firestore-next/test-firestore/set_custom_object.js index e76639b7..a71d06ef 100644 --- a/snippets/firestore-next/test-firestore/set_custom_object.js +++ b/snippets/firestore-next/test-firestore/set_custom_object.js @@ -3,10 +3,10 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_set_custom_object] +// [START set_custom_object_modular] import { doc, collection, setDoc } from "firebase/firestore"; // Set with cityConverter const ref = doc(collection(db, "cities"), "LA").withConverter(cityConverter); await setDoc(ref, new City("Los Angeles", "CA", "USA")); -// [END modular_set_custom_object] \ No newline at end of file +// [END set_custom_object_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/set_document.js b/snippets/firestore-next/test-firestore/set_document.js index e6c7040b..d3c246ad 100644 --- a/snippets/firestore-next/test-firestore/set_document.js +++ b/snippets/firestore-next/test-firestore/set_document.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_set_document] +// [START set_document_modular] import { doc, collection, setDoc } from "firebase/firestore"; // Add a new document in collection "cities" @@ -12,4 +12,4 @@ await setDoc(doc(collection(db, "cities"), "LA"), { state: "CA", country: "USA" }); -// [END modular_set_document] \ No newline at end of file +// [END set_document_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/set_with_merge.js b/snippets/firestore-next/test-firestore/set_with_merge.js index 8957fe29..e3981920 100644 --- a/snippets/firestore-next/test-firestore/set_with_merge.js +++ b/snippets/firestore-next/test-firestore/set_with_merge.js @@ -3,9 +3,9 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_set_with_merge] +// [START set_with_merge_modular] import { doc, collection, setDoc } from "firebase/firestore"; const cityRef = doc(collection(db, 'cities'), 'BJ'); setDoc(cityRef, { capital: true }, { merge: true }); -// [END modular_set_with_merge] \ No newline at end of file +// [END set_with_merge_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/simple_queries.js b/snippets/firestore-next/test-firestore/simple_queries.js index 90449071..348cd4e6 100644 --- a/snippets/firestore-next/test-firestore/simple_queries.js +++ b/snippets/firestore-next/test-firestore/simple_queries.js @@ -3,11 +3,11 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_simple_queries] +// [START simple_queries_modular] // Create a reference to the cities collection import { collection, query, where } from "firebase/firestore"; const citiesRef = collection(db, "cities"); // Create a query against the collection. const q = query(citiesRef, where("state", "==", "CA")); -// [END modular_simple_queries] \ No newline at end of file +// [END simple_queries_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/simple_queries_again.js b/snippets/firestore-next/test-firestore/simple_queries_again.js index 41616318..f6256baf 100644 --- a/snippets/firestore-next/test-firestore/simple_queries_again.js +++ b/snippets/firestore-next/test-firestore/simple_queries_again.js @@ -3,9 +3,9 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_simple_queries_again] +// [START simple_queries_again_modular] import { collection, query, where } from "firebase/firestore"; const citiesRef = collection(db, "cities"); const q = query(citiesRef, where("capital", "==", true)); -// [END modular_simple_queries_again] \ No newline at end of file +// [END simple_queries_again_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/simple_query_not_equal.js b/snippets/firestore-next/test-firestore/simple_query_not_equal.js index 12154706..0ddb5643 100644 --- a/snippets/firestore-next/test-firestore/simple_query_not_equal.js +++ b/snippets/firestore-next/test-firestore/simple_query_not_equal.js @@ -3,6 +3,6 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_simple_query_not_equal] +// [START simple_query_not_equal_modular] const q4 = query(citiesRef, where("capital", "!=", false)); -// [END modular_simple_query_not_equal] \ No newline at end of file +// [END simple_query_not_equal_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/start_doc.js b/snippets/firestore-next/test-firestore/start_doc.js index 853a75ed..23f38e63 100644 --- a/snippets/firestore-next/test-firestore/start_doc.js +++ b/snippets/firestore-next/test-firestore/start_doc.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_start_doc] +// [START start_doc_modular] import { collection, doc, getDoc, query, orderBy, startAt } from "firebase/firestore"; const citiesRef = collection(db, "cities"); @@ -12,4 +12,4 @@ const docSnap = await getDoc(doc(citiesRef, "SF")); // Get all cities with a population bigger than San Francisco const biggerThanSf = query(citiesRef, orderBy("popuation"), startAt(docSnap)); // ... -// [END modular_start_doc] \ No newline at end of file +// [END start_doc_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/start_multiple_orderby.js b/snippets/firestore-next/test-firestore/start_multiple_orderby.js index a2782678..f0faaec0 100644 --- a/snippets/firestore-next/test-firestore/start_multiple_orderby.js +++ b/snippets/firestore-next/test-firestore/start_multiple_orderby.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_start_multiple_orderby] +// [START start_multiple_orderby_modular] // Will return all Springfields import { collection, query, orderBy, startAt } from "firebase/firestore"; const q1 = query(collection(db, "cities"), @@ -16,4 +16,4 @@ const q2 = query(collection(db, "cities"), orderBy("name"), orderBy("state"), startAt("Springfield", "Missouri")); -// [END modular_start_multiple_orderby] \ No newline at end of file +// [END start_multiple_orderby_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/subcollection_reference.js b/snippets/firestore-next/test-firestore/subcollection_reference.js index 5ea77ae4..56019331 100644 --- a/snippets/firestore-next/test-firestore/subcollection_reference.js +++ b/snippets/firestore-next/test-firestore/subcollection_reference.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_subcollection_reference] +// [START subcollection_reference_modular] import { doc, collection } from "firebase/firestore"; const messageRef = doc(collection(doc(collection(db, "rooms"), "roomA"), "messages"), "message1"); -// [END modular_subcollection_reference] \ No newline at end of file +// [END subcollection_reference_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/transaction.js b/snippets/firestore-next/test-firestore/transaction.js index 0591ade9..27b84264 100644 --- a/snippets/firestore-next/test-firestore/transaction.js +++ b/snippets/firestore-next/test-firestore/transaction.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_transaction] +// [START transaction_modular] import { runTransaction } from "firebase/firestore"; try { @@ -20,4 +20,4 @@ try { } catch (e) { console.log("Transaction failed: ", e); } -// [END modular_transaction] \ No newline at end of file +// [END transaction_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/transaction_promise.js b/snippets/firestore-next/test-firestore/transaction_promise.js index 9d76243f..ef5ca4c7 100644 --- a/snippets/firestore-next/test-firestore/transaction_promise.js +++ b/snippets/firestore-next/test-firestore/transaction_promise.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_transaction_promise] +// [START transaction_promise_modular] import { collection, doc, runTransaction } from "firebase/firestore"; // Create a reference to the SF doc. @@ -29,4 +29,4 @@ try { // This will be a "population is too big" error. console.error(e); } -// [END modular_transaction_promise] \ No newline at end of file +// [END transaction_promise_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_delete_field.js b/snippets/firestore-next/test-firestore/update_delete_field.js index 007db2d3..b5477302 100644 --- a/snippets/firestore-next/test-firestore/update_delete_field.js +++ b/snippets/firestore-next/test-firestore/update_delete_field.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_update_delete_field] +// [START update_delete_field_modular] import { doc, collection, updateDoc, deleteField } from "firebase/firestore"; const cityRef = doc(collection(db, 'cities'), 'BJ'); @@ -12,4 +12,4 @@ const cityRef = doc(collection(db, 'cities'), 'BJ'); await updateDoc(cityRef, { capital: deleteField() }); -// [END modular_update_delete_field] \ No newline at end of file +// [END update_delete_field_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_document.js b/snippets/firestore-next/test-firestore/update_document.js index eb17b744..02c21f35 100644 --- a/snippets/firestore-next/test-firestore/update_document.js +++ b/snippets/firestore-next/test-firestore/update_document.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_update_document] +// [START update_document_modular] import { collection, doc, updateDoc } from "firebase/firestore"; const washingtonRef = doc(collection(db, "cities"), "DC"); @@ -12,4 +12,4 @@ const washingtonRef = doc(collection(db, "cities"), "DC"); await updateDoc(washingtonRef, { capital: true }); -// [END modular_update_document] \ No newline at end of file +// [END update_document_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_document_array.js b/snippets/firestore-next/test-firestore/update_document_array.js index 39c59bdb..e2c07145 100644 --- a/snippets/firestore-next/test-firestore/update_document_array.js +++ b/snippets/firestore-next/test-firestore/update_document_array.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_update_document_array] +// [START update_document_array_modular] import { collection, doc, updateDoc, arrayUnion, arrayRemove } from "firebase/firestore"; const washingtonRef = doc(collection(db, "cities"), "DC"); @@ -17,4 +17,4 @@ await updateDoc(washingtonRef, { await updateDoc(washingtonRef, { regions: arrayRemove("east_coast") }); -// [END modular_update_document_array] \ No newline at end of file +// [END update_document_array_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_document_increment.js b/snippets/firestore-next/test-firestore/update_document_increment.js index 05ff44eb..5ad2bb6a 100644 --- a/snippets/firestore-next/test-firestore/update_document_increment.js +++ b/snippets/firestore-next/test-firestore/update_document_increment.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_update_document_increment] +// [START update_document_increment_modular] import { collection, doc, updateDoc, increment } from "firebase/firestore"; const washingtonRef = doc(collection(db, "cities"), "DC"); @@ -12,4 +12,4 @@ const washingtonRef = doc(collection(db, "cities"), "DC"); await updateDoc(washingtonRef, { population: increment(50) }); -// [END modular_update_document_increment] \ No newline at end of file +// [END update_document_increment_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_document_nested.js b/snippets/firestore-next/test-firestore/update_document_nested.js index 0efd286c..a1412018 100644 --- a/snippets/firestore-next/test-firestore/update_document_nested.js +++ b/snippets/firestore-next/test-firestore/update_document_nested.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_update_document_nested] +// [START update_document_nested_modular] import { doc, collection, setDoc, updateDoc } from "firebase/firestore"; // Create an initial document to update. @@ -19,4 +19,4 @@ await updateDoc(frankDocRef, { "age": 13, "favorites.color": "Red" }); -// [END modular_update_document_nested] \ No newline at end of file +// [END update_document_nested_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/update_with_server_timestamp.js b/snippets/firestore-next/test-firestore/update_with_server_timestamp.js index 3fa9febc..39cb4c94 100644 --- a/snippets/firestore-next/test-firestore/update_with_server_timestamp.js +++ b/snippets/firestore-next/test-firestore/update_with_server_timestamp.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_update_with_server_timestamp] +// [START update_with_server_timestamp_modular] import { collection, updateDoc, serverTimestamp } from "firebase/firestore"; const docRef = doc(collection(db, 'objects'), 'some-id'); @@ -12,4 +12,4 @@ const docRef = doc(collection(db, 'objects'), 'some-id'); const updateTimestamp = await updateDoc(docRef, { timestamp: serverTimestamp() }); -// [END modular_update_with_server_timestamp] \ No newline at end of file +// [END update_with_server_timestamp_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/use_from_cache.js b/snippets/firestore-next/test-firestore/use_from_cache.js index dc689d8a..9f125e6c 100644 --- a/snippets/firestore-next/test-firestore/use_from_cache.js +++ b/snippets/firestore-next/test-firestore/use_from_cache.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_use_from_cache] +// [START use_from_cache_modular] import { collection, onSnapshot, where, query } from "firebase/firestore"; const q = query(collection(db, "cities"), where("state", "==", "CA")); @@ -17,4 +17,4 @@ onSnapshot(q, { includeMetadataChanges: true }, (snapshot) => { console.log("Data came from " + source); }); }); -// [END modular_use_from_cache] \ No newline at end of file +// [END use_from_cache_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/valid_filter_and_order.js b/snippets/firestore-next/test-firestore/valid_filter_and_order.js index fc4d54f0..ae2519d0 100644 --- a/snippets/firestore-next/test-firestore/valid_filter_and_order.js +++ b/snippets/firestore-next/test-firestore/valid_filter_and_order.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_valid_filter_and_order] +// [START valid_filter_and_order_modular] import { query, where, orderBy } from "firebase/firestore"; const q = query(citiesRef, where("population", ">", 100000), orderBy("population")); -// [END modular_valid_filter_and_order] \ No newline at end of file +// [END valid_filter_and_order_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/valid_range_filters.js b/snippets/firestore-next/test-firestore/valid_range_filters.js index bd39bac2..cd559456 100644 --- a/snippets/firestore-next/test-firestore/valid_range_filters.js +++ b/snippets/firestore-next/test-firestore/valid_range_filters.js @@ -3,9 +3,9 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_valid_range_filters] +// [START valid_range_filters_modular] import { query, where } from "firebase/firestore"; const q1 = query(citiesRef, where("state", ">=", "CA"), where("state", "<=", "IN")); const q2 = query(citiesRef, where("state", "==", "CA"), where("population", ">", 1000000)); -// [END modular_valid_range_filters] \ No newline at end of file +// [END valid_range_filters_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/write_batch.js b/snippets/firestore-next/test-firestore/write_batch.js index 605cdbb7..157d1bcf 100644 --- a/snippets/firestore-next/test-firestore/write_batch.js +++ b/snippets/firestore-next/test-firestore/write_batch.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_write_batch] +// [START write_batch_modular] import { writeBatch, doc, collection } from "firebase/firestore"; // Get a new write batch @@ -23,4 +23,4 @@ batch.delete(laRef); // Commit the batch await batch.commit(); -// [END modular_write_batch] \ No newline at end of file +// [END write_batch_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js b/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js index 2b690134..7f820455 100644 --- a/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js +++ b/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js @@ -3,9 +3,9 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_get_collection_ratings] +// [START get_collection_ratings_modular] import { collection, doc, getDocs } from "firebase/firestore"; const ratingsRef = collection(doc(collection(db, "restaurants"), "arinell-pizza"), "ratings"); const ratingsDocs = await getDocs(ratingsRef); -// [END modular_get_collection_ratings] \ No newline at end of file +// [END get_collection_ratings_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-aggregation/sample_doc.js b/snippets/firestore-next/test-solution-aggregation/sample_doc.js index 2c25bc70..dfc54ebf 100644 --- a/snippets/firestore-next/test-solution-aggregation/sample_doc.js +++ b/snippets/firestore-next/test-solution-aggregation/sample_doc.js @@ -3,10 +3,10 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_sample_doc] +// [START sample_doc_modular] const arinellDoc = { name: 'Arinell Pizza', avgRating: 4.65, numRatings: 683 } -// [END modular_sample_doc] \ No newline at end of file +// [END sample_doc_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/post_with_array.js b/snippets/firestore-next/test-solution-arrays/post_with_array.js index 2c3e5985..da070d3d 100644 --- a/snippets/firestore-next/test-solution-arrays/post_with_array.js +++ b/snippets/firestore-next/test-solution-arrays/post_with_array.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_post_with_array] +// [START post_with_array_modular] // Sample document in the 'posts' collection. { title: "My great post", @@ -13,4 +13,4 @@ "cats" ] } -// [END modular_post_with_array] \ No newline at end of file +// [END post_with_array_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/post_with_map.js b/snippets/firestore-next/test-solution-arrays/post_with_map.js index 59286b89..36ce26cc 100644 --- a/snippets/firestore-next/test-solution-arrays/post_with_map.js +++ b/snippets/firestore-next/test-solution-arrays/post_with_map.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_post_with_map] +// [START post_with_map_modular] // Sample document in the 'posts' collection { title: "My great post", @@ -13,4 +13,4 @@ "cats": true } } -// [END modular_post_with_map] \ No newline at end of file +// [END post_with_map_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js b/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js index 3553248c..b5b40eca 100644 --- a/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js +++ b/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_post_with_map_advanced] +// [START post_with_map_advanced_modular] // The value of each entry in 'categories' is a unix timestamp { title: "My great post", @@ -13,4 +13,4 @@ cats: 1502144665 } } -// [END modular_post_with_map_advanced] \ No newline at end of file +// [END post_with_map_advanced_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category.js b/snippets/firestore-next/test-solution-arrays/query_in_category.js index 3388cdb5..212ef92b 100644 --- a/snippets/firestore-next/test-solution-arrays/query_in_category.js +++ b/snippets/firestore-next/test-solution-arrays/query_in_category.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_query_in_category] +// [START query_in_category_modular] import { collection, getDocs, query, where } from "firebase/firestore"; // Find all documents in the 'posts' collection that are @@ -11,4 +11,4 @@ import { collection, getDocs, query, where } from "firebase/firestore"; const q = query(collection(db, "posts"), where("categories.cats", "==", true)); const docs = await getDocs(q); // ... -// [END modular_query_in_category] \ No newline at end of file +// [END query_in_category_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js index 6c6c0726..88477e12 100644 --- a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js +++ b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js @@ -3,10 +3,10 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_query_in_category_timestamp] +// [START query_in_category_timestamp_modular] import { collection, query, where, orderBy } from "@firebase/firestore"; const q = query(collection(db, "posts"), where("categories.cats", ">", 0), orderBy("categories.cats")); -// [END modular_query_in_category_timestamp] \ No newline at end of file +// [END query_in_category_timestamp_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js index 511acbfd..65a84c9f 100644 --- a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js +++ b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js @@ -3,10 +3,10 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_query_in_category_timestamp_invalid] +// [START query_in_category_timestamp_invalid_modular] import { collection, query, where, orderBy, FirebaseFirestore } from "@firebase/firestore"; const q = query(collection(db, "posts"), where("categories.cats", "==", true), orderBy("timestamp")); -// [END modular_query_in_category_timestamp_invalid] \ No newline at end of file +// [END query_in_category_timestamp_invalid_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-counters/create_counter.js b/snippets/firestore-next/test-solution-counters/create_counter.js index 4cc05cb9..d69b00e6 100644 --- a/snippets/firestore-next/test-solution-counters/create_counter.js +++ b/snippets/firestore-next/test-solution-counters/create_counter.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_create_counter] +// [START create_counter_modular] function createCounter(ref, num_shards) { import { collection, doc, writeBatch } from "firebase/firestore"; @@ -21,4 +21,4 @@ function createCounter(ref, num_shards) { // Commit the write batch return batch.commit(); } -// [END modular_create_counter] \ No newline at end of file +// [END create_counter_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-counters/get_count.js b/snippets/firestore-next/test-solution-counters/get_count.js index dcf61f55..04434fcd 100644 --- a/snippets/firestore-next/test-solution-counters/get_count.js +++ b/snippets/firestore-next/test-solution-counters/get_count.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_get_count] +// [START get_count_modular] async function getCount(ref) { import { collection, getDocs } from "@firebase/firestore"; @@ -17,4 +17,4 @@ async function getCount(ref) { return totalCount; } -// [END modular_get_count] \ No newline at end of file +// [END get_count_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-counters/increment_counter.js b/snippets/firestore-next/test-solution-counters/increment_counter.js index 53f5f28a..278fea5f 100644 --- a/snippets/firestore-next/test-solution-counters/increment_counter.js +++ b/snippets/firestore-next/test-solution-counters/increment_counter.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_increment_counter] +// [START increment_counter_modular] function incrementCounter(db, ref, num_shards) { import { collection, doc, updateDoc, increment, FirebaseFirestore } from "@firebase/firestore"; @@ -14,4 +14,4 @@ function incrementCounter(db, ref, num_shards) { // Update count return updateDoc(shardRef, "count", increment(1)); } -// [END modular_increment_counter] \ No newline at end of file +// [END increment_counter_modular] \ No newline at end of file diff --git a/snippets/functions-next/emulator-suite/functions_callable_call.js b/snippets/functions-next/emulator-suite/functions_callable_call.js index 31a244c7..8ac5f8ed 100644 --- a/snippets/functions-next/emulator-suite/functions_callable_call.js +++ b/snippets/functions-next/emulator-suite/functions_callable_call.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_functions_callable_call] +// [START functions_callable_call_modular] import { getApp } from "firebase/app"; import { getFunctions, httpsCallable } from "firebase/functions"; @@ -13,4 +13,4 @@ const addMessage = httpsCallable(functions, 'addMessage'); const result = await addMessage({ text: ''}); const sanitizedMessage = result.data.text; // ... -// [END modular_functions_callable_call] \ No newline at end of file +// [END functions_callable_call_modular] \ No newline at end of file diff --git a/snippets/functions-next/emulator-suite/functions_emulator_connect.js b/snippets/functions-next/emulator-suite/functions_emulator_connect.js index 04957e67..a25d2724 100644 --- a/snippets/functions-next/emulator-suite/functions_emulator_connect.js +++ b/snippets/functions-next/emulator-suite/functions_emulator_connect.js @@ -3,10 +3,10 @@ // // To make edits to the snippets in this file, please edit the source -// [START modular_functions_emulator_connect] +// [START functions_emulator_connect_modular] import { getApp } from "firebase/app"; import { getFunctions, useFunctionsEmulator } from "firebase/functions"; const functions = getFunctions(getApp()); useFunctionsEmulator(functions, "http://localhost:5001"); -// [END modular_functions_emulator_connect] \ No newline at end of file +// [END functions_emulator_connect_modular] \ No newline at end of file From 304f1685347beb435505fc27b6ab356461e90e39 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 6 Nov 2020 02:37:58 -0800 Subject: [PATCH 021/235] Auto-update dependencies. (#50) --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/auth/package.json b/auth/package.json index f4589364..e0eabb63 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.0.0" + "firebase": "^8.0.1" } } diff --git a/database/package.json b/database/package.json index 691cd82d..02dc1df8 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.0.0" + "firebase": "^8.0.1" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index e9d70521..12dbc583 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.0.0" + "firebase": "^8.0.1" } } diff --git a/firestore/package.json b/firestore/package.json index 39515e79..0ff20653 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.0.0" + "firebase": "^8.0.1" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/functions/package.json b/functions/package.json index 87065032..616fbc2a 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.0.0" + "firebase": "^8.0.1" } } diff --git a/installations/package.json b/installations/package.json index cddcb587..d16cdfbe 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.0.0" + "firebase": "^8.0.1" } } From 466e8c7fa31f4933bdcbdf1842e99c798902d9d5 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 6 Nov 2020 07:40:30 -0800 Subject: [PATCH 022/235] Auto-update dependencies. (#51) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 0e44455f..345f2291 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From e1ceac9b487ed5ffffc5fc17be08bfe6da33ce60 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 10 Nov 2020 12:24:39 -0500 Subject: [PATCH 023/235] Add "coming soon" snippet --- snippets/placeholder.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 snippets/placeholder.js diff --git a/snippets/placeholder.js b/snippets/placeholder.js new file mode 100644 index 00000000..c5da7069 --- /dev/null +++ b/snippets/placeholder.js @@ -0,0 +1,3 @@ +// [START coming_soon_modular] +// TODO: Snippet coming soon! +// [END coming_soon_modular] From d99938ef5ebab3781e81dd53aec572bc83fa27cf Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 12 Nov 2020 13:57:37 +0000 Subject: [PATCH 024/235] Auth: apple, cordova, and more --- auth/apple.js | 204 +++++++++++++++++++++++++++++++++ auth/auth-state-persistence.js | 45 ++++++++ auth/cordova.js | 57 +++++++++ auth/custom-email-handler.js | 143 +++++++++++++++++++++++ auth/index.js | 39 +++++++ 5 files changed, 488 insertions(+) create mode 100644 auth/apple.js create mode 100644 auth/auth-state-persistence.js create mode 100644 auth/cordova.js create mode 100644 auth/custom-email-handler.js create mode 100644 auth/index.js diff --git a/auth/apple.js b/auth/apple.js new file mode 100644 index 00000000..3a7a2c20 --- /dev/null +++ b/auth/apple.js @@ -0,0 +1,204 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/apple.md + +function appleProvider() { + // [START auth_apple_provider_create] + var provider = new firebase.auth.OAuthProvider('apple.com'); + // [END auth_apple_provider_create] + + // [START auth_apple_provider_scopes] + provider.addScope('email'); + provider.addScope('name'); + // [END auth_apple_provider_scopes] + + // [START auth_apple_provider_params] + provider.setCustomParameters({ + // Localize the Apple authentication screen in French. + locale: 'fr' + }); + // [END auth_apple_provider_params] +} + +function appleSignInPopup(provider) { + // [START auth_apple_signin_popup] + firebase + .auth() + .signInWithPopup(provider) + .then((result) => { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // The signed-in user info. + var user = result.user; + + // You can also get the Apple OAuth Access and ID Tokens. + var accessToken = credential.accessToken; + var idToken = credential.idToken; + + // ... + }) + .catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + + // ... + }); + // [END auth_apple_signin_popup] +} + +function appleSignInRedirect(provider) { + // [START auth_apple_signin_redirect] + firebase.auth().signInWithRedirect(provider); + // [END auth_apple_signin_redirect] +} + +function appleSignInRedirectResult() { + // [START auth_apple_signin_redirect_result] + // Result from Redirect auth flow. + firebase + .auth() + .getRedirectResult() + .then((result) => { + if (result.credential) { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // You can get the Apple OAuth Access and ID Tokens. + var accessToken = credential.accessToken; + var idToken = credential.idToken; + + // ... + } + // The signed-in user info. + var user = result.user; + }) + .catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + + // ... + }); + // [END auth_apple_signin_redirect_result] +} + +function appleReauthenticatePopup() { + // [START auth_apple_reauthenticate_popup] + const provider = new firebase.auth.OAuthProvider('apple.com'); + + firebase + .auth() + .currentUser + .reauthenticateWithPopup(provider) + .then((result) => { + // User is re-authenticated with fresh tokens minted and can perform + // sensitive operations like account deletion, or updating their email + // address or password. + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // The signed-in user info. + var user = result.user; + // You can also get the Apple OAuth Access and ID Tokens. + var accessToken = credential.accessToken; + var idToken = credential.idToken; + + // ... + }) + .catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + + // ... + }); + // [END auth_apple_reauthenticate_popup] +} + +function appleLinkFacebook() { + // [START auth_apple_link_facebook] + const provider = new firebase.auth.FacebookAuthProvider(); + provider.addScope('user_birthday'); + + // Assuming the current user is an Apple user linking a Facebook provider. + firebase.auth().currentUser.linkWithPopup(provider) + .then((result) => { + // Facebook credential is linked to the current Apple user. + // Facebook additional data available in result.additionalUserInfo.profile, + // Additional Facebook OAuth access token can also be retrieved. + // result.credential.accessToken + + // The user can now sign in to the same account + // with either Apple or Facebook. + }) + .catch((error) => { + // Handle error. + }); + // [END auth_apple_link_facebook] +} + +function appleNonceNode() { + // [START auth_apple_nonce_node] + const crypto = require("crypto"); + const string_decoder = require("string_decoder"); + + // Generate a new random string for each sign-in + const generateNonce = function(length) { + const decoder = new string_decoder.StringDecoder("ascii"); + const buf = Buffer.alloc(length); + var nonce = ""; + while (nonce.length < length) { + crypto.randomFillSync(buf); + nonce = decoder.write(buf); + } + return nonce.substr(0, length); + }; + + const unhashedNonce = generateNonce(10); + + // SHA256-hashed nonce in hex + const hashedNonceHex = crypto.createHash('sha256') + .update(unhashedNonce).digest().toString('hex'); + // [END auth_apple_nonce_node] +} + +function appleSignInNonce(appleIdToken, unhashedNonce,) { + // [START auth_apple_signin_nonce] + // Build Firebase credential with the Apple ID token. + const provider = new firebase.auth.OAuthProvider('apple.com'); + const authCredential = provider.credential({ + idToken: appleIdToken, + rawNonce: unhashedNonce, + }); + + // Sign in with credential form the Apple user. + firebase.auth().signInWithCredential(authCredential) + .then((result) => { + // User signed in. + }) + .catch((error) => { + // An error occurred. If error.code == 'auth/missing-or-invalid-nonce', + // make sure you're sending the SHA256-hashed nonce as a hex string + // with your request to Apple. + console.log(error); + }); + // [END auth_apple_signin_nonce] +} diff --git a/auth/auth-state-persistence.js b/auth/auth-state-persistence.js new file mode 100644 index 00000000..c85f1da2 --- /dev/null +++ b/auth/auth-state-persistence.js @@ -0,0 +1,45 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +function setPersistenceSession() { + var email = "..."; + var password = "..."; + + // [START auth_set_persistence_session] + firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION) + .then(() => { + // Existing and future Auth states are now persisted in the current + // session only. Closing the window would clear any existing state even + // if a user forgets to sign out. + // ... + // New sign-in will be persisted with session persistence. + return firebase.auth().signInWithEmailAndPassword(email, password); + }) + .catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + }); + // [END auth_set_persistence_session] +} + +function setPersistenceNone() { + // [START auth_set_persistence_none] + firebase.auth().setPersistence(firebase.auth.Auth.Persistence.NONE) + .then(() => { + var provider = new firebase.auth.GoogleAuthProvider(); + // In memory persistence will be applied to the signed in Google user + // even though the persistence was set to 'none' and a page redirect + // occurred. + return firebase.auth().signInWithRedirect(provider); + }) + .catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + }); + // [END auth_set_persistence_none] +} diff --git a/auth/cordova.js b/auth/cordova.js new file mode 100644 index 00000000..1da36ef1 --- /dev/null +++ b/auth/cordova.js @@ -0,0 +1,57 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/cordova.md + +function createGoogleProvider() { + // [START auth_create_google_provider] + var provider = new firebase.auth.GoogleAuthProvider(); + // [END auth_create_google_provider] +} + +function cordovaSignInRedirect(provider) { + // [START auth_cordova_sign_in_redirect] + firebase.auth().signInWithRedirect(provider).then(function() { + return firebase.auth().getRedirectResult(); + }).then((result) => { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // This gives you a Google Access Token. + // You can use it to access the Google API. + var token = credential.accessToken; + // The signed-in user info. + var user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + }); + // [END auth_cordova_sign_in_redirect] +} + +function cordovaRedirectResult() { + // [START auth_cordova_redirect_result] + firebase.auth().getRedirectResult().then((result) => { + if (result.credential) { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // This gives you a Google Access Token. + // You can use it to access the Google API. + var token = credential.accessToken; + // The signed-in user info. + var user = result.user; + // ... + } + }).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + }); + // [END auth_cordova_redirect_result] +} diff --git a/auth/custom-email-handler.js b/auth/custom-email-handler.js new file mode 100644 index 00000000..aea89aad --- /dev/null +++ b/auth/custom-email-handler.js @@ -0,0 +1,143 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/custom-email-handler.md + +function handleUserManagementQueryParams() { + // TODO: This helpers should be implemented by the developer + function getParameterByName(name) { + return ""; + } + + // [START auth_handle_mgmt_query_params] + document.addEventListener('DOMContentLoaded', () => { + // TODO: Implement getParameterByName() + + // Get the action to complete. + var mode = getParameterByName('mode'); + // Get the one-time code from the query parameter. + var actionCode = getParameterByName('oobCode'); + // (Optional) Get the continue URL from the query parameter if available. + var continueUrl = getParameterByName('continueUrl'); + // (Optional) Get the language code if available. + var lang = getParameterByName('lang') || 'en'; + + // Configure the Firebase SDK. + // This is the minimum configuration required for the API to be used. + var config = { + 'apiKey': "YOU_API_KEY" // Copy this key from the web initialization + // snippet found in the Firebase console. + }; + var app = firebase.initializeApp(config); + var auth = app.auth(); + + // Handle the user management action. + switch (mode) { + case 'resetPassword': + // Display reset password handler and UI. + handleResetPassword(auth, actionCode, continueUrl, lang); + break; + case 'recoverEmail': + // Display email recovery handler and UI. + handleRecoverEmail(auth, actionCode, lang); + break; + case 'verifyEmail': + // Display email verification handler and UI. + handleVerifyEmail(auth, actionCode, continueUrl, lang); + break; + default: + // Error: invalid mode. + } + }, false); + // [END auth_handle_mgmt_query_params] +} + +// [START auth_handle_reset_password] +function handleResetPassword(auth, actionCode, continueUrl, lang) { + // Localize the UI to the selected language as determined by the lang + // parameter. + + // Verify the password reset code is valid. + auth.verifyPasswordResetCode(actionCode).then((email) => { + var accountEmail = email; + + // TODO: Show the reset screen with the user's email and ask the user for + // the new password. + var newPassword = "..."; + + // Save the new password. + auth.confirmPasswordReset(actionCode, newPassword).then((resp) => { + // Password reset has been confirmed and new password updated. + + // TODO: Display a link back to the app, or sign-in the user directly + // if the page belongs to the same domain as the app: + // auth.signInWithEmailAndPassword(accountEmail, newPassword); + + // TODO: If a continue URL is available, display a button which on + // click redirects the user back to the app via continueUrl with + // additional state determined from that URL's parameters. + }).catch((error) => { + // Error occurred during confirmation. The code might have expired or the + // password is too weak. + }); + }).catch((error) => { + // Invalid or expired action code. Ask user to try to reset the password + // again. + }); +} +// [END auth_handle_reset_password] + +// [START auth_handle_recover_email] +function handleRecoverEmail(auth, actionCode, lang) { + // Localize the UI to the selected language as determined by the lang + // parameter. + var restoredEmail = null; + // Confirm the action code is valid. + auth.checkActionCode(actionCode).then((info) => { + // Get the restored email address. + restoredEmail = info['data']['email']; + + // Revert to the old email. + return auth.applyActionCode(actionCode); + }).then(() => { + // Account email reverted to restoredEmail + + // TODO: Display a confirmation message to the user. + + // You might also want to give the user the option to reset their password + // in case the account was compromised: + auth.sendPasswordResetEmail(restoredEmail).then(() => { + // Password reset confirmation sent. Ask user to check their email. + }).catch((error) => { + // Error encountered while sending password reset code. + }); + }).catch((error) => { + // Invalid code. + }); +} +// [END auth_handle_recover_emai] + +// [START auth_handle_verify_email] +function handleVerifyEmail(auth, actionCode, continueUrl, lang) { + // Localize the UI to the selected language as determined by the lang + // parameter. + // Try to apply the email verification code. + auth.applyActionCode(actionCode).then((resp) => { + // Email address has been verified. + + // TODO: Display a confirmation message to the user. + // You could also provide the user with a link back to the app. + + // TODO: If a continue URL is available, display a button which on + // click redirects the user back to the app via continueUrl with + // additional state determined from that URL's parameters. + }).catch((error) => { + // Code is invalid or expired. Ask the user to verify their email address + // again. + }); +} +// [END auth_handle_verify_email] + diff --git a/auth/index.js b/auth/index.js new file mode 100644 index 00000000..a1c9fb6b --- /dev/null +++ b/auth/index.js @@ -0,0 +1,39 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/_includes/_get_credentials_web.html + +function makeGoogleCredential(googleUser) { + // [START auth_make_google_credential] + var credential = firebase.auth.GoogleAuthProvider.credential( + googleUser.getAuthResponse().id_token); + // [END auth_make_google_credential] +} + +function makeFacebookCredential(response) { + // [START auth_make_facebook_credential] + var credential = firebase.auth.FacebookAuthProvider.credential( + response.authResponse.accessToken); + // [END auth_make_facebook_credential] +} + +function makeEmailCredential(email, password) { + // [START auth_make_email_credential] + var credential = firebase.auth.EmailAuthProvider.credential(email, password); + // [END auth_make_email_credential] +} + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/_includes/_next_steps_web.html + +function signOut() { + // [START auth_sign_out] + firebase.auth().signOut().then(() => { + // Sign-out successful. + }).catch((error) => { + // An error happened. + }); + // [END auth_sign_out] +} From 5222d149f4924a5e96820e44bffb43f1a09a5fec Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 12 Nov 2020 14:40:56 +0000 Subject: [PATCH 025/235] Auth: email link, firebaseui --- auth/email-link-auth.js | 140 +++++++++++++++++++ auth/firebaseui.js | 301 ++++++++++++++++++++++++++++++++++++++++ auth/package.json | 3 +- 3 files changed, 443 insertions(+), 1 deletion(-) create mode 100644 auth/email-link-auth.js create mode 100644 auth/firebaseui.js diff --git a/auth/email-link-auth.js b/auth/email-link-auth.js new file mode 100644 index 00000000..d008a0cf --- /dev/null +++ b/auth/email-link-auth.js @@ -0,0 +1,140 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/email-link-auth.md + +function emailLinkActionCodeSettings() { + // [START auth_email_link_actioncode_settings] + var actionCodeSettings = { + // URL you want to redirect back to. The domain (www.example.com) for this + // URL must be in the authorized domains list in the Firebase Console. + url: 'https://www.example.com/finishSignUp?cartId=1234', + // This must be true. + handleCodeInApp: true, + iOS: { + bundleId: 'com.example.ios' + }, + android: { + packageName: 'com.example.android', + installApp: true, + minimumVersion: '12' + }, + dynamicLinkDomain: 'example.page.link' + }; + // [END auth_email_link_actioncode_settings] +} + +function emailLinkSend(email, actionCodeSettings) { + // [START auth_email_link_send] + firebase.auth().sendSignInLinkToEmail(email, actionCodeSettings) + .then(() => { + // The link was successfully sent. Inform the user. + // Save the email locally so you don't need to ask the user for it again + // if they open the link on the same device. + window.localStorage.setItem('emailForSignIn', email); + }) + .catch((error) => { + // Some error occurred, you can inspect the code: error.code + }); + // [END auth_email_link_send] +} + +function emailLinkComplete() { + // [START email_link_complete] + // Confirm the link is a sign-in with email link. + if (firebase.auth().isSignInWithEmailLink(window.location.href)) { + // Additional state parameters can also be passed via URL. + // This can be used to continue the user's intended action before triggering + // the sign-in operation. + // Get the email if available. This should be available if the user completes + // the flow on the same device where they started it. + var email = window.localStorage.getItem('emailForSignIn'); + if (!email) { + // User opened the link on a different device. To prevent session fixation + // attacks, ask the user to provide the associated email again. For example: + email = window.prompt('Please provide your email for confirmation'); + } + // The client SDK will parse the code from the link for you. + firebase.auth().signInWithEmailLink(email, window.location.href) + .then((result) => { + // Clear email from storage. + window.localStorage.removeItem('emailForSignIn'); + // You can access the new user via result.user + // Additional user info profile not available via: + // result.additionalUserInfo.profile == null + // You can check if the user is new or existing: + // result.additionalUserInfo.isNewUser + }) + .catch((error) => { + // Some error occurred, you can inspect the code: error.code + // Common errors could be invalid email and invalid or expired OTPs. + }); + } + // [END email_link_complete] +} + +function emailLinkLink(email) { + // [START auth_email_link_link] + // Construct the email link credential from the current URL. + var credential = firebase.auth.EmailAuthProvider.credentialWithLink( + email, window.location.href); + + // Link the credential to the current user. + firebase.auth().currentUser.linkWithCredential(credential) + .then((usercred) => { + // The provider is now successfully linked. + // The phone user can now sign in with their phone number or email. + }) + .catch((error) => { + // Some error occurred. + }); + // [END auth_email_link_link] +} + +function emailLinkReauth(email) { + // [START auth_email_link_reauth] + // Construct the email link credential from the current URL. + var credential = firebase.auth.EmailAuthProvider.credentialWithLink( + email, window.location.href); + + // Re-authenticate the user with this credential. + firebase.auth().currentUser.reauthenticateWithCredential(credential) + .then((usercred) => { + // The user is now successfully re-authenticated and can execute sensitive + // operations. + }) + .catch((error) => { + // Some error occurred. + }); + // [END auth_email_link_reauth] +} + +function emailLinkDifferentiate() { + // [START email_link_diferentiate] + // After asking the user for their email. + var email = window.prompt('Please provide your email'); + firebase.auth().fetchSignInMethodsForEmail(email) + .then((signInMethods) => { + // This returns the same array as fetchProvidersForEmail but for email + // provider identified by 'password' string, signInMethods would contain 2 + // different strings: + // 'emailLink' if the user previously signed in with an email/link + // 'password' if the user has a password. + // A user could have both. + if (signInMethods.indexOf( + firebase.auth.EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD) != -1) { + // User can sign in with email/password. + } + if (signInMethods.indexOf( + firebase.auth.EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD) != -1) { + // User can sign in with email/link. + } + }) + .catch((error) => { + // Some error occurred, you can inspect the code: error.code + }); + // [END email_link_diferentiate] +} diff --git a/auth/firebaseui.js b/auth/firebaseui.js new file mode 100644 index 00000000..fde03e67 --- /dev/null +++ b/auth/firebaseui.js @@ -0,0 +1,301 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +import * as firebaseui from "firebaseui" + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/firebaseui.md + +function fuiInit() { + // [START auth_fui_init] + var ui = new firebaseui.auth.AuthUI(firebase.auth()); + // [END auth_fui_init] + + return ui; +} + +function fuiStartEmail() { + var ui = fuiInit(); + // [START auth_fui_start_email] + ui.start('#firebaseui-auth-container', { + signInOptions: [ + firebase.auth.EmailAuthProvider.PROVIDER_ID + ], + // Other config options... + }); + // [END auth_fui_start_email] +} + +function fuiStartEmailOptions() { + var ui = fuiInit(); + // [START auth_fui_start_email_options] + ui.start('#firebaseui-auth-container', { + signInOptions: [ + { + provider: firebase.auth.EmailAuthProvider.PROVIDER_ID, + requireDisplayName: false + } + ] + }); + // [END auth_fui_start_email_options] +} + +function fuiStartEmailLink() { + var ui = fuiInit(); + // [START auth_fui_start_email_link] + ui.start('#firebaseui-auth-container', { + signInOptions: [ + { + provider: firebase.auth.EmailAuthProvider.PROVIDER_ID, + signInMethod: firebase.auth.EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD + } + ], + // Other config options... + }); + // [END auth_fui_start_email_link] +} + +function fuiEmailLinkResult(uiConfig) { + var ui = fuiInit(); + // [START auth_fui_email_link_result] + // Is there an email link sign-in? + if (ui.isPendingRedirect()) { + ui.start('#firebaseui-auth-container', uiConfig); + } + // This can also be done via: + if (firebase.auth().isSignInWithEmailLink(window.location.href)) { + ui.start('#firebaseui-auth-container', uiConfig); + } + // [END auth_fui_email_link_result] +} + +function fuiStartEmailLinkOptions() { + var ui = fuiInit(); + // [START auth_fui_start_email_link_options] + ui.start('#firebaseui-auth-container', { + signInOptions: [ + { + provider: firebase.auth.EmailAuthProvider.PROVIDER_ID, + signInMethod: firebase.auth.EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD, + // Allow the user the ability to complete sign-in cross device, + // including the mobile apps specified in the ActionCodeSettings + // object below. + forceSameDevice: false, + // Used to define the optional firebase.auth.ActionCodeSettings if + // additional state needs to be passed along request and whether to open + // the link in a mobile app if it is installed. + emailLinkSignIn: () => { + return { + // Additional state showPromo=1234 can be retrieved from URL on + // sign-in completion in signInSuccess callback by checking + // window.location.href. + url: 'https://www.example.com/completeSignIn?showPromo=1234', + // Custom FDL domain. + dynamicLinkDomain: 'example.page.link', + // Always true for email link sign-in. + handleCodeInApp: true, + // Whether to handle link in iOS app if installed. + iOS: { + bundleId: 'com.example.ios' + }, + // Whether to handle link in Android app if opened in an Android + // device. + android: { + packageName: 'com.example.android', + installApp: true, + minimumVersion: '12' + } + }; + } + } + ] + }); + // [END auth_fui_start_email_link_options] +} + +function fuiStartOauth() { + var ui = fuiInit(); + // [START auth_fui_start_oauth] + ui.start('#firebaseui-auth-container', { + signInOptions: [ + // List of OAuth providers supported. + firebase.auth.GoogleAuthProvider.PROVIDER_ID, + firebase.auth.FacebookAuthProvider.PROVIDER_ID, + firebase.auth.TwitterAuthProvider.PROVIDER_ID, + firebase.auth.GithubAuthProvider.PROVIDER_ID + ], + // Other config options... + }); + // [END auth_fui_start_oauth] +} + +function fuiStartOauthOptions() { + var ui = fuiInit(); + // [START auth_fui_start_oauth_options] + ui.start('#firebaseui-auth-container', { + signInOptions: [ + { + provider: firebase.auth.GoogleAuthProvider.PROVIDER_ID, + scopes: [ + 'https://www.googleapis.com/auth/contacts.readonly' + ], + customParameters: { + // Forces account selection even when one account + // is available. + prompt: 'select_account' + } + }, + { + provider: firebase.auth.FacebookAuthProvider.PROVIDER_ID, + scopes: [ + 'public_profile', + 'email', + 'user_likes', + 'user_friends' + ], + customParameters: { + // Forces password re-entry. + auth_type: 'reauthenticate' + } + }, + firebase.auth.TwitterAuthProvider.PROVIDER_ID, // Twitter does not support scopes. + firebase.auth.EmailAuthProvider.PROVIDER_ID // Other providers don't need to be given as object. + ] + }); + // [END auth_fui_start_oauth_options] +} + +function fuiStartPhone() { + var ui = fuiInit(); + // [START auth_fui_start_phone] + ui.start('#firebaseui-auth-container', { + signInOptions: [ + firebase.auth.PhoneAuthProvider.PROVIDER_ID + ], + // Other config options... + }); + // [END auth_fui_start_phone] +} + +function fuiStartPhoneOptions() { + var ui = fuiInit(); + // [START auth_fui_start_phone_options] + ui.start('#firebaseui-auth-container', { + signInOptions: [ + { + provider: firebase.auth.PhoneAuthProvider.PROVIDER_ID, + recaptchaParameters: { + type: 'image', // 'audio' + size: 'normal', // 'invisible' or 'compact' + badge: 'bottomleft' //' bottomright' or 'inline' applies to invisible. + }, + defaultCountry: 'GB', // Set default country to the United Kingdom (+44). + // For prefilling the national number, set defaultNationNumber. + // This will only be observed if only phone Auth provider is used since + // for multiple providers, the NASCAR screen will always render first + // with a 'sign in with phone number' button. + defaultNationalNumber: '1234567890', + // You can also pass the full phone number string instead of the + // 'defaultCountry' and 'defaultNationalNumber'. However, in this case, + // the first country ID that matches the country code will be used to + // populate the country selector. So for countries that share the same + // country code, the selected country may not be the expected one. + // In that case, pass the 'defaultCountry' instead to ensure the exact + // country is selected. The 'defaultCountry' and 'defaultNationaNumber' + // will always have higher priority than 'loginHint' which will be ignored + // in their favor. In this case, the default country will be 'GB' even + // though 'loginHint' specified the country code as '+1'. + loginHint: '+11234567890' + } + ] + }); + // [END auth_fui_start_phone_options] +} + +function fuiConfig() { + // [START auth_fui_config] + var uiConfig = { + callbacks: { + signInSuccessWithAuthResult: function(authResult, redirectUrl) { + // User successfully signed in. + // Return type determines whether we continue the redirect automatically + // or whether we leave that to developer to handle. + return true; + }, + uiShown: function() { + // The widget is rendered. + // Hide the loader. + document.getElementById('loader').style.display = 'none'; + } + }, + // Will use popup for IDP Providers sign-in flow instead of the default, redirect. + signInFlow: 'popup', + signInSuccessUrl: '', + signInOptions: [ + // Leave the lines as is for the providers you want to offer your users. + firebase.auth.GoogleAuthProvider.PROVIDER_ID, + firebase.auth.FacebookAuthProvider.PROVIDER_ID, + firebase.auth.TwitterAuthProvider.PROVIDER_ID, + firebase.auth.GithubAuthProvider.PROVIDER_ID, + firebase.auth.EmailAuthProvider.PROVIDER_ID, + firebase.auth.PhoneAuthProvider.PROVIDER_ID + ], + // Terms of service url. + tosUrl: '', + // Privacy policy url. + privacyPolicyUrl: '' + }; + // [END auth_fui_config] +} + +function fuiConfigStart(uiConfig) { + var ui = fuiInit(); + // [START auth_fui_config_start] + ui.start('#firebaseui-auth-container', uiConfig); + // [END auth_fui_config_start] +} + +function fuiHandleAnonymous() { + var ui = fuiInit(); + // [START auth_fui_handle_anonymous] + // Temp variable to hold the anonymous user data if needed. + var data = null; + // Hold a reference to the anonymous current user. + var anonymousUser = firebase.auth().currentUser; + ui.start('#firebaseui-auth-container', { + // Whether to upgrade anonymous users should be explicitly provided. + // The user must already be signed in anonymously before FirebaseUI is + // rendered. + autoUpgradeAnonymousUsers: true, + signInSuccessUrl: '', + signInOptions: [ + firebase.auth.GoogleAuthProvider.PROVIDER_ID, + firebase.auth.FacebookAuthProvider.PROVIDER_ID, + firebase.auth.EmailAuthProvider.PROVIDER_ID, + firebase.auth.PhoneAuthProvider.PROVIDER_ID + ], + callbacks: { + // signInFailure callback must be provided to handle merge conflicts which + // occur when an existing credential is linked to an anonymous user. + signInFailure: (error) => { + // For merge conflicts, the error.code will be + // 'firebaseui/anonymous-upgrade-merge-conflict'. + if (error.code != 'firebaseui/anonymous-upgrade-merge-conflict') { + return Promise.resolve(); + } + // The credential the user tried to sign in with. + var cred = error.credential; + // Copy data from anonymous user to permanent user and delete anonymous + // user. + // ... + // Finish sign-in after data is copied. + return firebase.auth().signInWithCredential(cred).then(() => { + return; + }); + } + } + }); + // [END auth_fui_handle_anonymous] +} diff --git a/auth/package.json b/auth/package.json index e0eabb63..245fb7b2 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,6 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.0.1" + "firebase": "^8.0.1", + "firebaseui": "^4.7.1" } } From 5c7b8318df67dda22e4c4523657df42189e1dec9 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 12 Nov 2020 15:55:06 +0000 Subject: [PATCH 026/235] Google, Microsoft, Yahoo, Svc Worker --- auth/google-signin.js | 26 +++++ auth/microsoft-oauth.js | 128 +++++++++++++++++++++++++ auth/service-worker-sessions.js | 164 ++++++++++++++++++++++++++++++++ auth/yahoo-oauth.js | 118 +++++++++++++++++++++++ tsconfig.json.template | 2 +- 5 files changed, 437 insertions(+), 1 deletion(-) create mode 100644 auth/google-signin.js create mode 100644 auth/microsoft-oauth.js create mode 100644 auth/service-worker-sessions.js create mode 100644 auth/yahoo-oauth.js diff --git a/auth/google-signin.js b/auth/google-signin.js new file mode 100644 index 00000000..3b8240cf --- /dev/null +++ b/auth/google-signin.js @@ -0,0 +1,26 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/google-signin.md + +function googleBuildAndSignIn(id_token) { + // [START auth_google_build_signin] + // Build Firebase credential with the Google ID token. + var credential = firebase.auth.GoogleAuthProvider.credential(id_token); + + // Sign in with credential from the Google user. + firebase.auth().signInWithCredential(credential).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + // [END auth_google_build_signin] +} diff --git a/auth/microsoft-oauth.js b/auth/microsoft-oauth.js new file mode 100644 index 00000000..32d83156 --- /dev/null +++ b/auth/microsoft-oauth.js @@ -0,0 +1,128 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/microsoft-oauth.md + +function msftCreateProvider() { + // [START auth_msft_create_provider] + var provider = new firebase.auth.OAuthProvider('microsoft.com'); + // [END auth_msft_create_provider] + + return provider; +} + +function msftProviderParams() { + var provider = msftCreateProvider(); + // [START auth_msft_provider_params] + provider.setCustomParameters({ + // Force re-consent. + prompt: 'consent', + // Target specific email with login hint. + login_hint: 'user@firstadd.onmicrosoft.com' + }); + // [END auth_msft_provider_params] +} + +function msftProviderParamsTenant() { + var provider = msftCreateProvider(); + // [START auth_msft_provider_params_tenant] + provider.setCustomParameters({ + // Optional "tenant" parameter in case you are using an Azure AD tenant. + // eg. '8eaef023-2b34-4da1-9baa-8bc8c9d6a490' or 'contoso.onmicrosoft.com' + // or "common" for tenant-independent tokens. + // The default value is "common". + tenant: 'TENANT_ID' + }); + // [END auth_msft_provider_params_tenant] +} + +function msftProviderScopes() { + var provider = msftCreateProvider(); + // [START auth_msft_provider_scopes + provider.addScope('mail.read'); + provider.addScope('calendars.read'); + // [END auth_msft_provider_scopes +} + +function msftSigninPopup() { + var provider = msftCreateProvider(); + // [START auth_msft_signin_popup] + firebase.auth().signInWithPopup(provider) + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + // OAuth access token can also be retrieved: + // result.credential.accessToken + // OAuth ID token can also be retrieved: + // result.credential.idToken + }) + .catch((error) => { + // Handle error. + }); + // [END auth_msft_signin_popup] +} + +function msftSignInRedirect() { + var provider = msftCreateProvider(); + // [START auth_msft_signin_redirect] + firebase.auth().signInWithRedirect(provider); + // [END auth_msft_signin_redirect] +} + +function msftRedirectResult() { + // [START auth_msf_redirect_result] + firebase.auth().getRedirectResult() + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + // OAuth access token can also be retrieved: + // result.credential.accessToken + // OAuth ID token can also be retrieved: + // result.credential.idToken + }) + .catch((error) => { + // Handle error. + }); + // [END auth_msf_redirect_result] +} + +function msftLinkWithPopup() { + // [START auth_msft_link_popup] + var provider = new firebase.auth.OAuthProvider('microsoft.com'); + firebase.auth().currentUser.linkWithPopup(provider) + .then((result) => { + // Microsoft credential is linked to the current user. + // IdP data available in result.additionalUserInfo.profile. + // OAuth access token can also be retrieved: + // result.credential.accessToken + // OAuth ID token can also be retrieved: + // result.credential.idToken + }) + .catch((error) => { + // Handle error. + }); + // [END auth_msft_link_popup] +} + +function msftReauthPopup() { + // [START auth_msft_reauth_popup] + var provider = new firebase.auth.OAuthProvider('microsoft.com'); + firebase.auth().currentUser.reauthenticateWithPopup(provider) + .then((result) => { + // User is re-authenticated with fresh tokens minted and + // should be able to perform sensitive operations like account + // deletion and email or password update. + // IdP data available in result.additionalUserInfo.profile. + // OAuth access token can also be retrieved: + // result.credential.accessToken + // OAuth ID token can also be retrieved: + // result.credential.idToken + }) + .catch((error) => { + // Handle error. + }); + // [END auth_msft_reauth_popup] +} diff --git a/auth/service-worker-sessions.js b/auth/service-worker-sessions.js new file mode 100644 index 00000000..b151374c --- /dev/null +++ b/auth/service-worker-sessions.js @@ -0,0 +1,164 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/service-worker-sessions.md + +function svcGetIdToken() { + // [START auth_svc_get_idtoken] + firebase.auth().currentUser.getIdToken() + .then((idToken) => { + // idToken can be passed back to server. + }) + .catch((error) => { + // Error occurred. + }); + // [END auth_svc_get_idtoken] +} + +function svcSubscribe(config) { + // [START auth_svc_subscribe] + // Initialize the Firebase app in the service worker script. + firebase.initializeApp(config); + + /** + * Returns a promise that resolves with an ID token if available. + * @return {!Promise} The promise that resolves with an ID token if + * available. Otherwise, the promise resolves with null. + */ + const getIdToken = () => { + return new Promise((resolve, reject) => { + const unsubscribe = firebase.auth().onAuthStateChanged((user) => { + unsubscribe(); + if (user) { + user.getIdToken().then((idToken) => { + resolve(idToken); + }, (error) => { + resolve(null); + }); + } else { + resolve(null); + } + }); + }); + }; + // [END auth_svc_subscribe] +} + +function svcIntercept() { + // See above + function getIdToken() { + return Promise.resolve("id-token"); + } + + // [START auth_svc_intercept] + const getOriginFromUrl = (url) => { + // https://stackoverflow.com/questions/1420881/how-to-extract-base-url-from-a-string-in-javascript + const pathArray = url.split('/'); + const protocol = pathArray[0]; + const host = pathArray[2]; + return protocol + '//' + host; + }; + + // Get underlying body if available. Works for text and json bodies. + const getBodyContent = (req) => { + return Promise.resolve().then(() => { + if (req.method !== 'GET') { + if (req.headers.get('Content-Type').indexOf('json') !== -1) { + return req.json() + .then((json) => { + return JSON.stringify(json); + }); + } else { + return req.text(); + } + } + }).catch((error) => { + // Ignore error. + }); + }; + + self.addEventListener('fetch', (event) => { + /** @type {FetchEvent} */ + let evt = event; + + const requestProcessor = (idToken) => { + let req = evt.request; + let processRequestPromise = Promise.resolve(); + // For same origin https requests, append idToken to header. + if (self.location.origin == getOriginFromUrl(evt.request.url) && + (self.location.protocol == 'https:' || + self.location.hostname == 'localhost') && + idToken) { + // Clone headers as request headers are immutable. + const headers = new Headers(); + req.headers.forEach((val, key) => { + headers.append(key, val); + }) + // Add ID token to header. + headers.append('Authorization', 'Bearer ' + idToken); + processRequestPromise = getBodyContent(req).then((body) => { + try { + req = new Request(req.url, { + method: req.method, + headers: headers, + mode: 'same-origin', + credentials: req.credentials, + cache: req.cache, + redirect: req.redirect, + referrer: req.referrer, + body, + // bodyUsed: req.bodyUsed, + // context: req.context + }); + } catch (e) { + // This will fail for CORS requests. We just continue with the + // fetch caching logic below and do not pass the ID token. + } + }); + } + return processRequestPromise.then(() => { + return fetch(req); + }); + }; + // Fetch the resource after checking for the ID token. + // This can also be integrated with existing logic to serve cached files + // in offline mode. + evt.respondWith(getIdToken().then(requestProcessor, requestProcessor)); + }); + // [END auth_svc_intercept] +} + +function svcListenActivate(clients) { + // [START auth_svc_listen_activate] + self.addEventListener('activate', event => { + event.waitUntil(clients.claim()); + }); + // [END auth_svc_listen_activate] +} + +function svcRegister() { + // [START auth_svc_register] + // Install servicerWorker if supported on sign-in/sign-up page. + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/service-worker.js', {scope: '/'}); + } + // [END auth_svc_register] +} + +function svcSignInEmail(email, password) { + // [START auth_svc_sign_in_email] + // Sign in screen. + firebase.auth().signInWithEmailAndPassword(email, password) + .then((result) => { + // Redirect to profile page after sign-in. The service worker will detect + // this and append the ID token to the header. + window.location.assign('/profile'); + }) + .catch((error) => { + // Error occurred. + }); + // [END auth_svc_sign_in_email] +} diff --git a/auth/yahoo-oauth.js b/auth/yahoo-oauth.js new file mode 100644 index 00000000..f7ae147f --- /dev/null +++ b/auth/yahoo-oauth.js @@ -0,0 +1,118 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/yahoo-oauth.md + +function yahooCreateProvider() { + // [START auth_yahoo_create_provider] + var provider = new firebase.auth.OAuthProvider('yahoo.com'); + // [END auth_yahoo_create_provider] + + return provider; +} + +function yahooCreateProviderParams() { + var provider = yahooCreateProvider(); + // [START auth_yahoo_create_provider_params] + provider.setCustomParameters({ + // Prompt user to re-authenticate to Yahoo. + prompt: 'login', + // Localize to French. + language: 'fr' + }); + // [END auth_yahoo_create_provider_params] +} + +function yahooCreateProviderScopes() { + var provider = yahooCreateProvider(); + // [START auth_yahoo_create_provider_scopes] + // Request access to Yahoo Mail API. + provider.addScope('mail-r'); + // Request read/write access to user contacts. + // This must be preconfigured in the app's API permissions. + provider.addScope('sdct-w'); + // [END auth_yahoo_create_provider_scopes] +} + +function yahooSignInPopup() { + var provider = yahooCreateProvider(); + // [START auth_yahoo_signin_popup] + firebase.auth().signInWithPopup(provider) + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + // Yahoo OAuth access token can be retrieved by calling: + // result.credential.accessToken + // Yahoo OAuth ID token can be retrieved by calling: + // result.credential.idToken + }) + .catch((error) => { + // Handle error. + }); + // [END auth_yahoo_signin_popup] +} + +function yahooSignInRedirect() { + var provider = yahooCreateProvider(); + // [START auth_yahoo_signin_redirect] + firebase.auth().signInWithRedirect(provider); + // [END auth_yahoo_signin_redirect] +} + +function yahooRedirectResult() { + // [START auth_yahoo_redirect_result] + firebase.auth().getRedirectResult() + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + // Yahoo OAuth access token can be retrieved by calling: + // result.credential.accessToken + // Yahoo OAuth ID token can be retrieved by calling: + // result.credential.idToken + }) + .catch((error) => { + // Handle error. + }); + // [END auth_yahoo_redirect_result] +} + +function yahooLinkPopup() { + // [START auth_yahoo_link_popup] + var provider = new firebase.auth.OAuthProvider('yahoo.com'); + firebase.auth().currentUser.linkWithPopup(provider) + .then((result) => { + // Yahoo credential is linked to the current user. + // IdP data available in result.additionalUserInfo.profile. + // Yahoo OAuth access token can be retrieved by calling: + // result.credential.accessToken + // Yahoo OAuth ID token can be retrieved by calling: + // result.credential.idToken + }) + .catch((error) => { + // Handle error. + }); + // [END auth_yahoo_link_popup] +} + +function yahooReauthPopup() { + // [START auth_yahoo_reauth_popup] + var provider = new firebase.auth.OAuthProvider('yahoo.com'); + firebase.auth().currentUser.reauthenticateWithPopup(provider) + .then((result) => { + // User is re-authenticated with fresh tokens minted and + // should be able to perform sensitive operations like account + // deletion and email or password update. + // IdP data available in result.additionalUserInfo.profile. + // Yahoo OAuth access token can be retrieved by calling: + // result.credential.accessToken + // Yahoo OAuth ID token can be retrieved by calling: + // result.credential.idToken + }) + .catch((error) => { + // Handle error. + }); + // [END auth_yahoo_reauth_popup] +} diff --git a/tsconfig.json.template b/tsconfig.json.template index 072197f8..1ac5b948 100644 --- a/tsconfig.json.template +++ b/tsconfig.json.template @@ -3,7 +3,7 @@ /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ - "lib": ["dom"], /* Specify library files to be included in the compilation. */ + "lib": ["dom", "webworker"], /* Specify library files to be included in the compilation. */ "allowJs": true, /* Allow javascript files to be compiled. */ "checkJs": true, /* Report errors in .js files. */ "outDir": "./dist", /* Redirect output structure to the directory. */ From 4608687e712662b887272ab1a6bcc2becf0f44c9 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 12 Nov 2020 16:06:31 +0000 Subject: [PATCH 027/235] Make compile pass --- tsconfig.json.template | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tsconfig.json.template b/tsconfig.json.template index 1ac5b948..9b4a631b 100644 --- a/tsconfig.json.template +++ b/tsconfig.json.template @@ -12,7 +12,6 @@ "typeRoots": [ "./node_modules/@types" ], - /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ @@ -23,6 +22,9 @@ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + // See: https://github.com/microsoft/TypeScript/issues/20595 + "skipLibCheck": true, + /* Additional Checks */ "noUnusedLocals": false, /* Report errors on unused locals. */ // "noUnusedParameters": true, /* Report errors on unused parameters. */ From 78ad27046828437d1cf33a609a2baf788084873a Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 13 Nov 2020 02:18:50 -0800 Subject: [PATCH 028/235] Auto-update dependencies. (#55) --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/auth/package.json b/auth/package.json index 245fb7b2..d044395e 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.0.1", + "firebase": "^8.0.2", "firebaseui": "^4.7.1" } } diff --git a/database/package.json b/database/package.json index 02dc1df8..ea6dd1d3 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.0.1" + "firebase": "^8.0.2" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 12dbc583..6a95f21c 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.0.1" + "firebase": "^8.0.2" } } diff --git a/firestore/package.json b/firestore/package.json index 0ff20653..4dc24997 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.0.1" + "firebase": "^8.0.2" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/functions/package.json b/functions/package.json index 616fbc2a..d8fffd5d 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.0.1" + "firebase": "^8.0.2" } } diff --git a/installations/package.json b/installations/package.json index d16cdfbe..f31413ef 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.0.1" + "firebase": "^8.0.2" } } From 31690d55b7a1a864595c7c0fb09647defca7fe7b Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 13 Nov 2020 05:47:50 -0800 Subject: [PATCH 029/235] Auto-update dependencies. (#56) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 345f2291..91d0cc0a 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From cfd50b294ae4ef56b56953df2fcff54c8f25d9f6 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 13 Nov 2020 10:21:01 -0500 Subject: [PATCH 030/235] Move auth snippets from quickstart-js (#57) --- auth/anonymous.js | 19 ++++++++++++ auth/custom.js | 21 ++++++++++++++ auth/email-link-auth.js | 5 +++- auth/email.js | 64 +++++++++++++++++++++++++++++++++++++++++ auth/facebook.js | 55 +++++++++++++++++++++++++++++++++++ auth/index.js | 22 ++++++++++++-- 6 files changed, 182 insertions(+), 4 deletions(-) create mode 100644 auth/anonymous.js create mode 100644 auth/custom.js create mode 100644 auth/email.js create mode 100644 auth/facebook.js diff --git a/auth/anonymous.js b/auth/anonymous.js new file mode 100644 index 00000000..42d817dc --- /dev/null +++ b/auth/anonymous.js @@ -0,0 +1,19 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +function anonSignIn() { + // [START auth_anon_sign_in] + firebase.auth().signInAnonymously() + .then(() => { + // Signed in.. + }) + .catch((error) => { + var errorCode = error.code; + var errorMessage = error.message; + // ... + }) + // [END auth_anon_sign_in] +} diff --git a/auth/custom.js b/auth/custom.js new file mode 100644 index 00000000..1d1a6037 --- /dev/null +++ b/auth/custom.js @@ -0,0 +1,21 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +function signInCustom() { + var token = "token123"; + // [START auth_sign_in_custom] + firebase.auth().signInWithCustomToken(token) + .then((user) => { + // Signed in + // ... + }) + .catch((error) => { + var errorCode = error.code; + var errorMessage = error.message; + // ... + }) + // [END auth_sign_in_custom] +} diff --git a/auth/email-link-auth.js b/auth/email-link-auth.js index d008a0cf..ce1e22ec 100644 --- a/auth/email-link-auth.js +++ b/auth/email-link-auth.js @@ -35,9 +35,12 @@ function emailLinkSend(email, actionCodeSettings) { // Save the email locally so you don't need to ask the user for it again // if they open the link on the same device. window.localStorage.setItem('emailForSignIn', email); + // ... }) .catch((error) => { - // Some error occurred, you can inspect the code: error.code + var errorCode = error.code; + var errorMessage = error.message; + // ... }); // [END auth_email_link_send] } diff --git a/auth/email.js b/auth/email.js new file mode 100644 index 00000000..ba919819 --- /dev/null +++ b/auth/email.js @@ -0,0 +1,64 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +function signInWithEmailPassword() { + var email = "test@example.com"; + var password = "hunter2"; + // [START auth_signin_password] + firebase.auth().signInWithEmailAndPassword(email, password) + .then((user) => { + // Signed in + // ... + }) + .catch((error) => { + var errorCode = error.code; + var errorMessage = error.message; + }); + // [END auth_signin_password] +} + +function signUpWithEmailPasswoerd() { + var email = "test@example.com"; + var password = "hunter2"; + // [START auth_signup_password] + firebase.auth().createUserWithEmailAndPassword(email, password) + .then((user) => { + // Signed in + // ... + }) + .catch((error) => { + var errorCode = error.code; + var errorMessage = error.message; + // .. + }); + // [END auth_signup_password] +} + +function sendEmailVerification() { + // [START auth_send_email_verification] + firebase.auth().currentUser.sendEmailVerification() + .then(() => { + // Email verification sent! + // ... + }); + // [END auth_send_email_verification] +} + +function sendPasswordReset() { + const email = "sam@example.com"; + // [START auth_send_password_reset] + firebase.auth().sendPasswordResetEmail(email) + .then(() => { + // Password reset email sent! + // .. + }) + .catch((error) => { + var errorCode = error.code; + var errorMessage = error.message; + // .. + }); + // [END auth_send_password_reset] +} diff --git a/auth/facebook.js b/auth/facebook.js new file mode 100644 index 00000000..4a1fd5ef --- /dev/null +++ b/auth/facebook.js @@ -0,0 +1,55 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// [START auth_facebook_callback] +function checkLoginState(response) { + if (response.authResponse) { + // User is signed-in Facebook. + var unsubscribe = firebase.auth().onAuthStateChanged((firebaseUser) => { + unsubscribe(); + // Check if we are already signed-in Firebase with the correct user. + if (!isUserEqual(response.authResponse, firebaseUser)) { + // Build Firebase credential with the Facebook auth token. + var credential = firebase.auth.FacebookAuthProvider.credential( + response.authResponse.accessToken); + + // Sign in with the credential from the Facebook user. + firebase.auth().signInWithCredential(credential).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + } else { + // User is already signed-in Firebase with the correct user. + } + }); + } else { + // User is signed-out of Facebook. + firebase.auth().signOut(); + } +} +// [END auth_facebook_callback] + +// [START auth_facebook_checksameuser] +function isUserEqual(facebookAuthResponse, firebaseUser) { + if (firebaseUser) { + var providerData = firebaseUser.providerData; + for (var i = 0; i < providerData.length; i++) { + if (providerData[i].providerId === firebase.auth.FacebookAuthProvider.PROVIDER_ID && + providerData[i].uid === facebookAuthResponse.userID) { + // We don't need to re-auth the Firebase connection. + return true; + } + } + } + return false; +} +// [END auth_facebook_checksameuser] diff --git a/auth/index.js b/auth/index.js index a1c9fb6b..d57d704f 100644 --- a/auth/index.js +++ b/auth/index.js @@ -4,7 +4,9 @@ import firebase from "firebase/app"; import "firebase/auth"; -// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/_includes/_get_credentials_web.html +// ========================================================================================== +// Docs: Snippets in this file are "general purpose" and are used on more than one docs page +// ========================================================================================== function makeGoogleCredential(googleUser) { // [START auth_make_google_credential] @@ -26,8 +28,6 @@ function makeEmailCredential(email, password) { // [END auth_make_email_credential] } -// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/_includes/_next_steps_web.html - function signOut() { // [START auth_sign_out] firebase.auth().signOut().then(() => { @@ -37,3 +37,19 @@ function signOut() { }); // [END auth_sign_out] } + +function authStateListener() { + // [START auth_state_listener] + firebase.auth().onAuthStateChanged((user) => { + if (user) { + // User is signed in, see docs for a list of available properties + // https://firebase.google.com/docs/reference/js/firebase.User + var uid = user.uid; + // ... + } else { + // User is signed out + // ... + } + }); + // [END auth_state_listener] +} From 332805235fc4d94e241fe0b4aba3b7afab16acd0 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 13 Nov 2020 10:50:59 -0500 Subject: [PATCH 031/235] Bring in some move auth snippets (#58) --- auth/facebook.js | 44 ++++++++++++++++++++++++++++++--------- auth/google-signin.js | 48 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 10 deletions(-) diff --git a/auth/facebook.js b/auth/facebook.js index 4a1fd5ef..b94cdcd9 100644 --- a/auth/facebook.js +++ b/auth/facebook.js @@ -16,17 +16,20 @@ function checkLoginState(response) { var credential = firebase.auth.FacebookAuthProvider.credential( response.authResponse.accessToken); + // [START auth_facebook_signin_credential] // Sign in with the credential from the Facebook user. - firebase.auth().signInWithCredential(credential).catch((error) => { - // Handle Errors here. - var errorCode = error.code; - var errorMessage = error.message; - // The email of the user's account used. - var email = error.email; - // The firebase.auth.AuthCredential type that was used. - var credential = error.credential; - // ... - }); + firebase.auth().signInWithCredential(credential) + .catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + // [END auth_facebook_signin_credential] } else { // User is already signed-in Firebase with the correct user. } @@ -53,3 +56,24 @@ function isUserEqual(facebookAuthResponse, firebaseUser) { return false; } // [END auth_facebook_checksameuser] + +function authWithCredential(credential) { + // [START auth_facebook_signin_credential] + // Sign in with the credential from the Facebook user. + firebase.auth().signInWithCredential(credential) + .then((cred) => { + // Signed in + // ... + }) + .catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + // [END auth_facebook_signin_credential] +} diff --git a/auth/google-signin.js b/auth/google-signin.js index 3b8240cf..3323d2a5 100644 --- a/auth/google-signin.js +++ b/auth/google-signin.js @@ -24,3 +24,51 @@ function googleBuildAndSignIn(id_token) { }); // [END auth_google_build_signin] } + +// [START auth_google_callback] +function onSignIn(googleUser) { + console.log('Google Auth Response', googleUser); + // We need to register an Observer on Firebase Auth to make sure auth is initialized. + var unsubscribe = firebase.auth().onAuthStateChanged((firebaseUser) => { + unsubscribe(); + // Check if we are already signed-in Firebase with the correct user. + if (!isUserEqual(googleUser, firebaseUser)) { + // Build Firebase credential with the Google ID token. + var credential = firebase.auth.GoogleAuthProvider.credential( + googleUser.getAuthResponse().id_token); + + // Sign in with credential from the Google user. + // [START auth_google_signin_credential] + firebase.auth().signInWithCredential(credential).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + // [END auth_google_signin_credential] + } else { + console.log('User already signed-in Firebase.'); + } + }); +} +// [END auth_google_callback] + +// [START auth_google_checksameuser] +function isUserEqual(googleUser, firebaseUser) { + if (firebaseUser) { + var providerData = firebaseUser.providerData; + for (var i = 0; i < providerData.length; i++) { + if (providerData[i].providerId === firebase.auth.GoogleAuthProvider.PROVIDER_ID && + providerData[i].uid === googleUser.getBasicProfile().getId()) { + // We don't need to reauth the Firebase connection. + return true; + } + } + } + return false; +} +// [END auth_google_checksameuser] From 52b0c205d9707138c0fa1673d07110e60be426ec Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 13 Nov 2020 15:57:55 +0000 Subject: [PATCH 032/235] One line fix --- auth/facebook.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/facebook.js b/auth/facebook.js index b94cdcd9..b7a055b0 100644 --- a/auth/facebook.js +++ b/auth/facebook.js @@ -16,8 +16,8 @@ function checkLoginState(response) { var credential = firebase.auth.FacebookAuthProvider.credential( response.authResponse.accessToken); - // [START auth_facebook_signin_credential] // Sign in with the credential from the Facebook user. + // [START auth_facebook_signin_credential] firebase.auth().signInWithCredential(credential) .catch((error) => { // Handle Errors here. From 1bb200eaf712ea73639f87cb8b2c8902189be50c Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 16 Nov 2020 06:32:51 -0500 Subject: [PATCH 033/235] Add snippets for Firestore geoqueries (#52) --- firestore-next/package.json | 3 +- firestore-next/test.solution-geoqueries.js | 100 +++++++++++++++++ firestore/package.json | 3 +- firestore/test.solution-geoqueries.js | 103 ++++++++++++++++++ .../fs_geo_add_hash.js | 22 ++++ .../fs_geo_query_hashes.js | 45 ++++++++ 6 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 firestore-next/test.solution-geoqueries.js create mode 100644 firestore/test.solution-geoqueries.js create mode 100644 snippets/firestore-next/test-solution-geoqueries/fs_geo_add_hash.js create mode 100644 snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js diff --git a/firestore-next/package.json b/firestore-next/package.json index 9537996c..8289e346 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,8 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp" + "firebase": "exp", + "geofire-common": "^5.1.0" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/firestore-next/test.solution-geoqueries.js b/firestore-next/test.solution-geoqueries.js new file mode 100644 index 00000000..68380b2a --- /dev/null +++ b/firestore-next/test.solution-geoqueries.js @@ -0,0 +1,100 @@ +// [SNIPPETS_SEPARATION enabled] +const { FirebaseFirestore } = require('firebase/firestore'); + +const geofire = require('geofire-common'); + +/** @type {FirebaseFirestore} */ +let db; + +async function addHash(done) { + // [START fs_geo_add_hash] + const { doc, updateDoc } = require('firebase/firestore'); + + // Compute the GeoHash for a lat/lng point + const lat = 51.5074; + const lng = 0.1278; + const hash = geofire.geohashForLocation([lat, lng]); + + // Add the hash and the lat/lng to the document. We will use the hash + // for queries and the lat/lng for distance comparisons. + const londonRef = doc(db, 'cities', 'LON'); + await updateDoc(londonRef, { + geohash: hash, + lat: lat, + lng: lng + }); + // [END fs_geo_add_hash] + done(); +} + +async function queryHashes(done) { + // [START fs_geo_query_hashes] + const { collection, query, orderBy, startAt, endAt, getDocs } = require('firebase/firestore'); + + // Find cities within 50km of London + const center = [51.5074, 0.1278]; + const radiusInKm = 50; + + // Each item in 'bounds' represents a startAt/endAt pair. We have to issue + // a separate query for each pair. There can be up to 9 pais of bounds + // depending on overlap, but in most cases there are 4. + const bounds = geofire.geohashQueryBounds(center, radiusInKm); + const promises = []; + for (const b of bounds) { + const q = query( + collection(db, 'cities'), + orderBy('geohash'), + startAt(b[0]), + endAt(b[1])); + + promises.push(getDocs(q)); + } + + // Collect all the query results together into a single list + const snapshots = await Promise.all(promises); + + const matchingDocs = []; + for (const snap of snapshots) { + for (const doc of snap.docs) { + const lat = doc.get('lat'); + const lng = doc.get('lng'); + + // We have to filter out a few false positives due to GeoHash + // accuracy, but most will match + const distance = geofire.distanceBetween([lat, lng], center); + if (distance <= radiusInKm) { + matchingDocs.push(doc); + } + } + } + // [END fs_geo_query_hashes] + done(matchingDocs); +} + +describe("firestore-solution-geoqueries", () => { + before(() => { + const { initializeApp } = require("firebase/app"); + const { getFirestore} = require("firebase/firestore"); + + const config = { + apiKey: "AIzaSyArvVh6VSdXicubcvIyuB-GZs8ua0m0DTI", + authDomain: "firestorequickstarts.firebaseapp.com", + projectId: "firestorequickstarts", + }; + const app = initializeApp(config, "solution-geoqueries"); + db = getFirestore(app); + }); + + describe("solution-geoqueries", () => { + it("should add a hash to a doc", (done) => { + addHash(done) + }); + + it("should query hashes", (done) => { + queryHashes(done); + }); + }); +}); + + + diff --git a/firestore/package.json b/firestore/package.json index 4dc24997..54a49bd4 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,8 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.0.2" + "firebase": "^8.0.2", + "geofire-common": "^5.1.0" }, "devDependencies": { "@types/chai": "^4.2.12", diff --git a/firestore/test.solution-geoqueries.js b/firestore/test.solution-geoqueries.js new file mode 100644 index 00000000..73465b84 --- /dev/null +++ b/firestore/test.solution-geoqueries.js @@ -0,0 +1,103 @@ +import firebase from 'firebase/app'; +import 'firebase/firestore'; + +const geofire = require('geofire-common'); + +/** + * @type firebase.firestore.Firestore + */ +var db; + +function addHash(done) { + // [START fs_geo_add_hash] + + // Compute the GeoHash for a lat/lng point + const lat = 51.5074; + const lng = 0.1278; + const hash = geofire.geohashForLocation([lat, lng]); + + // Add the h and the lat/lng to the document. We will use the hash + // for queries and the lat/lng for distance comparisons. + const londonRef = db.collection('cities').doc('LON'); + londonRef.update({ + geohash: hash, + lat: lat, + lng: lng + }).then(() => { + // [START_EXCLUDE] + done(); + // [END_EXCLUDE] + }); + // [END fs_geo_add_hash] +} + +function queryHashes(done) { + // [START fs_geo_query_hashes] + // Find cities within 50km of London + const center = [51.5074, 0.1278]; + const radiusInKm = 50; + + // Each item in 'bounds' represents a startAt/endAt pair. We have to issue + // a separate query for each pair. There can be up to 9 pais of bounds + // depending on overlap, but in most cases there are 4. + const bounds = geofire.geohashQueryBounds(center, radiusInKm); + const promises = []; + for (const b of bounds) { + const q = db.collection('cities') + .orderBy('geohash') + .startAt(b[0]) + .endAt(b[1]); + + promises.push(q.get()); + } + + // Collect all the query results together into a single list + Promise.all(promises).then((snapshots) => { + const matchingDocs = []; + + for (const snap of snapshots) { + for (const doc of snap.docs) { + const lat = doc.get('lat'); + const lng = doc.get('lng'); + + // We have to filter out a few false positives due to GeoHash + // accuracy, but most will match + const distance = geofire.distanceBetween([lat, lng], center); + if (distance <= radiusInKm) { + matchingDocs.push(doc); + } + } + } + + return matchingDocs; + }).then((matchingDocs) => { + // Process the matching documents + // [START_EXCLUDE] + done(matchingDocs); + // [END_EXCLUDE] + }) + + // [END fs_geo_query_hashes] +} + +describe("firestore-solution-geoqueries", () => { + before(() => { + var config = { + apiKey: "AIzaSyArvVh6VSdXicubcvIyuB-GZs8ua0m0DTI", + authDomain: "firestorequickstarts.firebaseapp.com", + projectId: "firestorequickstarts", + }; + var app = firebase.initializeApp(config, "solution-geoqueries"); + db = firebase.firestore(app); + }); + + describe("solution-geoqueries", () => { + it("should add a hash to a doc", (done) => { + addHash(done) + }); + + it("should query hashes", (done) => { + queryHashes(done); + }); + }); +}); diff --git a/snippets/firestore-next/test-solution-geoqueries/fs_geo_add_hash.js b/snippets/firestore-next/test-solution-geoqueries/fs_geo_add_hash.js new file mode 100644 index 00000000..f50ab477 --- /dev/null +++ b/snippets/firestore-next/test-solution-geoqueries/fs_geo_add_hash.js @@ -0,0 +1,22 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-geoqueries.js +// +// To make edits to the snippets in this file, please edit the source + +// [START fs_geo_add_hash_modular] +import { doc, updateDoc } from 'firebase/firestore'; + +// Compute the GeoHash for a lat/lng point +const lat = 51.5074; +const lng = 0.1278; +const hash = geofire.geohashForLocation([lat, lng]); + +// Add the hash and the lat/lng to the document. We will use the hash +// for queries and the lat/lng for distance comparisons. +const londonRef = doc(db, 'cities', 'LON'); +await updateDoc(londonRef, { + geohash: hash, + lat: lat, + lng: lng +}); +// [END fs_geo_add_hash_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js b/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js new file mode 100644 index 00000000..2de46c75 --- /dev/null +++ b/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js @@ -0,0 +1,45 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-geoqueries.js +// +// To make edits to the snippets in this file, please edit the source + +// [START fs_geo_query_hashes_modular] +import { collection, query, orderBy, startAt, endAt, getDocs } from 'firebase/firestore'; + +// Find cities within 50km of London +const center = [51.5074, 0.1278]; +const radiusInKm = 50; + +// Each item in 'bounds' represents a startAt/endAt pair. We have to issue +// a separate query for each pair. There can be up to 9 pais of bounds +// depending on overlap, but in most cases there are 4. +const bounds = geofire.geohashQueryBounds(center, radiusInKm); +const promises = []; +for (const b of bounds) { + const q = query( + collection(db, 'cities'), + orderBy('geohash'), + startAt(b[0]), + endAt(b[1])); + + promises.push(getDocs(q)); +} + +// Collect all the query results together into a single list +const snapshots = await Promise.all(promises); + +const matchingDocs = []; +for (const snap of snapshots) { + for (const doc of snap.docs) { + const lat = doc.get('lat'); + const lng = doc.get('lng'); + + // We have to filter out a few false positives due to GeoHash + // accuracy, but most will match + const distance = geofire.distanceBetween([lat, lng], center); + if (distance <= radiusInKm) { + matchingDocs.push(doc); + } + } +} +// [END fs_geo_query_hashes_modular] \ No newline at end of file From c8949e5a8c5538ec4f2893938399fbb0ed42dd8d Mon Sep 17 00:00:00 2001 From: Arthur Thompson Date: Thu, 19 Nov 2020 14:27:23 -0800 Subject: [PATCH 034/235] Fix include tag typo Tag had no END tag. This fixes the typo. --- installations/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installations/index.js b/installations/index.js index 35daae92..1764ea74 100644 --- a/installations/index.js +++ b/installations/index.js @@ -41,7 +41,7 @@ async function setOnIdChangeHandler() { console.log(newId); // TODO: Handle new installation ID. }); - // [START set_id_change_handler] + // [END set_id_change_handler] } catch (err) { console.error('Unable to set ID change handler: ', err); } From ba9edaf9663a2095852d1351291d9aa222ddfd3a Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 20 Nov 2020 03:11:33 -0800 Subject: [PATCH 035/235] Auto-update dependencies. (#60) --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/auth/package.json b/auth/package.json index d044395e..99355580 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.0.2", + "firebase": "^8.1.1", "firebaseui": "^4.7.1" } } diff --git a/database/package.json b/database/package.json index ea6dd1d3..93824133 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.0.2" + "firebase": "^8.1.1" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 6a95f21c..1dc65cc5 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.0.2" + "firebase": "^8.1.1" } } diff --git a/firestore/package.json b/firestore/package.json index 54a49bd4..3f23ccf4 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.0.2", + "firebase": "^8.1.1", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index d8fffd5d..19e3c427 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.0.2" + "firebase": "^8.1.1" } } diff --git a/installations/package.json b/installations/package.json index f31413ef..a415acce 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.0.2" + "firebase": "^8.1.1" } } From 47bc8cbac220d9eabed10de708a458d7aa209888 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 20 Nov 2020 06:24:50 -0800 Subject: [PATCH 036/235] Auto-update dependencies. (#61) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 91d0cc0a..aa296817 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From 313815829f850e7b3a9613e9e6c372a85472522d Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 20 Nov 2020 10:50:56 -0500 Subject: [PATCH 037/235] Database snippets (#62) --- database/index.js | 11 +++++ database/lists-of-data.js | 65 +++++++++++++++++++++++++++++ database/read-and-write.js | 84 ++++++++++++++++++++++++++++++++++++++ database/sharding.js | 23 +++++++++++ 4 files changed, 183 insertions(+) create mode 100644 database/index.js create mode 100644 database/lists-of-data.js create mode 100644 database/sharding.js diff --git a/database/index.js b/database/index.js new file mode 100644 index 00000000..eb13416e --- /dev/null +++ b/database/index.js @@ -0,0 +1,11 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/database"; + +function getReference() { + // [START rtdb_get_reference] + var database = firebase.database(); + // [END rtdb_get_reference] +} diff --git a/database/lists-of-data.js b/database/lists-of-data.js new file mode 100644 index 00000000..40c6c30a --- /dev/null +++ b/database/lists-of-data.js @@ -0,0 +1,65 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/database"; + +function socialPush() { + // [START rtdb_social_push] + // Create a new post reference with an auto-generated id + var postListRef = firebase.database().ref('posts'); + var newPostRef = postListRef.push(); + newPostRef.set({ + // ... + }); + // [END rtdb_social_push] +} + +function socialListenChildren() { + const postElement = document.querySelector("#post"); + const postId = "1234"; + function addCommentElement(el, key, text, author) {} + function setCommentValues(el, key, text, author) {}; + function deleteComment(el, key) {}; + + // [START rtb_social_listen_children] + var commentsRef = firebase.database().ref('post-comments/' + postId); + commentsRef.on('child_added', (data) => { + addCommentElement(postElement, data.key, data.val().text, data.val().author); + }); + + commentsRef.on('child_changed', (data) => { + setCommentValues(postElement, data.key, data.val().text, data.val().author); + }); + + commentsRef.on('child_removed', (data) => { + deleteComment(postElement, data.key); + }); + // [END rtb_social_listen_children] +} + +function socialListenValue() { + const ref = firebase.database().ref('/a/b/c'); + + // [START rtdb_social_listen_value] + ref.once('value', (snapshot) => { + snapshot.forEach((childSnapshot) => { + var childKey = childSnapshot.key; + var childData = childSnapshot.val(); + // ... + }); + }); + // [END rtdb_social_listen_value] +} + +function socialMostViewed() { + // [START rtdb_social_most_viewed] + var mostViewedPosts = firebase.database().ref('posts').orderByChild('metrics/views'); + // [END rtdb_social_most_viewed] +} + +function socialRecent() { + // [START rtdb_social_recent] + var recentPostsRef = firebase.database().ref('posts').limitToLast(100); + // [END rtdb_social_recent] +} diff --git a/database/read-and-write.js b/database/read-and-write.js index e18ae42a..2cac698f 100644 --- a/database/read-and-write.js +++ b/database/read-and-write.js @@ -29,3 +29,87 @@ function writeUserDataWithCompletion(userId, name, email, imageUrl) { }); // [START rtdb_write_new_user_completion] } + +function socialListenStarCount() { + const postElement = document.querySelector('#post'); + const postId = "1234"; + function updateStarCount(a, b) { + // ... + } + + // [START rtdb_social_listen_star_count] + var starCountRef = firebase.database().ref('posts/' + postId + '/starCount'); + starCountRef.on('value', (snapshot) =>{ + const data = snapshot.val(); + updateStarCount(postElement, data); + }); + // [END rtdb_social_listen_star_count] +} + +// [START rtdb_social_write_fan_out] +function writeNewPost(uid, username, picture, title, body) { + // A post entry. + var postData = { + author: username, + uid: uid, + body: body, + title: title, + starCount: 0, + authorPic: picture + }; + + // Get a key for a new Post. + var newPostKey = firebase.database().ref().child('posts').push().key; + + // Write the new post's data simultaneously in the posts list and the user's post list. + var updates = {}; + updates['/posts/' + newPostKey] = postData; + updates['/user-posts/' + uid + '/' + newPostKey] = postData; + + return firebase.database().ref().update(updates); +} +// [END rtdb_social_write_fan_out] + +function socialCompletionCallback() { + const userId = "123"; + const email = "test@example.com"; + const imageUrl = "https://example.com/image.png"; + + // [START rtdb_social_completion_callback] + firebase.database().ref('users/' + userId).set({ + username: name, + email: email, + profile_picture : imageUrl + }, (error) => { + if (error) { + // The write failed... + } else { + // Data saved successfully! + } + }); + // [END rtdb_social_completion_callback] +} + +/** + * @param {firebase.database.Reference} postRef + * @param {string} uid + */ +// [START rtdb_social_star_transaction] +function toggleStar(postRef, uid) { + postRef.transaction((post) => { + if (post) { + if (post.stars && post.stars[uid]) { + post.starCount--; + post.stars[uid] = null; + } else { + post.starCount++; + if (!post.stars) { + post.stars = {}; + } + post.stars[uid] = true; + } + } + return post; + }); +} +// [END rtdb_social_star_transaction] diff --git a/database/sharding.js b/database/sharding.js new file mode 100644 index 00000000..7a828689 --- /dev/null +++ b/database/sharding.js @@ -0,0 +1,23 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/database"; + +function multipleInstances() { + // [START rtdb_multiple_instances] + const app1 = firebase.initializeApp({ + databaseURL: "https://testapp-1234-1.firebaseio.com" + }); + + const app2 = firebase.initializeApp({ + databaseURL: "https://testapp-1234-2.firebaseio.com" + }, 'app2'); + + // Get the default database instance for an app1 + var database1 = firebase.database(); + + // Get a database instance for app2 + var database2 = firebase.database(app2); + // [END rtdb_multiple_instances] +} From e651200aeff19039e48129e9d12d87c05b962bb5 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 20 Nov 2020 16:00:24 +0000 Subject: [PATCH 038/235] One more database snippet --- database/lists-of-data.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/database/lists-of-data.js b/database/lists-of-data.js index 40c6c30a..c7a4b7d3 100644 --- a/database/lists-of-data.js +++ b/database/lists-of-data.js @@ -52,6 +52,13 @@ function socialListenValue() { // [END rtdb_social_listen_value] } +function socialMostStarred() { + // [START rtdb_social_most_starred] + var myUserId = firebase.auth().currentUser.uid; + var topUserPostsRef = firebase.database().ref('user-posts/' + myUserId).orderByChild('starCount'); + // [END rtdb_social_most_starred] +} + function socialMostViewed() { // [START rtdb_social_most_viewed] var mostViewedPosts = firebase.database().ref('posts').orderByChild('metrics/views'); From b1d4f1d1ae2a2064c50feb7d1f53af0ad53a82a7 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 20 Nov 2020 16:04:38 +0000 Subject: [PATCH 039/235] Another database snippet --- database/read-and-write.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/database/read-and-write.js b/database/read-and-write.js index 2cac698f..c2de45a9 100644 --- a/database/read-and-write.js +++ b/database/read-and-write.js @@ -46,6 +46,16 @@ function socialListenStarCount() { // [END rtdb_social_listen_star_count] } +function socialSingleValueRead() { + // [START rtdb_social_single_value_read] + var userId = firebase.auth().currentUser.uid; + return firebase.database().ref('/users/' + userId).once('value').then((snapshot) => { + var username = (snapshot.val() && snapshot.val().username) || 'Anonymous'; + // ... + }); + // [END rtdb_social_single_value_read] +} + // [START rtdb_social_write_fan_out] function writeNewPost(uid, username, picture, title, body) { // A post entry. From 64323e3969e2850fd4d24c5a269602517f761d80 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 20 Nov 2020 16:17:05 +0000 Subject: [PATCH 040/235] Typo --- database/lists-of-data.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/lists-of-data.js b/database/lists-of-data.js index c7a4b7d3..8010d10b 100644 --- a/database/lists-of-data.js +++ b/database/lists-of-data.js @@ -22,7 +22,7 @@ function socialListenChildren() { function setCommentValues(el, key, text, author) {}; function deleteComment(el, key) {}; - // [START rtb_social_listen_children] + // [START rtdb_social_listen_children] var commentsRef = firebase.database().ref('post-comments/' + postId); commentsRef.on('child_added', (data) => { addCommentElement(postElement, data.key, data.val().text, data.val().author); @@ -35,7 +35,7 @@ function socialListenChildren() { commentsRef.on('child_removed', (data) => { deleteComment(postElement, data.key); }); - // [END rtb_social_listen_children] + // [END rtdb_social_listen_children] } function socialListenValue() { From 9aa2c72a9f957e2bbebd13649f9c719ae45d9f18 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Wed, 2 Dec 2020 16:08:35 -0800 Subject: [PATCH 041/235] Move callable functions snippets (#63) --- firestore-next/emulator-suite.js | 2 + firestore-next/test.firestore.js | 2 + firestore-next/test.solution-aggregation.js | 2 + firestore-next/test.solution-arrays.js | 2 + firestore-next/test.solution-counters.js | 2 + firestore-next/test.solution-geoqueries.js | 2 + functions-next/callable.js | 41 +++++++++++++++++++ functions-next/emulator-suite.js | 2 + functions/callable.js | 35 ++++++++++++++++ .../callable/functions_call_add_message.js | 16 ++++++++ .../functions_call_add_message_error.js | 23 +++++++++++ 11 files changed, 129 insertions(+) create mode 100644 functions-next/callable.js create mode 100644 functions/callable.js create mode 100644 snippets/functions-next/callable/functions_call_add_message.js create mode 100644 snippets/functions-next/callable/functions_call_add_message_error.js diff --git a/firestore-next/emulator-suite.js b/firestore-next/emulator-suite.js index 6e608dc7..05997344 100644 --- a/firestore-next/emulator-suite.js +++ b/firestore-next/emulator-suite.js @@ -1,4 +1,6 @@ +// [SNIPPETS_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] + function onDocumentReady(firebaseApp) { // [START fs_emulator_connect] const { initializeFirestore } = require("firebase/firestore"); diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 09189eb2..98e856ed 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -1,4 +1,6 @@ +// [SNIPPETS_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] + const { expect } = require('chai'); // [START city_custom_object] diff --git a/firestore-next/test.solution-aggregation.js b/firestore-next/test.solution-aggregation.js index a2b8c487..06556023 100644 --- a/firestore-next/test.solution-aggregation.js +++ b/firestore-next/test.solution-aggregation.js @@ -1,4 +1,6 @@ +// [SNIPPETS_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] + // [START sample_doc] const arinellDoc = { name: 'Arinell Pizza', diff --git a/firestore-next/test.solution-arrays.js b/firestore-next/test.solution-arrays.js index 7c2ee04d..5353b7ed 100644 --- a/firestore-next/test.solution-arrays.js +++ b/firestore-next/test.solution-arrays.js @@ -1,4 +1,6 @@ +// [SNIPPETS_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] + const postsWithArray = [ // [START post_with_array] // Sample document in the 'posts' collection. diff --git a/firestore-next/test.solution-counters.js b/firestore-next/test.solution-counters.js index ab9eae36..9f6b2c37 100644 --- a/firestore-next/test.solution-counters.js +++ b/firestore-next/test.solution-counters.js @@ -1,4 +1,6 @@ +// [SNIPPETS_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] + const { FirebaseFirestore } = require('firebase/firestore'); /** @type {FirebaseFirestore} */ diff --git a/firestore-next/test.solution-geoqueries.js b/firestore-next/test.solution-geoqueries.js index 68380b2a..9560623b 100644 --- a/firestore-next/test.solution-geoqueries.js +++ b/firestore-next/test.solution-geoqueries.js @@ -1,4 +1,6 @@ +// [SNIPPETS_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] + const { FirebaseFirestore } = require('firebase/firestore'); const geofire = require('geofire-common'); diff --git a/functions-next/callable.js b/functions-next/callable.js new file mode 100644 index 00000000..9c5065bf --- /dev/null +++ b/functions-next/callable.js @@ -0,0 +1,41 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +export function callAddMessage(firebaseApp) { + const messageText = "Hello, World!"; + + // [START functions_call_add_message] + const { getFunctions, httpsCallable } = require("firebase/functions"); + + const functions = getFunctions(firebaseApp); + const addMessage = httpsCallable(functions, 'addMessage'); + addMessage({ text: messageText }) + .then((result) => { + // Read result of the Cloud Function. + const sanitizedMessage = result.data.text; + }); + // [END functions_call_add_message] +} + +export function callAddMessageError(firebaseApp) { + const messageText = "Hello, World!"; + + // [START functions_call_add_message_error] + const { getFunctions, httpsCallable } = require("firebase/functions"); + + const functions = getFunctions(firebaseApp); + const addMessage = httpsCallable(functions, 'addMessage'); + addMessage({ text: messageText }) + .then((result) => { + // Read result of the Cloud Function. + const sanitizedMessage = result.data.text; + }) + .catch((error) => { + // Getting the Error details. + const code = error.code; + const message = error.message; + const details = error.details; + // ... + }); + // [END functions_call_add_message_error] +} diff --git a/functions-next/emulator-suite.js b/functions-next/emulator-suite.js index ec7eddb8..976b1734 100644 --- a/functions-next/emulator-suite.js +++ b/functions-next/emulator-suite.js @@ -1,4 +1,6 @@ +// [SNIPPETS_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] + import { initializeApp } from "firebase/app"; initializeApp({ diff --git a/functions/callable.js b/functions/callable.js new file mode 100644 index 00000000..5cb6a515 --- /dev/null +++ b/functions/callable.js @@ -0,0 +1,35 @@ +import firebase from "firebase/app"; +import "firebase/functions"; + +function callAddMessage() { + const messageText = "Hello, World!"; + + // [START functions_call_add_message] + var addMessage = firebase.functions().httpsCallable('addMessage'); + addMessage({ text: messageText }) + .then((result) => { + // Read result of the Cloud Function. + var sanitizedMessage = result.data.text; + }); + // [END functions_call_add_message] +} + +function callAddMessageError() { + const messageText = "Hello, World!"; + + // [START functions_call_add_message_error] + var addMessage = firebase.functions().httpsCallable('addMessage'); + addMessage({ text: messageText }) + .then((result) => { + // Read result of the Cloud Function. + var sanitizedMessage = result.data.text; + }) + .catch((error) => { + // Getting the Error details. + var code = error.code; + var message = error.message; + var details = error.details; + // ... + }); + // [END functions_call_add_message_error] +} diff --git a/snippets/functions-next/callable/functions_call_add_message.js b/snippets/functions-next/callable/functions_call_add_message.js new file mode 100644 index 00000000..7836b85c --- /dev/null +++ b/snippets/functions-next/callable/functions_call_add_message.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./functions-next/callable.js +// +// To make edits to the snippets in this file, please edit the source + +// [START functions_call_add_message_modular] +import { getFunctions, httpsCallable } from "firebase/functions"; + +const functions = getFunctions(firebaseApp); +const addMessage = httpsCallable(functions, 'addMessage'); +addMessage({ text: messageText }) + .then((result) => { + // Read result of the Cloud Function. + const sanitizedMessage = result.data.text; + }); +// [END functions_call_add_message_modular] \ No newline at end of file diff --git a/snippets/functions-next/callable/functions_call_add_message_error.js b/snippets/functions-next/callable/functions_call_add_message_error.js new file mode 100644 index 00000000..84d8a381 --- /dev/null +++ b/snippets/functions-next/callable/functions_call_add_message_error.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./functions-next/callable.js +// +// To make edits to the snippets in this file, please edit the source + +// [START functions_call_add_message_error_modular] +import { getFunctions, httpsCallable } from "firebase/functions"; + +const functions = getFunctions(firebaseApp); +const addMessage = httpsCallable(functions, 'addMessage'); +addMessage({ text: messageText }) + .then((result) => { + // Read result of the Cloud Function. + const sanitizedMessage = result.data.text; + }) + .catch((error) => { + // Getting the Error details. + const code = error.code; + const message = error.message; + const details = error.details; + // ... + }); +// [END functions_call_add_message_error_modular] \ No newline at end of file From 1e2f89517b88f2c7db04833abe4c6b5fd5852eb0 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Wed, 2 Dec 2020 17:07:32 -0800 Subject: [PATCH 042/235] Add PerfMon snippets (#64) --- lerna.json | 4 +- perf-next/index.js | 93 +++++++++++++++++++ perf-next/package.json | 11 +++ perf/index.js | 71 ++++++++++++++ perf/package.json | 11 +++ .../index/perf_add_custom_attributes.js | 23 +++++ .../index/perf_add_custom_metrics.js | 22 +++++ .../perf-next/index/perf_add_custom_trace.js | 16 ++++ snippets/perf-next/index/perf_get_instance.js | 9 ++ .../perf-next/index/perf_user_timing_marks.js | 16 ++++ 10 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 perf-next/index.js create mode 100644 perf-next/package.json create mode 100644 perf/index.js create mode 100644 perf/package.json create mode 100644 snippets/perf-next/index/perf_add_custom_attributes.js create mode 100644 snippets/perf-next/index/perf_add_custom_metrics.js create mode 100644 snippets/perf-next/index/perf_add_custom_trace.js create mode 100644 snippets/perf-next/index/perf_get_instance.js create mode 100644 snippets/perf-next/index/perf_user_timing_marks.js diff --git a/lerna.json b/lerna.json index bf6d962e..dc13b226 100644 --- a/lerna.json +++ b/lerna.json @@ -8,7 +8,9 @@ "firestore-next", "functions", "functions-next", - "installations" + "installations", + "perf", + "perf-next" ], "version": "1.0.0" } diff --git a/perf-next/index.js b/perf-next/index.js new file mode 100644 index 00000000..af6a08db --- /dev/null +++ b/perf-next/index.js @@ -0,0 +1,93 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); +const perf = getInstance(firebaseApp); + +export function getInstance(firebaseApp) { + // [START perf_get_instance] + const { getPerformance } = require("firebase/performance"); + const perf = getPerformance(firebaseApp); + // [END perf_get_instance] + + return perf; +} + +export function addCustomTrace() { + // [START perf_add_custom_trace] + const { trace } = require("firebase/performance"); + + const t = trace(perf, "CUSTOM_TRACE_NAME"); + t.start(); + + // Code that you want to trace + // ... + + t.stop(); + // [END perf_add_custom_trace] +} + +export function userTimingMarks() { + // [START perf_user_timing_marks] + const performance = window.performance; + + performance.mark("measurementStart"); + + // Code that you want to trace + // ... + + performance.mark("measurementStop"); + performance.measure("customTraceName", "measurementStart", "measurementStop"); + // [END perf_user_timing_marks] +} + +export function addCustomAttributes() { + // [START perf_add_custom_attributes] + const { trace } = require("firebase/performance"); + + const t = trace(perf, "test_trace"); + t.putAttribute("experiment", "A"); + + // Update scenario + t.putAttribute("experiment", "B"); + + // Reading scenario + const experimentValue = t.getAttribute("experiment"); + + // Delete scenario + t.removeAttribute("experiment"); + + // Read attributes + const traceAttributes = t.getAttributes(); + // [END perf_add_custom_attributes] +} + +export function addCustomMetrics() { + async function retrieveInventory(inventoryIds) { + return {}; + } + + // [START perf_add_custom_metrics] + const { trace } = require("firebase/performance"); + + async function getInventory(inventoryIds) { + const t = trace(perf, "inventoryRetrieval"); + + // Tracks the number of IDs fetched (the metric could help you to optimize in the future) + t.incrementMetric("numberOfIds", inventoryIds.length); + + // Measures the time it takes to request inventory based on the amount of inventory + t.start(); + const inventoryData = await retrieveInventory(inventoryIds); + t.stop(); + + return inventoryData; + } + // [END perf_add_custom_metrics] +} diff --git a/perf-next/package.json b/perf-next/package.json new file mode 100644 index 00000000..3a04b696 --- /dev/null +++ b/perf-next/package.json @@ -0,0 +1,11 @@ +{ + "name": "perf-next", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "exp" + } +} diff --git a/perf/index.js b/perf/index.js new file mode 100644 index 00000000..9ef0dd9c --- /dev/null +++ b/perf/index.js @@ -0,0 +1,71 @@ +import firebase from "firebase/app"; +import "firebase/performance"; + +const perf = firebase.performance(); + +function addCustomTrace() { + // [START perf_add_custom_trace] + const trace = perf.trace("CUSTOM_TRACE_NAME"); + trace.start(); + + // Code that you want to trace + // ... + + trace.stop(); + // [END perf_add_custom_trace] +} + +function userTimingMarks() { + // [START perf_user_timing_marks] + const performance = window.performance; + + performance.mark("measurementStart"); + + // Code that you want to trace + // ... + + performance.mark("measurementStop"); + performance.measure("customTraceName", "measurementStart", "measurementStop"); + // [END perf_user_timing_marks] +} + +function addCustomAttributes() { + // [START perf_add_custom_attributes] + const trace = perf.trace("test_trace"); + trace.putAttribute("experiment", "A"); + + // Update scenario + trace.putAttribute("experiment", "B"); + + // Reading scenario + const experimentValue = trace.getAttribute("experiment"); + + // Delete scenario + trace.removeAttribute("experiment"); + + // Read attributes + const traceAttributes = trace.getAttributes(); + // [END perf_add_custom_attributes] +} + +function addCustomMetrics() { + async function retrieveInventory(inventoryIds) { + return {}; + } + + // [START perf_add_custom_metrics] + async function getInventory(inventoryIds) { + const trace = perf.trace("inventoryRetrieval"); + + // Tracks the number of IDs fetched (the metric could help you to optimize in the future) + trace.incrementMetric("numberOfIds", inventoryIds.length); + + // Measures the time it takes to request inventory based on the amount of inventory + trace.start(); + const inventoryData = await retrieveInventory(inventoryIds); + trace.stop(); + + return inventoryData; + } + // [END perf_add_custom_metrics] +} diff --git a/perf/package.json b/perf/package.json new file mode 100644 index 00000000..2d816586 --- /dev/null +++ b/perf/package.json @@ -0,0 +1,11 @@ +{ + "name": "perf", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^8.1.1" + } +} diff --git a/snippets/perf-next/index/perf_add_custom_attributes.js b/snippets/perf-next/index/perf_add_custom_attributes.js new file mode 100644 index 00000000..42639c63 --- /dev/null +++ b/snippets/perf-next/index/perf_add_custom_attributes.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./perf-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START perf_add_custom_attributes_modular] +import { trace } from "firebase/performance"; + +const t = trace(perf, "test_trace"); +t.putAttribute("experiment", "A"); + +// Update scenario +t.putAttribute("experiment", "B"); + +// Reading scenario +const experimentValue = t.getAttribute("experiment"); + +// Delete scenario +t.removeAttribute("experiment"); + +// Read attributes +const traceAttributes = t.getAttributes(); +// [END perf_add_custom_attributes_modular] \ No newline at end of file diff --git a/snippets/perf-next/index/perf_add_custom_metrics.js b/snippets/perf-next/index/perf_add_custom_metrics.js new file mode 100644 index 00000000..ad8ef48c --- /dev/null +++ b/snippets/perf-next/index/perf_add_custom_metrics.js @@ -0,0 +1,22 @@ +// This snippet file was generated by processing the source file: +// ./perf-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START perf_add_custom_metrics_modular] +import { trace } from "firebase/performance"; + +async function getInventory(inventoryIds) { + const t = trace(perf, "inventoryRetrieval"); + + // Tracks the number of IDs fetched (the metric could help you to optimize in the future) + t.incrementMetric("numberOfIds", inventoryIds.length); + + // Measures the time it takes to request inventory based on the amount of inventory + t.start(); + const inventoryData = await retrieveInventory(inventoryIds); + t.stop(); + + return inventoryData; +} +// [END perf_add_custom_metrics_modular] \ No newline at end of file diff --git a/snippets/perf-next/index/perf_add_custom_trace.js b/snippets/perf-next/index/perf_add_custom_trace.js new file mode 100644 index 00000000..004ecda2 --- /dev/null +++ b/snippets/perf-next/index/perf_add_custom_trace.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./perf-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START perf_add_custom_trace_modular] +import { trace } from "firebase/performance"; + +const t = trace(perf, "CUSTOM_TRACE_NAME"); +t.start(); + +// Code that you want to trace +// ... + +t.stop(); +// [END perf_add_custom_trace_modular] \ No newline at end of file diff --git a/snippets/perf-next/index/perf_get_instance.js b/snippets/perf-next/index/perf_get_instance.js new file mode 100644 index 00000000..c17d5103 --- /dev/null +++ b/snippets/perf-next/index/perf_get_instance.js @@ -0,0 +1,9 @@ +// This snippet file was generated by processing the source file: +// ./perf-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START perf_get_instance_modular] +import { getPerformance } from "firebase/performance"; +const perf = getPerformance(firebaseApp); +// [END perf_get_instance_modular] \ No newline at end of file diff --git a/snippets/perf-next/index/perf_user_timing_marks.js b/snippets/perf-next/index/perf_user_timing_marks.js new file mode 100644 index 00000000..5854f85c --- /dev/null +++ b/snippets/perf-next/index/perf_user_timing_marks.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./perf-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START perf_user_timing_marks_modular] +const performance = window.performance; + +performance.mark("measurementStart"); + +// Code that you want to trace +// ... + +performance.mark("measurementStop"); +performance.measure("customTraceName", "measurementStart", "measurementStop"); +// [END perf_user_timing_marks_modular] \ No newline at end of file From da6a2380f3c3f0775e69f4a176adc2c26373e4fd Mon Sep 17 00:00:00 2001 From: DPEBot Date: Tue, 8 Dec 2020 08:48:55 -0800 Subject: [PATCH 043/235] Auto-update dependencies. (#65) Co-authored-by: Sam --- firestore/index.html | 4 ++-- functions-next/emulator-suite.js | 2 +- functions-next/package.json | 2 +- .../emulator-suite/functions_emulator_connect.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index aa296817..c3ef1c91 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/functions-next/emulator-suite.js b/functions-next/emulator-suite.js index 976b1734..db085b57 100644 --- a/functions-next/emulator-suite.js +++ b/functions-next/emulator-suite.js @@ -15,7 +15,7 @@ export function emulatorSettings() { const { getFunctions, useFunctionsEmulator } = require("firebase/functions"); const functions = getFunctions(getApp()); - useFunctionsEmulator(functions, "http://localhost:5001"); + useFunctionsEmulator(functions, "localhost", 5001); // [END functions_emulator_connect] } diff --git a/functions-next/package.json b/functions-next/package.json index b5c9c6df..b2c9571e 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -7,6 +7,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp" + "firebase": "^0.900.2" } } diff --git a/snippets/functions-next/emulator-suite/functions_emulator_connect.js b/snippets/functions-next/emulator-suite/functions_emulator_connect.js index a25d2724..e9d5fead 100644 --- a/snippets/functions-next/emulator-suite/functions_emulator_connect.js +++ b/snippets/functions-next/emulator-suite/functions_emulator_connect.js @@ -8,5 +8,5 @@ import { getApp } from "firebase/app"; import { getFunctions, useFunctionsEmulator } from "firebase/functions"; const functions = getFunctions(getApp()); -useFunctionsEmulator(functions, "http://localhost:5001"); +useFunctionsEmulator(functions, "localhost", 5001); // [END functions_emulator_connect_modular] \ No newline at end of file From 114b5be26ff724d47fcd71981c41a6ad7c638cde Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Wed, 9 Dec 2020 03:11:17 -0800 Subject: [PATCH 044/235] Remote Config Snippets (#68) --- lerna.json | 4 +- remoteconfig-next/index.js | 60 +++++++++++++++++++ remoteconfig-next/package.json | 11 ++++ remoteconfig/index.js | 44 ++++++++++++++ remoteconfig/package.json | 11 ++++ .../index/rc_fetch_config_callback.js | 16 +++++ .../index/rc_get_instance.js | 10 ++++ .../remoteconfig-next/index/rc_get_values.js | 10 ++++ .../index/rc_set_default_values.js | 10 ++++ .../index/rc_set_minimum_fetch_time.js | 8 +++ 10 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 remoteconfig-next/index.js create mode 100644 remoteconfig-next/package.json create mode 100644 remoteconfig/index.js create mode 100644 remoteconfig/package.json create mode 100644 snippets/remoteconfig-next/index/rc_fetch_config_callback.js create mode 100644 snippets/remoteconfig-next/index/rc_get_instance.js create mode 100644 snippets/remoteconfig-next/index/rc_get_values.js create mode 100644 snippets/remoteconfig-next/index/rc_set_default_values.js create mode 100644 snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js diff --git a/lerna.json b/lerna.json index dc13b226..eac69d63 100644 --- a/lerna.json +++ b/lerna.json @@ -10,7 +10,9 @@ "functions-next", "installations", "perf", - "perf-next" + "perf-next", + "remoteconfig", + "remoteconfig-next" ], "version": "1.0.0" } diff --git a/remoteconfig-next/index.js b/remoteconfig-next/index.js new file mode 100644 index 00000000..b5240973 --- /dev/null +++ b/remoteconfig-next/index.js @@ -0,0 +1,60 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function getInstance() { + // [START rc_get_instance] + const { getRemoteConfig } = require("firebase/remote-config"); + + const remoteConfig = getRemoteConfig(firebaseApp); + // [END rc_get_instance] + + return remoteConfig; +} + +function setMinimumFetchTime() { + const remoteConfig = getInstance(); + // [START rc_set_minimum_fetch_time] + remoteConfig.settings.minimumFetchIntervalMillis = 3600000; + // [END rc_set_minimum_fetch_time] +} + +function setDefaultValues() { + const remoteConfig = getInstance(); + // [START rc_set_default_values] + remoteConfig.defaultConfig = { + "welcome_message": "Welcome" + }; + // [END rc_set_default_values] +} + +function getValues() { + const remoteConfig = getInstance(); + // [START rc_get_values] + const { getValue } = require("firebase/remote-config"); + + const val = getValue(remoteConfig, "welcome_messsage"); + // [END rc_get_values] +} + +function fetchConfigCallback() { + const remoteConfig = getInstance(); + // [START rc_fetch_config_callback] + const { fetchAndActivate } = require("firebase/remote-config"); + + fetchAndActivate(remoteConfig) + .then(() => { + // ... + }) + .catch((err) => { + // ... + }); + // [END rc_fetch_config_callback] +} diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json new file mode 100644 index 00000000..8977d454 --- /dev/null +++ b/remoteconfig-next/package.json @@ -0,0 +1,11 @@ +{ + "name": "remoteconfig-next", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "exp" + } +} diff --git a/remoteconfig/index.js b/remoteconfig/index.js new file mode 100644 index 00000000..bba80ac9 --- /dev/null +++ b/remoteconfig/index.js @@ -0,0 +1,44 @@ +import firebase from "firebase"; +import "firebase/remote-config"; + +function getInstance() { + // [START rc_get_instance] + const remoteConfig = firebase.remoteConfig(); + // [END rc_get_instance] +} + +function setMinimumFetchTime() { + const remoteConfig = firebase.remoteConfig(); + // [START rc_set_minimum_fetch_time] + remoteConfig.settings.minimumFetchIntervalMillis = 3600000; + // [END rc_set_minimum_fetch_time] +} + +function setDefaultValues() { + const remoteConfig = firebase.remoteConfig(); + // [START rc_set_default_values] + remoteConfig.defaultConfig = { + "welcome_message": "Welcome" + }; + // [END rc_set_default_values] +} + +function getValues() { + const remoteConfig = firebase.remoteConfig(); + // [START rc_get_values] + const val = remoteConfig.getValue("welcome_messsage"); + // [END rc_get_values] +} + +function fetchConfigCallback() { + const remoteConfig = firebase.remoteConfig(); + // [START rc_fetch_config_callback] + remoteConfig.fetchAndActivate() + .then(() => { + // ... + }) + .catch((err) => { + // ... + }); + // [END rc_fetch_config_callback] +} diff --git a/remoteconfig/package.json b/remoteconfig/package.json new file mode 100644 index 00000000..c4091095 --- /dev/null +++ b/remoteconfig/package.json @@ -0,0 +1,11 @@ +{ + "name": "remoteconfig", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^8.1.2" + } +} diff --git a/snippets/remoteconfig-next/index/rc_fetch_config_callback.js b/snippets/remoteconfig-next/index/rc_fetch_config_callback.js new file mode 100644 index 00000000..3975befd --- /dev/null +++ b/snippets/remoteconfig-next/index/rc_fetch_config_callback.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./remoteconfig-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rc_fetch_config_callback_modular] +import { fetchAndActivate } from "firebase/remote-config"; + +fetchAndActivate(remoteConfig) + .then(() => { + // ... + }) + .catch((err) => { + // ... + }); +// [END rc_fetch_config_callback_modular] \ No newline at end of file diff --git a/snippets/remoteconfig-next/index/rc_get_instance.js b/snippets/remoteconfig-next/index/rc_get_instance.js new file mode 100644 index 00000000..e20bd5a9 --- /dev/null +++ b/snippets/remoteconfig-next/index/rc_get_instance.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./remoteconfig-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rc_get_instance_modular] +import { getRemoteConfig } from "firebase/remote-config"; + +const remoteConfig = getRemoteConfig(firebaseApp); +// [END rc_get_instance_modular] \ No newline at end of file diff --git a/snippets/remoteconfig-next/index/rc_get_values.js b/snippets/remoteconfig-next/index/rc_get_values.js new file mode 100644 index 00000000..1266cfe9 --- /dev/null +++ b/snippets/remoteconfig-next/index/rc_get_values.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./remoteconfig-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rc_get_values_modular] +import { getValue } from "firebase/remote-config"; + +const val = getValue(remoteConfig, "welcome_messsage"); +// [END rc_get_values_modular] \ No newline at end of file diff --git a/snippets/remoteconfig-next/index/rc_set_default_values.js b/snippets/remoteconfig-next/index/rc_set_default_values.js new file mode 100644 index 00000000..6db33c0d --- /dev/null +++ b/snippets/remoteconfig-next/index/rc_set_default_values.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./remoteconfig-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rc_set_default_values_modular] +remoteConfig.defaultConfig = { + "welcome_message": "Welcome" +}; +// [END rc_set_default_values_modular] \ No newline at end of file diff --git a/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js b/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js new file mode 100644 index 00000000..77a442f9 --- /dev/null +++ b/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./remoteconfig-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rc_set_minimum_fetch_time_modular] +remoteConfig.settings.minimumFetchIntervalMillis = 3600000; +// [END rc_set_minimum_fetch_time_modular] \ No newline at end of file From 09ed8baf05126592f036edd2654c3724d179db7d Mon Sep 17 00:00:00 2001 From: DPEBot Date: Wed, 9 Dec 2020 04:08:31 -0800 Subject: [PATCH 045/235] Auto-update dependencies. (#67) Co-authored-by: Sam Stern --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions-next/package.json | 3 +-- functions/package.json | 2 +- installations/package.json | 2 +- perf/package.json | 2 +- 8 files changed, 8 insertions(+), 9 deletions(-) diff --git a/auth/package.json b/auth/package.json index 99355580..4c23c640 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.1.1", + "firebase": "^8.1.2", "firebaseui": "^4.7.1" } } diff --git a/database/package.json b/database/package.json index 93824133..4936c8de 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.1.1" + "firebase": "^8.1.2" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 1dc65cc5..55ef63f5 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.1.1" + "firebase": "^8.1.2" } } diff --git a/firestore/package.json b/firestore/package.json index 3f23ccf4..9b618ef2 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.1.1", + "firebase": "^8.1.2", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/package.json b/functions-next/package.json index b2c9571e..85e91e5d 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -2,11 +2,10 @@ "name": "functions-next", "version": "1.0.0", "scripts": { - "build": "webpack", "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" }, "license": "Apache-2.0", "dependencies": { - "firebase": "^0.900.2" + "firebase": "exp" } } diff --git a/functions/package.json b/functions/package.json index 19e3c427..e754fa56 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.1.1" + "firebase": "^8.1.2" } } diff --git a/installations/package.json b/installations/package.json index a415acce..d73fdd80 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.1.1" + "firebase": "^8.1.2" } } diff --git a/perf/package.json b/perf/package.json index 2d816586..f772e0c2 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.1.1" + "firebase": "^8.1.2" } } From ea75488205c7e50f90cf84a942aedfbdfec9b832 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 14 Dec 2020 02:01:57 -0800 Subject: [PATCH 046/235] Auto-update dependencies. (#69) --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/auth/package.json b/auth/package.json index 4c23c640..77466264 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.1.2", + "firebase": "^8.2.0", "firebaseui": "^4.7.1" } } diff --git a/database/package.json b/database/package.json index 4936c8de..529a6030 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.1.2" + "firebase": "^8.2.0" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 55ef63f5..e531cfc0 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.1.2" + "firebase": "^8.2.0" } } diff --git a/firestore/package.json b/firestore/package.json index 9b618ef2..87002065 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.1.2", + "firebase": "^8.2.0", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index e754fa56..cb6724d1 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.1.2" + "firebase": "^8.2.0" } } diff --git a/installations/package.json b/installations/package.json index d73fdd80..7ebf0472 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.1.2" + "firebase": "^8.2.0" } } diff --git a/perf/package.json b/perf/package.json index f772e0c2..281beee7 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.1.2" + "firebase": "^8.2.0" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index c4091095..1177c27d 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.1.2" + "firebase": "^8.2.0" } } From 94f5dc85944d0f84530c59e8442dfeddc1170872 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 14 Dec 2020 05:26:46 -0800 Subject: [PATCH 047/235] Auto-update dependencies. (#70) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index c3ef1c91..f79e54d4 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From 543e3aa859dfc3f5e21fa66825acc4a45acbee69 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 15 Dec 2020 03:38:37 -0800 Subject: [PATCH 048/235] Auth vNext Snippets (#66) --- auth-next/anonymous.js | 27 +++ auth-next/apple.js | 216 ++++++++++++++++++ auth-next/auth-state-persistence.js | 56 +++++ auth-next/cordova.js | 72 ++++++ auth-next/custom-email-handler.js | 155 +++++++++++++ auth-next/custom.js | 30 +++ auth-next/email-link-auth.js | 162 +++++++++++++ auth-next/email.js | 84 +++++++ auth-next/facebook.js | 102 +++++++++ auth-next/google-signin.js | 98 ++++++++ auth-next/index.js | 72 ++++++ auth-next/link-multiple-accounts.js | 192 ++++++++++++++++ auth-next/microsoft-oauth.js | 156 +++++++++++++ auth-next/package.json | 11 + auth-next/service-worker-sessions.js | 179 +++++++++++++++ auth-next/yahoo-oauth.js | 144 ++++++++++++ auth/apple.js | 1 + auth/custom-email-handler.js | 2 +- lerna.json | 1 + scripts/separate-snippets.ts | 29 +-- .../auth-next/anonymous/auth_anon_sign_in.js | 19 ++ .../apple/auth_apple_link_facebook.js | 25 ++ .../auth-next/apple/auth_apple_nonce_node.js | 27 +++ .../apple/auth_apple_provider_create.js | 10 + .../apple/auth_apple_provider_params.js | 11 + .../apple/auth_apple_provider_scopes.js | 9 + .../apple/auth_apple_reauthenticate_popup.js | 40 ++++ .../apple/auth_apple_signin_nonce.js | 29 +++ .../apple/auth_apple_signin_popup.js | 33 +++ .../apple/auth_apple_signin_redirect.js | 11 + .../auth_apple_signin_redirect_result.js | 33 +++ .../auth_set_persistence_none.js | 23 ++ .../auth_set_persistence_session.js | 24 ++ .../cordova/auth_cordova_redirect_result.js | 27 +++ .../cordova/auth_cordova_sign_in_redirect.js | 29 +++ .../cordova/auth_create_google_provider.js | 10 + .../auth_handle_mgmt_query_params.js | 49 ++++ .../auth_handle_recover_email.js | 36 +++ .../auth_handle_reset_password.js | 41 ++++ .../auth_handle_verify_email.js | 25 ++ .../auth-next/custom/auth_sign_in_custom.js | 20 ++ .../auth_email_link_actioncode_settings.js | 23 ++ .../email-link-auth/auth_email_link_link.js | 23 ++ .../email-link-auth/auth_email_link_reauth.js | 23 ++ .../email-link-auth/auth_email_link_send.js | 23 ++ .../email-link-auth/email_link_complete.js | 39 ++++ .../email_link_diferentiate.js | 31 +++ .../email/auth_send_email_verification.js | 15 ++ .../email/auth_send_password_reset.js | 20 ++ .../auth-next/email/auth_signin_password.js | 19 ++ .../auth-next/email/auth_signup_password.js | 20 ++ .../facebook/auth_facebook_callback.js | 42 ++++ .../facebook/auth_facebook_checksameuser.js | 22 ++ .../auth_facebook_signin_credential.js | 26 +++ .../auth-next/firebaseui/auth_fui_config.js | 38 +++ .../firebaseui/auth_fui_config_start.js | 8 + .../firebaseui/auth_fui_email_link_result.js | 15 ++ .../firebaseui/auth_fui_handle_anonymous.js | 44 ++++ .../auth-next/firebaseui/auth_fui_init.js | 8 + .../firebaseui/auth_fui_start_email.js | 13 ++ .../firebaseui/auth_fui_start_email_link.js | 16 ++ .../auth_fui_start_email_link_options.js | 45 ++++ .../auth_fui_start_email_options.js | 15 ++ .../firebaseui/auth_fui_start_oauth.js | 17 ++ .../auth_fui_start_oauth_options.js | 37 +++ .../firebaseui/auth_fui_start_phone.js | 13 ++ .../auth_fui_start_phone_options.js | 36 +++ .../google-signin/auth_google_build_signin.js | 24 ++ .../google-signin/auth_google_callback.js | 37 +++ .../auth_google_checksameuser.js | 22 ++ .../auth_google_signin_credential.js | 17 ++ .../index/auth_make_email_credential.js | 10 + .../index/auth_make_facebook_credential.js | 11 + .../index/auth_make_google_credential.js | 11 + snippets/auth-next/index/auth_sign_out.js | 15 ++ .../auth-next/index/auth_state_listener.js | 21 ++ .../auth_anonymous_link.js | 17 ++ .../auth_get_providers.js | 13 ++ .../auth_get_redirect_result.js | 19 ++ .../auth_link_with_popup.js | 20 ++ .../auth_link_with_redirect.js | 14 ++ .../auth_make_email_credential.js | 10 + .../auth_merge_accounts.js | 49 ++++ .../auth_simple_link.js | 17 ++ .../auth_unlink_provider.js | 17 ++ .../auth_msf_redirect_result.js | 23 ++ .../auth_msft_create_provider.js | 10 + .../microsoft-oauth/auth_msft_link_popup.js | 25 ++ .../auth_msft_provider_params.js | 13 ++ .../auth_msft_provider_params_tenant.js | 14 ++ .../microsoft-oauth/auth_msft_reauth_popup.js | 26 +++ .../microsoft-oauth/auth_msft_signin_popup.js | 23 ++ .../auth_msft_signin_redirect.js | 11 + .../auth_svc_get_idtoken.js | 17 ++ .../auth_svc_intercept.js | 81 +++++++ .../auth_svc_listen_activate.js | 10 + .../auth_svc_register.js | 11 + .../auth_svc_sign_in_email.js | 20 ++ .../auth_svc_subscribe.js | 35 +++ .../yahoo-oauth/auth_yahoo_create_provider.js | 10 + .../auth_yahoo_create_provider_params.js | 13 ++ .../auth_yahoo_create_provider_scopes.js | 12 + .../yahoo-oauth/auth_yahoo_link_popup.js | 24 ++ .../yahoo-oauth/auth_yahoo_reauth_popup.js | 26 +++ .../yahoo-oauth/auth_yahoo_redirect_result.js | 23 ++ .../yahoo-oauth/auth_yahoo_signin_popup.js | 23 ++ .../yahoo-oauth/auth_yahoo_signin_redirect.js | 11 + 107 files changed, 3742 insertions(+), 14 deletions(-) create mode 100644 auth-next/anonymous.js create mode 100644 auth-next/apple.js create mode 100644 auth-next/auth-state-persistence.js create mode 100644 auth-next/cordova.js create mode 100644 auth-next/custom-email-handler.js create mode 100644 auth-next/custom.js create mode 100644 auth-next/email-link-auth.js create mode 100644 auth-next/email.js create mode 100644 auth-next/facebook.js create mode 100644 auth-next/google-signin.js create mode 100644 auth-next/index.js create mode 100644 auth-next/link-multiple-accounts.js create mode 100644 auth-next/microsoft-oauth.js create mode 100644 auth-next/package.json create mode 100644 auth-next/service-worker-sessions.js create mode 100644 auth-next/yahoo-oauth.js create mode 100644 snippets/auth-next/anonymous/auth_anon_sign_in.js create mode 100644 snippets/auth-next/apple/auth_apple_link_facebook.js create mode 100644 snippets/auth-next/apple/auth_apple_nonce_node.js create mode 100644 snippets/auth-next/apple/auth_apple_provider_create.js create mode 100644 snippets/auth-next/apple/auth_apple_provider_params.js create mode 100644 snippets/auth-next/apple/auth_apple_provider_scopes.js create mode 100644 snippets/auth-next/apple/auth_apple_reauthenticate_popup.js create mode 100644 snippets/auth-next/apple/auth_apple_signin_nonce.js create mode 100644 snippets/auth-next/apple/auth_apple_signin_popup.js create mode 100644 snippets/auth-next/apple/auth_apple_signin_redirect.js create mode 100644 snippets/auth-next/apple/auth_apple_signin_redirect_result.js create mode 100644 snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js create mode 100644 snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js create mode 100644 snippets/auth-next/cordova/auth_cordova_redirect_result.js create mode 100644 snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js create mode 100644 snippets/auth-next/cordova/auth_create_google_provider.js create mode 100644 snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js create mode 100644 snippets/auth-next/custom-email-handler/auth_handle_recover_email.js create mode 100644 snippets/auth-next/custom-email-handler/auth_handle_reset_password.js create mode 100644 snippets/auth-next/custom-email-handler/auth_handle_verify_email.js create mode 100644 snippets/auth-next/custom/auth_sign_in_custom.js create mode 100644 snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js create mode 100644 snippets/auth-next/email-link-auth/auth_email_link_link.js create mode 100644 snippets/auth-next/email-link-auth/auth_email_link_reauth.js create mode 100644 snippets/auth-next/email-link-auth/auth_email_link_send.js create mode 100644 snippets/auth-next/email-link-auth/email_link_complete.js create mode 100644 snippets/auth-next/email-link-auth/email_link_diferentiate.js create mode 100644 snippets/auth-next/email/auth_send_email_verification.js create mode 100644 snippets/auth-next/email/auth_send_password_reset.js create mode 100644 snippets/auth-next/email/auth_signin_password.js create mode 100644 snippets/auth-next/email/auth_signup_password.js create mode 100644 snippets/auth-next/facebook/auth_facebook_callback.js create mode 100644 snippets/auth-next/facebook/auth_facebook_checksameuser.js create mode 100644 snippets/auth-next/facebook/auth_facebook_signin_credential.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_config.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_config_start.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_email_link_result.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_handle_anonymous.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_init.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_start_email.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_start_email_link.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_start_email_link_options.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_start_email_options.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_start_oauth.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_start_oauth_options.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_start_phone.js create mode 100644 snippets/auth-next/firebaseui/auth_fui_start_phone_options.js create mode 100644 snippets/auth-next/google-signin/auth_google_build_signin.js create mode 100644 snippets/auth-next/google-signin/auth_google_callback.js create mode 100644 snippets/auth-next/google-signin/auth_google_checksameuser.js create mode 100644 snippets/auth-next/google-signin/auth_google_signin_credential.js create mode 100644 snippets/auth-next/index/auth_make_email_credential.js create mode 100644 snippets/auth-next/index/auth_make_facebook_credential.js create mode 100644 snippets/auth-next/index/auth_make_google_credential.js create mode 100644 snippets/auth-next/index/auth_sign_out.js create mode 100644 snippets/auth-next/index/auth_state_listener.js create mode 100644 snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js create mode 100644 snippets/auth-next/link-multiple-accounts/auth_get_providers.js create mode 100644 snippets/auth-next/link-multiple-accounts/auth_get_redirect_result.js create mode 100644 snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js create mode 100644 snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js create mode 100644 snippets/auth-next/link-multiple-accounts/auth_make_email_credential.js create mode 100644 snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js create mode 100644 snippets/auth-next/link-multiple-accounts/auth_simple_link.js create mode 100644 snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js create mode 100644 snippets/auth-next/microsoft-oauth/auth_msf_redirect_result.js create mode 100644 snippets/auth-next/microsoft-oauth/auth_msft_create_provider.js create mode 100644 snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js create mode 100644 snippets/auth-next/microsoft-oauth/auth_msft_provider_params.js create mode 100644 snippets/auth-next/microsoft-oauth/auth_msft_provider_params_tenant.js create mode 100644 snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js create mode 100644 snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js create mode 100644 snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js create mode 100644 snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js create mode 100644 snippets/auth-next/service-worker-sessions/auth_svc_intercept.js create mode 100644 snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js create mode 100644 snippets/auth-next/service-worker-sessions/auth_svc_register.js create mode 100644 snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js create mode 100644 snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js create mode 100644 snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider.js create mode 100644 snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_params.js create mode 100644 snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_scopes.js create mode 100644 snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js create mode 100644 snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js create mode 100644 snippets/auth-next/yahoo-oauth/auth_yahoo_redirect_result.js create mode 100644 snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js create mode 100644 snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js diff --git a/auth-next/anonymous.js b/auth-next/anonymous.js new file mode 100644 index 00000000..59619a93 --- /dev/null +++ b/auth-next/anonymous.js @@ -0,0 +1,27 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +function anonSignIn() { + // [START auth_anon_sign_in] + const { getAuth, signInAnonymously } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInAnonymously(auth) + .then(() => { + // Signed in.. + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // ... + }) + // [END auth_anon_sign_in] +} diff --git a/auth-next/apple.js b/auth-next/apple.js new file mode 100644 index 00000000..f5620031 --- /dev/null +++ b/auth-next/apple.js @@ -0,0 +1,216 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/apple.md + +function appleProvider() { + // [START auth_apple_provider_create] + const { OAuthProvider } = require("firebase/auth"); + + const provider = new OAuthProvider('apple.com'); + // [END auth_apple_provider_create] + + // [START auth_apple_provider_scopes] + provider.addScope('email'); + provider.addScope('name'); + // [END auth_apple_provider_scopes] + + // [START auth_apple_provider_params] + provider.setCustomParameters({ + // Localize the Apple authentication screen in French. + locale: 'fr' + }); + // [END auth_apple_provider_params] +} + +function appleSignInPopup(provider) { + // [START auth_apple_signin_popup] + const { getAuth, signInWithPopup, OAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithPopup(auth, provider) + .then((result) => { + // The signed-in user info. + const user = result.user; + + // Apple credential + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + + // ... + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The credential that was used. + const credential = OAuthProvider.credentialFromError(error); + + // ... + }); + // [END auth_apple_signin_popup] +} + +function appleSignInRedirect(provider) { + // [START auth_apple_signin_redirect] + const { getAuth, signInWithRedirect } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithRedirect(auth, provider); + // [END auth_apple_signin_redirect] +} + +function appleSignInRedirectResult() { + // [START auth_apple_signin_redirect_result] + const { getAuth, getRedirectResult, OAuthProvider } = require("firebase/auth"); + + // Result from Redirect auth flow. + const auth = getAuth(firebaseApp); + getRedirectResult(auth) + .then((result) => { + const credential = OAuthProvider.credentialFromResult(result); + if (credential) { + // You can also get the Apple OAuth Access and ID Tokens. + const accessToken = credential.accessToken; + const idToken = credential.idToken; + } + // The signed-in user info. + const user = result.user; + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The credential that was used. + const credential = OAuthProvider.credentialFromError(error); + + // ... + }); + // [END auth_apple_signin_redirect_result] +} + +function appleReauthenticatePopup() { + // [START auth_apple_reauthenticate_popup] + const { getAuth, reauthenticateWithPopup, OAuthProvider } = require("firebase/auth"); + + // Result from Redirect auth flow. + const auth = getAuth(firebaseApp); + const provider = new OAuthProvider('apple.com'); + + reauthenticateWithPopup(auth.currentUser, provider) + .then((result) => { + // User is re-authenticated with fresh tokens minted and can perform + // sensitive operations like account deletion, or updating their email + // address or password. + + // The signed-in user info. + const user = result.user; + + // You can also get the Apple OAuth Access and ID Tokens. + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + + // ... + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The credential that was used. + const credential = OAuthProvider.credentialFromError(error); + + // ... + }); + // [END auth_apple_reauthenticate_popup] +} + +function appleLinkFacebook() { + // [START auth_apple_link_facebook] + const { getAuth, linkWithPopup, FacebookAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + const provider = new FacebookAuthProvider(); + provider.addScope('user_birthday'); + + // Assuming the current user is an Apple user linking a Facebook provider. + linkWithPopup(auth.currentUser, provider) + .then((result) => { + // Facebook credential is linked to the current Apple user. + // ... + + // The user can now sign in to the same account + // with either Apple or Facebook. + }) + .catch((error) => { + // Handle error. + }); + // [END auth_apple_link_facebook] +} + +function appleNonceNode() { + // [START auth_apple_nonce_node] + const crypto = require("crypto"); + const string_decoder = require("string_decoder"); + + // Generate a new random string for each sign-in + const generateNonce = (length) => { + const decoder = new string_decoder.StringDecoder("ascii"); + const buf = Buffer.alloc(length); + let nonce = ""; + while (nonce.length < length) { + crypto.randomFillSync(buf); + nonce = decoder.write(buf); + } + return nonce.substr(0, length); + }; + + const unhashedNonce = generateNonce(10); + + // SHA256-hashed nonce in hex + const hashedNonceHex = crypto.createHash('sha256') + .update(unhashedNonce).digest().toString('hex'); + // [END auth_apple_nonce_node] +} + +function appleSignInNonce(appleIdToken, unhashedNonce,) { + // [START auth_apple_signin_nonce] + const { getAuth, signInWithCredential, OAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + + // Build Firebase credential with the Apple ID token. + const provider = new OAuthProvider('apple.com'); + const authCredential = provider.credential({ + idToken: appleIdToken, + rawNonce: unhashedNonce, + }); + + // Sign in with credential form the Apple user. + signInWithCredential(auth, authCredential) + .then((result) => { + // User signed in. + }) + .catch((error) => { + // An error occurred. If error.code == 'auth/missing-or-invalid-nonce', + // make sure you're sending the SHA256-hashed nonce as a hex string + // with your request to Apple. + console.log(error); + }); + // [END auth_apple_signin_nonce] +} diff --git a/auth-next/auth-state-persistence.js b/auth-next/auth-state-persistence.js new file mode 100644 index 00000000..c128e5b7 --- /dev/null +++ b/auth-next/auth-state-persistence.js @@ -0,0 +1,56 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +function setPersistenceSession() { + const email = "..."; + const password = "..."; + + // [START auth_set_persistence_session] + const { getAuth, setPersistence, signInWithEmailAndPassword, browserSessionPersistence } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + setPersistence(auth, browserSessionPersistence) + .then(() => { + // Existing and future Auth states are now persisted in the current + // session only. Closing the window would clear any existing state even + // if a user forgets to sign out. + // ... + // New sign-in will be persisted with session persistence. + return signInWithEmailAndPassword(auth, email, password); + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + }); + // [END auth_set_persistence_session] +} + +function setPersistenceNone() { + // [START auth_set_persistence_none] + const { getAuth, setPersistence, signInWithRedirect, inMemoryPersistence, GoogleAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + setPersistence(auth, inMemoryPersistence) + .then(() => { + const provider = new GoogleAuthProvider(); + // In memory persistence will be applied to the signed in Google user + // even though the persistence was set to 'none' and a page redirect + // occurred. + return signInWithRedirect(auth, provider); + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + }); + // [END auth_set_persistence_none] +} diff --git a/auth-next/cordova.js b/auth-next/cordova.js new file mode 100644 index 00000000..6847ce7b --- /dev/null +++ b/auth-next/cordova.js @@ -0,0 +1,72 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/cordova.md + +function createGoogleProvider() { + // [START auth_create_google_provider] + const { GoogleAuthProvider } = require("firebase/auth"); + + const provider = new GoogleAuthProvider(); + // [END auth_create_google_provider] +} + +function cordovaSignInRedirect() { + // [START auth_cordova_sign_in_redirect] + const { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithRedirect(auth, new GoogleAuthProvider()) + .then(() => { + return getRedirectResult(auth); + }) + .then((result) => { + const credential = GoogleAuthProvider.credentialFromResult(result); + + // This gives you a Google Access Token. + // You can use it to access the Google API. + const token = credential.accessToken; + + // The signed-in user info. + const user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + }); + // [END auth_cordova_sign_in_redirect] +} + +function cordovaRedirectResult() { + // [START auth_cordova_redirect_result] + const { getAuth, getRedirectResult, GoogleAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + getRedirectResult(auth) + .then((result) => { + const credential = GoogleAuthProvider.credentialFromResult(result); + if (credential) { + // This gives you a Google Access Token. + // You can use it to access the Google API. + const token = credential.accessToken; + // The signed-in user info. + const user = result.user; + // ... + } + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + }); + // [END auth_cordova_redirect_result] +} diff --git a/auth-next/custom-email-handler.js b/auth-next/custom-email-handler.js new file mode 100644 index 00000000..69aad664 --- /dev/null +++ b/auth-next/custom-email-handler.js @@ -0,0 +1,155 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/custom-email-handler.md + +function handleUserManagementQueryParams() { + // TODO: This helpers should be implemented by the developer + function getParameterByName(name) { + return ""; + } + + // [START auth_handle_mgmt_query_params] + const { initializeApp } = require("firebase/app"); + const { getAuth } = require("firebase/auth"); + + document.addEventListener('DOMContentLoaded', () => { + // TODO: Implement getParameterByName() + + // Get the action to complete. + const mode = getParameterByName('mode'); + // Get the one-time code from the query parameter. + const actionCode = getParameterByName('oobCode'); + // (Optional) Get the continue URL from the query parameter if available. + const continueUrl = getParameterByName('continueUrl'); + // (Optional) Get the language code if available. + const lang = getParameterByName('lang') || 'en'; + + // Configure the Firebase SDK. + // This is the minimum configuration required for the API to be used. + const config = { + 'apiKey': "YOU_API_KEY" // Copy this key from the web initialization + // snippet found in the Firebase console. + }; + const app = initializeApp(config); + const auth = getAuth(app); + + // Handle the user management action. + switch (mode) { + case 'resetPassword': + // Display reset password handler and UI. + handleResetPassword(auth, actionCode, continueUrl, lang); + break; + case 'recoverEmail': + // Display email recovery handler and UI. + handleRecoverEmail(auth, actionCode, lang); + break; + case 'verifyEmail': + // Display email verification handler and UI. + handleVerifyEmail(auth, actionCode, continueUrl, lang); + break; + default: + // Error: invalid mode. + } + }, false); + // [END auth_handle_mgmt_query_params] +} + +// [START auth_handle_reset_password] +const { verifyPasswordResetCode, confirmPasswordReset } = require("firebase/auth"); + +function handleResetPassword(auth, actionCode, continueUrl, lang) { + // Localize the UI to the selected language as determined by the lang + // parameter. + + // Verify the password reset code is valid. + verifyPasswordResetCode(auth, actionCode).then((email) => { + const accountEmail = email; + + // TODO: Show the reset screen with the user's email and ask the user for + // the new password. + const newPassword = "..."; + + // Save the new password. + confirmPasswordReset(auth, actionCode, newPassword).then((resp) => { + // Password reset has been confirmed and new password updated. + + // TODO: Display a link back to the app, or sign-in the user directly + // if the page belongs to the same domain as the app: + // auth.signInWithEmailAndPassword(accountEmail, newPassword); + + // TODO: If a continue URL is available, display a button which on + // click redirects the user back to the app via continueUrl with + // additional state determined from that URL's parameters. + }).catch((error) => { + // Error occurred during confirmation. The code might have expired or the + // password is too weak. + }); + }).catch((error) => { + // Invalid or expired action code. Ask user to try to reset the password + // again. + }); +} +// [END auth_handle_reset_password] + +// [START auth_handle_recover_email] +const { checkActionCode, applyActionCode, sendPasswordResetEmail } = require("firebase/auth"); + +function handleRecoverEmail(auth, actionCode, lang) { + // Localize the UI to the selected language as determined by the lang + // parameter. + let restoredEmail = null; + // Confirm the action code is valid. + checkActionCode(auth, actionCode).then((info) => { + // Get the restored email address. + restoredEmail = info['data']['email']; + + // Revert to the old email. + return applyActionCode(auth, actionCode); + }).then(() => { + // Account email reverted to restoredEmail + + // TODO: Display a confirmation message to the user. + + // You might also want to give the user the option to reset their password + // in case the account was compromised: + sendPasswordResetEmail(auth, restoredEmail).then(() => { + // Password reset confirmation sent. Ask user to check their email. + }).catch((error) => { + // Error encountered while sending password reset code. + }); + }).catch((error) => { + // Invalid code. + }); +} +// [END auth_handle_recover_email] + +// [START auth_handle_verify_email] +function handleVerifyEmail(auth, actionCode, continueUrl, lang) { + // Localize the UI to the selected language as determined by the lang + // parameter. + // Try to apply the email verification code. + applyActionCode(auth, actionCode).then((resp) => { + // Email address has been verified. + + // TODO: Display a confirmation message to the user. + // You could also provide the user with a link back to the app. + + // TODO: If a continue URL is available, display a button which on + // click redirects the user back to the app via continueUrl with + // additional state determined from that URL's parameters. + }).catch((error) => { + // Code is invalid or expired. Ask the user to verify their email address + // again. + }); +} +// [END auth_handle_verify_email] + diff --git a/auth-next/custom.js b/auth-next/custom.js new file mode 100644 index 00000000..b9457a61 --- /dev/null +++ b/auth-next/custom.js @@ -0,0 +1,30 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +function signInCustom() { + const token = "token123"; + + // [START auth_sign_in_custom] + const { getAuth, signInWithCustomToken } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithCustomToken(auth, token) + .then((user) => { + // Signed in + // ... + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // ... + }) + // [END auth_sign_in_custom] +} diff --git a/auth-next/email-link-auth.js b/auth-next/email-link-auth.js new file mode 100644 index 00000000..50bf3753 --- /dev/null +++ b/auth-next/email-link-auth.js @@ -0,0 +1,162 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/email-link-auth.md + +function emailLinkActionCodeSettings() { + // [START auth_email_link_actioncode_settings] + const actionCodeSettings = { + // URL you want to redirect back to. The domain (www.example.com) for this + // URL must be in the authorized domains list in the Firebase Console. + url: 'https://www.example.com/finishSignUp?cartId=1234', + // This must be true. + handleCodeInApp: true, + iOS: { + bundleId: 'com.example.ios' + }, + android: { + packageName: 'com.example.android', + installApp: true, + minimumVersion: '12' + }, + dynamicLinkDomain: 'example.page.link' + }; + // [END auth_email_link_actioncode_settings] +} + +function emailLinkSend(email, actionCodeSettings) { + // [START auth_email_link_send] + const { getAuth, sendSignInLinkToEmail } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + sendSignInLinkToEmail(auth, email, actionCodeSettings) + .then(() => { + // The link was successfully sent. Inform the user. + // Save the email locally so you don't need to ask the user for it again + // if they open the link on the same device. + window.localStorage.setItem('emailForSignIn', email); + // ... + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // ... + }); + // [END auth_email_link_send] +} + +function emailLinkComplete() { + // [START email_link_complete] + const { getAuth, isSignInWithEmailLink, signInWithEmailLink } = require("firebase/auth"); + + // Confirm the link is a sign-in with email link. + const auth = getAuth(firebaseApp); + if (isSignInWithEmailLink(auth, window.location.href)) { + // Additional state parameters can also be passed via URL. + // This can be used to continue the user's intended action before triggering + // the sign-in operation. + // Get the email if available. This should be available if the user completes + // the flow on the same device where they started it. + let email = window.localStorage.getItem('emailForSignIn'); + if (!email) { + // User opened the link on a different device. To prevent session fixation + // attacks, ask the user to provide the associated email again. For example: + email = window.prompt('Please provide your email for confirmation'); + } + // The client SDK will parse the code from the link for you. + signInWithEmailLink(auth, email, window.location.href) + .then((result) => { + // Clear email from storage. + window.localStorage.removeItem('emailForSignIn'); + // You can access the new user via result.user + // Additional user info profile not available via: + // result.additionalUserInfo.profile == null + // You can check if the user is new or existing: + // result.additionalUserInfo.isNewUser + }) + .catch((error) => { + // Some error occurred, you can inspect the code: error.code + // Common errors could be invalid email and invalid or expired OTPs. + }); + } + // [END email_link_complete] +} + +function emailLinkLink(email) { + // [START auth_email_link_link] + const { getAuth, linkWithCredential, EmailAuthProvider } = require("firebase/auth"); + + // Construct the email link credential from the current URL. + const credential = EmailAuthProvider.credentialWithLink( + email, window.location.href); + + // Link the credential to the current user. + const auth = getAuth(firebaseApp); + linkWithCredential(auth.currentUser, credential) + .then((usercred) => { + // The provider is now successfully linked. + // The phone user can now sign in with their phone number or email. + }) + .catch((error) => { + // Some error occurred. + }); + // [END auth_email_link_link] +} + +function emailLinkReauth(email) { + // [START auth_email_link_reauth] + const { getAuth, reauthenticateWithCredential, EmailAuthProvider } = require("firebase/auth"); + + // Construct the email link credential from the current URL. + const credential = EmailAuthProvider.credentialWithLink( + email, window.location.href); + + // Re-authenticate the user with this credential. + const auth = getAuth(firebaseApp); + reauthenticateWithCredential(auth.currentUser, credential) + .then((usercred) => { + // The user is now successfully re-authenticated and can execute sensitive + // operations. + }) + .catch((error) => { + // Some error occurred. + }); + // [END auth_email_link_reauth] +} + +function emailLinkDifferentiate() { + // [START email_link_diferentiate] + const { getAuth, fetchSignInMethodsForEmail, EmailAuthProvider} = require("firebase/auth"); + + // After asking the user for their email. + const email = window.prompt('Please provide your email'); + + const auth = getAuth(firebaseApp); + fetchSignInMethodsForEmail(auth, email) + .then((signInMethods) => { + // This returns the same array as fetchProvidersForEmail but for email + // provider identified by 'password' string, signInMethods would contain 2 + // different strings: + // 'emailLink' if the user previously signed in with an email/link + // 'password' if the user has a password. + // A user could have both. + if (signInMethods.indexOf(EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD) != -1) { + // User can sign in with email/password. + } + if (signInMethods.indexOf(EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD) != -1) { + // User can sign in with email/link. + } + }) + .catch((error) => { + // Some error occurred, you can inspect the code: error.code + }); + // [END email_link_diferentiate] +} diff --git a/auth-next/email.js b/auth-next/email.js new file mode 100644 index 00000000..57d5308d --- /dev/null +++ b/auth-next/email.js @@ -0,0 +1,84 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +function signInWithEmailPassword() { + const email = "test@example.com"; + const password = "hunter2"; + + // [START auth_signin_password] + const { getAuth, signInWithEmailAndPassword } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithEmailAndPassword(auth, email, password) + .then((user) => { + // Signed in + // ... + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + }); + // [END auth_signin_password] +} + +function signUpWithEmailPasswoerd() { + const email = "test@example.com"; + const password = "hunter2"; + + // [START auth_signup_password] + const { getAuth, createUserWithEmailAndPassword } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + createUserWithEmailAndPassword(auth, email, password) + .then((user) => { + // Signed in + // ... + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // .. + }); + // [END auth_signup_password] +} + +function sendEmailVerification() { + // [START auth_send_email_verification] + const { getAuth, sendEmailVerification } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + sendEmailVerification(auth.currentUser) + .then(() => { + // Email verification sent! + // ... + }); + // [END auth_send_email_verification] +} + +function sendPasswordReset() { + const email = "sam@example.com"; + + // [START auth_send_password_reset] + const { getAuth, sendPasswordResetEmail } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + sendPasswordResetEmail(auth, email) + .then(() => { + // Password reset email sent! + // .. + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // .. + }); + // [END auth_send_password_reset] +} diff --git a/auth-next/facebook.js b/auth-next/facebook.js new file mode 100644 index 00000000..84a33568 --- /dev/null +++ b/auth-next/facebook.js @@ -0,0 +1,102 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +function checkLoginState_wrapper() { + // See real implementation below + function isUserEqual(x, y) { + return true; + } + + // [START auth_facebook_callback] + const { getAuth, onAuthStateChanged, signInWithCredential, signOut, FacebookAuthProvider } = require("firebase/auth"); + const auth = getAuth(firebaseApp); + + function checkLoginState(response) { + if (response.authResponse) { + // User is signed-in Facebook. + const unsubscribe = onAuthStateChanged(auth, (firebaseUser) => { + unsubscribe(); + // Check if we are already signed-in Firebase with the correct user. + if (!isUserEqual(response.authResponse, firebaseUser)) { + // Build Firebase credential with the Facebook auth token. + const credential = FacebookAuthProvider.credential( + response.authResponse.accessToken); + + // Sign in with the credential from the Facebook user. + // [START auth_facebook_signin_credential] + signInWithCredential(auth, credential) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = FacebookAuthProvider.credentialFromError(error); + // ... + }); + // [END auth_facebook_signin_credential] + } else { + // User is already signed-in Firebase with the correct user. + } + }); + } else { + // User is signed-out of Facebook. + signOut(auth); + } + } + // [END auth_facebook_callback] +} + +function isUserEqual_wrapper() { + // [START auth_facebook_checksameuser] + const { FacebookAuthProvider } = require("firebase/auth"); + + function isUserEqual(facebookAuthResponse, firebaseUser) { + if (firebaseUser) { + const providerData = firebaseUser.providerData; + for (let i = 0; i < providerData.length; i++) { + if (providerData[i].providerId === FacebookAuthProvider.PROVIDER_ID && + providerData[i].uid === facebookAuthResponse.userID) { + // We don't need to re-auth the Firebase connection. + return true; + } + } + } + return false; + } + // [END auth_facebook_checksameuser] +} + + +function authWithCredential(credential) { + // [START auth_facebook_signin_credential] + const { getAuth, signInWithCredential, FacebookAuthProvider } = require("firebase/auth"); + + // Sign in with the credential from the Facebook user. + const auth = getAuth(firebaseApp); + signInWithCredential(auth, credential) + .then((cred) => { + // Signed in + // ... + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = FacebookAuthProvider.credentialFromError(error); + // ... + }); + // [END auth_facebook_signin_credential] +} diff --git a/auth-next/google-signin.js b/auth-next/google-signin.js new file mode 100644 index 00000000..a087055c --- /dev/null +++ b/auth-next/google-signin.js @@ -0,0 +1,98 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/google-signin.md + +function googleBuildAndSignIn(id_token) { + // [START auth_google_build_signin] + const { getAuth, signInWithCredential, GoogleAuthProvider } = require("firebase/auth"); + + // Build Firebase credential with the Google ID token. + const credential = GoogleAuthProvider.credential(id_token); + + // Sign in with credential from the Google user. + const auth = getAuth(firebaseApp); + signInWithCredential(auth, credential).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = GoogleAuthProvider.credentialFromError(error); + // ... + }); + // [END auth_google_build_signin] +} + +function onSignIn_wrapper() { + // See real implementation below + function isUserEqual(x, y) { + return true; + } + + // [START auth_google_callback] + const { getAuth, onAuthStateChanged, signInWithCredential, GoogleAuthProvider } = require("firebase/auth"); + const auth = getAuth(firebaseApp); + + function onSignIn(googleUser) { + console.log('Google Auth Response', googleUser); + // We need to register an Observer on Firebase Auth to make sure auth is initialized. + const unsubscribe = onAuthStateChanged(auth, (firebaseUser) => { + unsubscribe(); + // Check if we are already signed-in Firebase with the correct user. + if (!isUserEqual(googleUser, firebaseUser)) { + // Build Firebase credential with the Google ID token. + const credential = GoogleAuthProvider.credential( + googleUser.getAuthResponse().id_token); + + // Sign in with credential from the Google user. + // [START auth_google_signin_credential] + signInWithCredential(auth, credential).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The credential that was used. + const credential = GoogleAuthProvider.credentialFromError(error); + // ... + }); + // [END auth_google_signin_credential] + } else { + console.log('User already signed-in Firebase.'); + } + }); + } + // [END auth_google_callback] +} + +function isUserEqual_wrapper() { + // [START auth_google_checksameuser] + const { GoogleAuthProvider } = require("firebase/auth"); + + function isUserEqual(googleUser, firebaseUser) { + if (firebaseUser) { + const providerData = firebaseUser.providerData; + for (let i = 0; i < providerData.length; i++) { + if (providerData[i].providerId === GoogleAuthProvider.PROVIDER_ID && + providerData[i].uid === googleUser.getBasicProfile().getId()) { + // We don't need to reauth the Firebase connection. + return true; + } + } + } + return false; + } + // [END auth_google_checksameuser] +} + + diff --git a/auth-next/index.js b/auth-next/index.js new file mode 100644 index 00000000..52e4bdeb --- /dev/null +++ b/auth-next/index.js @@ -0,0 +1,72 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +// ========================================================================================== +// Docs: Snippets in this file are "general purpose" and are used on more than one docs page +// ========================================================================================== + +function makeGoogleCredential(googleUser) { + // [START auth_make_google_credential] + const { GoogleAuthProvider } = require("firebase/auth"); + + const credential = GoogleAuthProvider.credential( + googleUser.getAuthResponse().id_token); + // [END auth_make_google_credential] +} + +function makeFacebookCredential(response) { + // [START auth_make_facebook_credential] + const { FacebookAuthProvider } = require("firebase/auth"); + + const credential = FacebookAuthProvider.credential( + response.authResponse.accessToken); + // [END auth_make_facebook_credential] +} + +function makeEmailCredential(email, password) { + // [START auth_make_email_credential] + const { EmailAuthProvider } = require("firebase/auth"); + + const credential = EmailAuthProvider.credential(email, password); + // [END auth_make_email_credential] +} + +function signOut() { + // [START auth_sign_out] + const { getAuth, signOut } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signOut(auth).then(() => { + // Sign-out successful. + }).catch((error) => { + // An error happened. + }); + // [END auth_sign_out] +} + +function authStateListener() { + // [START auth_state_listener] + const { getAuth, onAuthStateChanged } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + onAuthStateChanged(auth, (user) => { + if (user) { + // User is signed in, see docs for a list of available properties + // https://firebase.google.com/docs/reference/js/firebase.User + const uid = user.uid; + // ... + } else { + // User is signed out + // ... + } + }); + // [END auth_state_listener] +} diff --git a/auth-next/link-multiple-accounts.js b/auth-next/link-multiple-accounts.js new file mode 100644 index 00000000..6a861ddd --- /dev/null +++ b/auth-next/link-multiple-accounts.js @@ -0,0 +1,192 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +const MyUserDataRepo = function() {}; + +MyUserDataRepo.prototype.merge = function(data1, data2) { + // TODO(you): How you implement this is specific to your application! + return { + ...data1, + ...data2, + } +} + +MyUserDataRepo.prototype.set = function(user, data) { + // TODO(you): How you implement this is specific to your application! +} + +MyUserDataRepo.prototype.delete = function(user) { + // TODO(you): How you implement this is specific to your application! +} + +MyUserDataRepo.prototype.get = function(user) { + // TODO(you): How you implement this is specific to your application! + return {}; +} + +function getProviders() { + // [START auth_get_providers] + const { GoogleAuthProvider, FacebookAuthProvider, TwitterAuthProvider, GithubAuthProvider } = require("firebase/auth"); + + const googleProvider = new GoogleAuthProvider(); + const facebookProvider = new FacebookAuthProvider(); + const twitterProvider = new TwitterAuthProvider(); + const githubProvider = new GithubAuthProvider(); + // [END auth_get_providers] +} + +function simpleLink(credential) { + // [START auth_simple_link] + const { getAuth, linkWithCredential } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + linkWithCredential(auth.currentUser, credential) + .then((usercred) => { + const user = usercred.user; + console.log("Account linking success", user); + }).catch((error) => { + console.log("Account linking error", error); + }); + // [END auth_simple_link] +} + +function anonymousLink(credential) { + // [START auth_anonymous_link] + const { getAuth, linkWithCredential } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + linkWithCredential(auth.currentUser, credential) + .then((usercred) => { + const user = usercred.user; + console.log("Anonymous account successfully upgraded", user); + }).catch((error) => { + console.log("Error upgrading anonymous account", error); + }); + // [END auth_anonymous_link] +} + +function linkWithPopup() { + // [START auth_link_with_popup] + const { getAuth, linkWithPopup, GoogleAuthProvider } = require("firebase/auth"); + const provider = new GoogleAuthProvider(); + + const auth = getAuth(firebaseApp); + linkWithPopup(auth.currentUser, provider).then((result) => { + // Accounts successfully linked. + const credential = GoogleAuthProvider.credentialFromResult(result); + const user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + // ... + }); + // [END auth_link_with_popup] +} + +function linkWithRedirect() { + // [START auth_link_with_redirect] + const { getAuth, linkWithRedirect, GoogleAuthProvider } = require("firebase/auth"); + const provider = new GoogleAuthProvider(); + + const auth = getAuth(firebaseApp); + linkWithRedirect(auth.currentUser, provider) + .then(/* ... */) + .catch(/* ... */); + // [END auth_link_with_redirect] + + // [START auth_get_redirect_result] + const { getRedirectResult } = require("firebase/auth"); + getRedirectResult(auth).then((result) => { + const credential = GoogleAuthProvider.credentialFromResult(result); + if (credential) { + // Accounts successfully linked. + const user = result.user; + // ... + } + }).catch((error) => { + // Handle Errors here. + // ... + }); + // [END auth_get_redirect_result] +} + +function mergeAccounts(newCredential) { + // [START auth_merge_accounts] + const { getAuth, signInWithCredential, linkWithCredential, OAuthProvider } = require("firebase/auth"); + + // The implementation of how you store your user data depends on your application + const repo = new MyUserDataRepo(); + + // Get reference to the currently signed-in user + const auth = getAuth(firebaseApp); + const prevUser = auth.currentUser; + + // Get the data which you will want to merge. This should be done now + // while the app is still signed in as this user. + const prevUserData = repo.get(prevUser); + + // Delete the user's data now, we will restore it if the merge fails + repo.delete(prevUser); + + // Sign in user with the account you want to link to + signInWithCredential(auth, newCredential).then((result) => { + console.log("Sign In Success", result); + const currentUser = result.user; + const currentUserData = repo.get(currentUser); + + // Merge prevUser and currentUser data stored in Firebase. + // Note: How you handle this is specific to your application + const mergedData = repo.merge(prevUserData, currentUserData); + + const credential = OAuthProvider.credentialFromResult(result); + return linkWithCredential(prevUser, credential) + .then((linkResult) => { + // Sign in with the newly linked credential + const linkCredential = OAuthProvider.credentialFromResult(linkResult); + return signInWithCredential(auth, linkCredential); + }) + .then((signInResult) => { + // Save the merged data to the new user + repo.set(signInResult.user, mergedData); + }); + }).catch((error) => { + // If there are errors we want to undo the data merge/deletion + console.log("Sign In Error", error); + repo.set(prevUser, prevUserData); + }); + // [END auth_merge_accounts] +} + +function makeEmailCredential() { + const email = "test@test.com"; + const password = "abcde12345"; + + // [START auth_make_email_credential] + const { EmailAuthProvider } = require("firebase/auth"); + + const credential = EmailAuthProvider.credential(email, password); + // [END auth_make_email_credential] +} + +function unlink(providerId) { + // [START auth_unlink_provider] + const { getAuth, unlink } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + unlink(auth.currentUser, providerId).then(() => { + // Auth provider unlinked from account + // ... + }).catch((error) => { + // An error happened + // ... + }); + // [END auth_unlink_provider] +} diff --git a/auth-next/microsoft-oauth.js b/auth-next/microsoft-oauth.js new file mode 100644 index 00000000..508cd323 --- /dev/null +++ b/auth-next/microsoft-oauth.js @@ -0,0 +1,156 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/microsoft-oauth.md + +function msftCreateProvider() { + // [START auth_msft_create_provider] + const { OAuthProvider } = require("firebase/auth"); + + const provider = new OAuthProvider('microsoft.com'); + // [END auth_msft_create_provider] + + return provider; +} + +function msftProviderParams() { + const provider = msftCreateProvider(); + // [START auth_msft_provider_params] + provider.setCustomParameters({ + // Force re-consent. + prompt: 'consent', + // Target specific email with login hint. + login_hint: 'user@firstadd.onmicrosoft.com' + }); + // [END auth_msft_provider_params] +} + +function msftProviderParamsTenant() { + const provider = msftCreateProvider(); + // [START auth_msft_provider_params_tenant] + provider.setCustomParameters({ + // Optional "tenant" parameter in case you are using an Azure AD tenant. + // eg. '8eaef023-2b34-4da1-9baa-8bc8c9d6a490' or 'contoso.onmicrosoft.com' + // or "common" for tenant-independent tokens. + // The default value is "common". + tenant: 'TENANT_ID' + }); + // [END auth_msft_provider_params_tenant] +} + +function msftProviderScopes() { + const provider = msftCreateProvider(); + // [START auth_msft_provider_scopes + provider.addScope('mail.read'); + provider.addScope('calendars.read'); + // [END auth_msft_provider_scopes +} + +function msftSigninPopup() { + const provider = msftCreateProvider(); + // [START auth_msft_signin_popup] + const { getAuth, signInWithPopup, OAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithPopup(auth, provider) + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); + // [END auth_msft_signin_popup] +} + +function msftSignInRedirect() { + const provider = msftCreateProvider(); + + // [START auth_msft_signin_redirect] + const { getAuth, signInWithRedirect } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithRedirect(auth, provider); + // [END auth_msft_signin_redirect] +} + +function msftRedirectResult() { + // [START auth_msf_redirect_result] + const { getAuth, getRedirectResult, OAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + getRedirectResult(auth) + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); + // [END auth_msf_redirect_result] +} + +function msftLinkWithPopup() { + // [START auth_msft_link_popup] + const { getAuth, linkWithPopup, OAuthProvider } = require("firebase/auth"); + + const provider = new OAuthProvider('microsoft.com'); + const auth = getAuth(firebaseApp); + + linkWithPopup(auth.currentUser, provider) + .then((result) => { + // Microsoft credential is linked to the current user. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); + // [END auth_msft_link_popup] +} + +function msftReauthPopup() { + // [START auth_msft_reauth_popup] + const { getAuth, reauthenticateWithPopup, OAuthProvider } = require("firebase/auth"); + + const provider = new OAuthProvider('microsoft.com'); + const auth = getAuth(firebaseApp); + reauthenticateWithPopup(auth.currentUser, provider) + .then((result) => { + // User is re-authenticated with fresh tokens minted and + // should be able to perform sensitive operations like account + // deletion and email or password update. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); + // [END auth_msft_reauth_popup] +} diff --git a/auth-next/package.json b/auth-next/package.json new file mode 100644 index 00000000..3b90165e --- /dev/null +++ b/auth-next/package.json @@ -0,0 +1,11 @@ +{ + "name": "auth-next", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^0.900.4" + } +} diff --git a/auth-next/service-worker-sessions.js b/auth-next/service-worker-sessions.js new file mode 100644 index 00000000..0934cc4a --- /dev/null +++ b/auth-next/service-worker-sessions.js @@ -0,0 +1,179 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/service-worker-sessions.md + +function svcGetIdToken() { + // [START auth_svc_get_idtoken] + const { getAuth, getIdToken } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + getIdToken(auth.currentUser) + .then((idToken) => { + // idToken can be passed back to server. + }) + .catch((error) => { + // Error occurred. + }); + // [END auth_svc_get_idtoken] +} + +function svcSubscribe(config) { + // [START auth_svc_subscribe] + const { initializeApp } = require("firebase/app"); + const { getAuth, onAuthStateChanged, getIdToken } = require("firebase/auth"); + + // Initialize the Firebase app in the service worker script. + initializeApp(config); + + /** + * Returns a promise that resolves with an ID token if available. + * @return {!Promise} The promise that resolves with an ID token if + * available. Otherwise, the promise resolves with null. + */ + const auth = getAuth(firebaseApp); + const getIdTokenPromise = () => { + return new Promise((resolve, reject) => { + const unsubscribe = onAuthStateChanged(auth, (user) => { + unsubscribe(); + if (user) { + getIdToken(user).then((idToken) => { + resolve(idToken); + }, (error) => { + resolve(null); + }); + } else { + resolve(null); + } + }); + }); + }; + // [END auth_svc_subscribe] +} + +function svcIntercept() { + // See above + function getIdTokenPromise() { + return Promise.resolve("id-token"); + } + + // [START auth_svc_intercept] + const getOriginFromUrl = (url) => { + // https://stackoverflow.com/questions/1420881/how-to-extract-base-url-from-a-string-in-javascript + const pathArray = url.split('/'); + const protocol = pathArray[0]; + const host = pathArray[2]; + return protocol + '//' + host; + }; + + // Get underlying body if available. Works for text and json bodies. + const getBodyContent = (req) => { + return Promise.resolve().then(() => { + if (req.method !== 'GET') { + if (req.headers.get('Content-Type').indexOf('json') !== -1) { + return req.json() + .then((json) => { + return JSON.stringify(json); + }); + } else { + return req.text(); + } + } + }).catch((error) => { + // Ignore error. + }); + }; + + self.addEventListener('fetch', (event) => { + /** @type {FetchEvent} */ + let evt = event; + + const requestProcessor = (idToken) => { + let req = evt.request; + let processRequestPromise = Promise.resolve(); + // For same origin https requests, append idToken to header. + if (self.location.origin == getOriginFromUrl(evt.request.url) && + (self.location.protocol == 'https:' || + self.location.hostname == 'localhost') && + idToken) { + // Clone headers as request headers are immutable. + const headers = new Headers(); + req.headers.forEach((val, key) => { + headers.append(key, val); + }) + // Add ID token to header. + headers.append('Authorization', 'Bearer ' + idToken); + processRequestPromise = getBodyContent(req).then((body) => { + try { + req = new Request(req.url, { + method: req.method, + headers: headers, + mode: 'same-origin', + credentials: req.credentials, + cache: req.cache, + redirect: req.redirect, + referrer: req.referrer, + body, + // bodyUsed: req.bodyUsed, + // context: req.context + }); + } catch (e) { + // This will fail for CORS requests. We just continue with the + // fetch caching logic below and do not pass the ID token. + } + }); + } + return processRequestPromise.then(() => { + return fetch(req); + }); + }; + // Fetch the resource after checking for the ID token. + // This can also be integrated with existing logic to serve cached files + // in offline mode. + evt.respondWith(getIdTokenPromise().then(requestProcessor, requestProcessor)); + }); + // [END auth_svc_intercept] +} + +function svcListenActivate(clients) { + // [START auth_svc_listen_activate] + self.addEventListener('activate', event => { + event.waitUntil(clients.claim()); + }); + // [END auth_svc_listen_activate] +} + +function svcRegister() { + // [START auth_svc_register] + // Install servicerWorker if supported on sign-in/sign-up page. + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/service-worker.js', {scope: '/'}); + } + // [END auth_svc_register] +} + +function svcSignInEmail(email, password) { + // [START auth_svc_sign_in_email] + const { getAuth, signInWithEmailAndPassword } = require("firebase/auth"); + + // Sign in screen. + const auth = getAuth(firebaseApp); + signInWithEmailAndPassword(auth, email, password) + .then((result) => { + // Redirect to profile page after sign-in. The service worker will detect + // this and append the ID token to the header. + window.location.assign('/profile'); + }) + .catch((error) => { + // Error occurred. + }); + // [END auth_svc_sign_in_email] +} diff --git a/auth-next/yahoo-oauth.js b/auth-next/yahoo-oauth.js new file mode 100644 index 00000000..83531eae --- /dev/null +++ b/auth-next/yahoo-oauth.js @@ -0,0 +1,144 @@ +// [SNIPPETS_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/yahoo-oauth.md + +function yahooCreateProvider() { + // [START auth_yahoo_create_provider] + const { OAuthProvider } = require("firebase/auth"); + + const provider = new OAuthProvider('yahoo.com'); + // [END auth_yahoo_create_provider] + + return provider; +} + +function yahooCreateProviderParams() { + const provider = yahooCreateProvider(); + // [START auth_yahoo_create_provider_params] + provider.setCustomParameters({ + // Prompt user to re-authenticate to Yahoo. + prompt: 'login', + // Localize to French. + language: 'fr' + }); + // [END auth_yahoo_create_provider_params] +} + +function yahooCreateProviderScopes() { + const provider = yahooCreateProvider(); + // [START auth_yahoo_create_provider_scopes] + // Request access to Yahoo Mail API. + provider.addScope('mail-r'); + // Request read/write access to user contacts. + // This must be preconfigured in the app's API permissions. + provider.addScope('sdct-w'); + // [END auth_yahoo_create_provider_scopes] +} + +function yahooSignInPopup() { + const provider = yahooCreateProvider(); + // [START auth_yahoo_signin_popup] + const { getAuth, signInWithPopup,OAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithPopup(auth, provider) + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); + // [END auth_yahoo_signin_popup] +} + +function yahooSignInRedirect() { + const provider = yahooCreateProvider(); + // [START auth_yahoo_signin_redirect] + const { getAuth, signInWithRedirect } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithRedirect(auth, provider); + // [END auth_yahoo_signin_redirect] +} + +function yahooRedirectResult() { + // [START auth_yahoo_redirect_result] + const { getAuth, getRedirectResult, OAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + getRedirectResult(auth) + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); + // [END auth_yahoo_redirect_result] +} + +function yahooLinkPopup() { + // [START auth_yahoo_link_popup] + const { getAuth, linkWithPopup, OAuthProvider } = require("firebase/auth"); + + const provider = new OAuthProvider('yahoo.com'); + const auth = getAuth(firebaseApp); + linkWithPopup(auth.currentUser, provider) + .then((result) => { + // Yahoo credential is linked to the current user. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); + // [END auth_yahoo_link_popup] +} + +function yahooReauthPopup() { + // [START auth_yahoo_reauth_popup] + const { getAuth, reauthenticateWithPopup, OAuthProvider } = require("firebase/auth"); + + const provider = new OAuthProvider('yahoo.com'); + const auth = getAuth(firebaseApp); + reauthenticateWithPopup(auth.currentUser, provider) + .then((result) => { + // User is re-authenticated with fresh tokens minted and + // should be able to perform sensitive operations like account + // deletion and email or password update. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); + // [END auth_yahoo_reauth_popup] +} diff --git a/auth/apple.js b/auth/apple.js index 3a7a2c20..ad65ef08 100644 --- a/auth/apple.js +++ b/auth/apple.js @@ -143,6 +143,7 @@ function appleLinkFacebook() { .then((result) => { // Facebook credential is linked to the current Apple user. // Facebook additional data available in result.additionalUserInfo.profile, + // Additional Facebook OAuth access token can also be retrieved. // result.credential.accessToken diff --git a/auth/custom-email-handler.js b/auth/custom-email-handler.js index aea89aad..18a97043 100644 --- a/auth/custom-email-handler.js +++ b/auth/custom-email-handler.js @@ -118,7 +118,7 @@ function handleRecoverEmail(auth, actionCode, lang) { // Invalid code. }); } -// [END auth_handle_recover_emai] +// [END auth_handle_recover_email] // [START auth_handle_verify_email] function handleVerifyEmail(auth, actionCode, continueUrl, lang) { diff --git a/lerna.json b/lerna.json index eac69d63..6397cfbf 100644 --- a/lerna.json +++ b/lerna.json @@ -2,6 +2,7 @@ "lerna": "2.8.0", "packages": [ "auth", + "auth-next", "database", "firebaseapp", "firestore", diff --git a/scripts/separate-snippets.ts b/scripts/separate-snippets.ts index e449ad8b..575d08fe 100644 --- a/scripts/separate-snippets.ts +++ b/scripts/separate-snippets.ts @@ -130,29 +130,32 @@ function collectSnippets(filePath: string): SnippetsConfig { config.suffix = m[1]; } - let currSnippetName = ""; - let inSnippet = false; + let inSnippetNames = []; + for (const line of lines) { const startMatch = line.match(RE_START_SNIPPET); const endMatch = line.match(RE_END_SNIPPET); if (startMatch) { - inSnippet = true; - currSnippetName = startMatch[1]; - config.map[currSnippetName] = []; - } + const snippetName = startMatch[1]; + config.map[snippetName] = []; + config.map[snippetName].push(line); - if (inSnippet) { - config.map[currSnippetName].push(line); - } + inSnippetNames.push(snippetName); + } else if (endMatch) { + const snippetName = endMatch[1]; + config.map[snippetName].push(line); - if (endMatch) { - if (endMatch[1] !== currSnippetName) { + if (!inSnippetNames.includes(snippetName)) { throw new Error( - `Snippet ${currSnippetName} in ${filePath} has unmatched START/END tags` + `Unrecognized END tag ${snippetName} in ${filePath}.` ); } - inSnippet = false; + inSnippetNames.splice(inSnippetNames.indexOf(snippetName), 1); + } else if (inSnippetNames.length > 0) { + for (const snippetName of inSnippetNames) { + config.map[snippetName].push(line); + } } } diff --git a/snippets/auth-next/anonymous/auth_anon_sign_in.js b/snippets/auth-next/anonymous/auth_anon_sign_in.js new file mode 100644 index 00000000..f9c8f8e9 --- /dev/null +++ b/snippets/auth-next/anonymous/auth_anon_sign_in.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/anonymous.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_anon_sign_in_modular] +import { getAuth, signInAnonymously } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInAnonymously(auth) + .then(() => { + // Signed in.. + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // ... + }) +// [END auth_anon_sign_in_modular] \ No newline at end of file diff --git a/snippets/auth-next/apple/auth_apple_link_facebook.js b/snippets/auth-next/apple/auth_apple_link_facebook.js new file mode 100644 index 00000000..431f2621 --- /dev/null +++ b/snippets/auth-next/apple/auth_apple_link_facebook.js @@ -0,0 +1,25 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/apple.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_apple_link_facebook_modular] +import { getAuth, linkWithPopup, FacebookAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +const provider = new FacebookAuthProvider(); +provider.addScope('user_birthday'); + +// Assuming the current user is an Apple user linking a Facebook provider. +linkWithPopup(auth.currentUser, provider) + .then((result) => { + // Facebook credential is linked to the current Apple user. + // ... + + // The user can now sign in to the same account + // with either Apple or Facebook. + }) + .catch((error) => { + // Handle error. + }); +// [END auth_apple_link_facebook_modular] \ No newline at end of file diff --git a/snippets/auth-next/apple/auth_apple_nonce_node.js b/snippets/auth-next/apple/auth_apple_nonce_node.js new file mode 100644 index 00000000..27b08552 --- /dev/null +++ b/snippets/auth-next/apple/auth_apple_nonce_node.js @@ -0,0 +1,27 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/apple.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_apple_nonce_node_modular] +const crypto = require("crypto"); +const string_decoder = require("string_decoder"); + +// Generate a new random string for each sign-in +const generateNonce = (length) => { + const decoder = new string_decoder.StringDecoder("ascii"); + const buf = Buffer.alloc(length); + let nonce = ""; + while (nonce.length < length) { + crypto.randomFillSync(buf); + nonce = decoder.write(buf); + } + return nonce.substr(0, length); +}; + +const unhashedNonce = generateNonce(10); + +// SHA256-hashed nonce in hex +const hashedNonceHex = crypto.createHash('sha256') + .update(unhashedNonce).digest().toString('hex'); +// [END auth_apple_nonce_node_modular] \ No newline at end of file diff --git a/snippets/auth-next/apple/auth_apple_provider_create.js b/snippets/auth-next/apple/auth_apple_provider_create.js new file mode 100644 index 00000000..9612b2c3 --- /dev/null +++ b/snippets/auth-next/apple/auth_apple_provider_create.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/apple.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_apple_provider_create_modular] +import { OAuthProvider } from "firebase/auth"; + +const provider = new OAuthProvider('apple.com'); +// [END auth_apple_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth-next/apple/auth_apple_provider_params.js b/snippets/auth-next/apple/auth_apple_provider_params.js new file mode 100644 index 00000000..f0f914a2 --- /dev/null +++ b/snippets/auth-next/apple/auth_apple_provider_params.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/apple.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_apple_provider_params_modular] +provider.setCustomParameters({ + // Localize the Apple authentication screen in French. + locale: 'fr' +}); +// [END auth_apple_provider_params_modular] \ No newline at end of file diff --git a/snippets/auth-next/apple/auth_apple_provider_scopes.js b/snippets/auth-next/apple/auth_apple_provider_scopes.js new file mode 100644 index 00000000..306853bd --- /dev/null +++ b/snippets/auth-next/apple/auth_apple_provider_scopes.js @@ -0,0 +1,9 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/apple.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_apple_provider_scopes_modular] +provider.addScope('email'); +provider.addScope('name'); +// [END auth_apple_provider_scopes_modular] \ No newline at end of file diff --git a/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js b/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js new file mode 100644 index 00000000..2023c2cf --- /dev/null +++ b/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js @@ -0,0 +1,40 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/apple.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_apple_reauthenticate_popup_modular] +import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth"; + +// Result from Redirect auth flow. +const auth = getAuth(firebaseApp); +const provider = new OAuthProvider('apple.com'); + +reauthenticateWithPopup(auth.currentUser, provider) + .then((result) => { + // User is re-authenticated with fresh tokens minted and can perform + // sensitive operations like account deletion, or updating their email + // address or password. + + // The signed-in user info. + const user = result.user; + + // You can also get the Apple OAuth Access and ID Tokens. + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + + // ... + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The credential that was used. + const credential = OAuthProvider.credentialFromError(error); + + // ... + }); +// [END auth_apple_reauthenticate_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/apple/auth_apple_signin_nonce.js b/snippets/auth-next/apple/auth_apple_signin_nonce.js new file mode 100644 index 00000000..7f7dd884 --- /dev/null +++ b/snippets/auth-next/apple/auth_apple_signin_nonce.js @@ -0,0 +1,29 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/apple.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_apple_signin_nonce_modular] +import { getAuth, signInWithCredential, OAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); + +// Build Firebase credential with the Apple ID token. +const provider = new OAuthProvider('apple.com'); +const authCredential = provider.credential({ + idToken: appleIdToken, + rawNonce: unhashedNonce, +}); + +// Sign in with credential form the Apple user. +signInWithCredential(auth, authCredential) + .then((result) => { + // User signed in. + }) + .catch((error) => { + // An error occurred. If error.code == 'auth/missing-or-invalid-nonce', + // make sure you're sending the SHA256-hashed nonce as a hex string + // with your request to Apple. + console.log(error); + }); +// [END auth_apple_signin_nonce_modular] \ No newline at end of file diff --git a/snippets/auth-next/apple/auth_apple_signin_popup.js b/snippets/auth-next/apple/auth_apple_signin_popup.js new file mode 100644 index 00000000..1c5cc27f --- /dev/null +++ b/snippets/auth-next/apple/auth_apple_signin_popup.js @@ -0,0 +1,33 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/apple.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_apple_signin_popup_modular] +import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithPopup(auth, provider) + .then((result) => { + // The signed-in user info. + const user = result.user; + + // Apple credential + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + + // ... + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The credential that was used. + const credential = OAuthProvider.credentialFromError(error); + + // ... + }); +// [END auth_apple_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/apple/auth_apple_signin_redirect.js b/snippets/auth-next/apple/auth_apple_signin_redirect.js new file mode 100644 index 00000000..e00445f0 --- /dev/null +++ b/snippets/auth-next/apple/auth_apple_signin_redirect.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/apple.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_apple_signin_redirect_modular] +import { getAuth, signInWithRedirect } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithRedirect(auth, provider); +// [END auth_apple_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/apple/auth_apple_signin_redirect_result.js b/snippets/auth-next/apple/auth_apple_signin_redirect_result.js new file mode 100644 index 00000000..8872d0f7 --- /dev/null +++ b/snippets/auth-next/apple/auth_apple_signin_redirect_result.js @@ -0,0 +1,33 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/apple.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_apple_signin_redirect_result_modular] +import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; + +// Result from Redirect auth flow. +const auth = getAuth(firebaseApp); +getRedirectResult(auth) + .then((result) => { + const credential = OAuthProvider.credentialFromResult(result); + if (credential) { + // You can also get the Apple OAuth Access and ID Tokens. + const accessToken = credential.accessToken; + const idToken = credential.idToken; + } + // The signed-in user info. + const user = result.user; + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The credential that was used. + const credential = OAuthProvider.credentialFromError(error); + + // ... + }); +// [END auth_apple_signin_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js b/snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js new file mode 100644 index 00000000..5a1ce6fe --- /dev/null +++ b/snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/auth-state-persistence.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_set_persistence_none_modular] +import { getAuth, setPersistence, signInWithRedirect, inMemoryPersistence, GoogleAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +setPersistence(auth, inMemoryPersistence) + .then(() => { + const provider = new GoogleAuthProvider(); + // In memory persistence will be applied to the signed in Google user + // even though the persistence was set to 'none' and a page redirect + // occurred. + return signInWithRedirect(auth, provider); + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + }); +// [END auth_set_persistence_none_modular] \ No newline at end of file diff --git a/snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js b/snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js new file mode 100644 index 00000000..26917559 --- /dev/null +++ b/snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js @@ -0,0 +1,24 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/auth-state-persistence.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_set_persistence_session_modular] +import { getAuth, setPersistence, signInWithEmailAndPassword, browserSessionPersistence } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +setPersistence(auth, browserSessionPersistence) + .then(() => { + // Existing and future Auth states are now persisted in the current + // session only. Closing the window would clear any existing state even + // if a user forgets to sign out. + // ... + // New sign-in will be persisted with session persistence. + return signInWithEmailAndPassword(auth, email, password); + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + }); +// [END auth_set_persistence_session_modular] \ No newline at end of file diff --git a/snippets/auth-next/cordova/auth_cordova_redirect_result.js b/snippets/auth-next/cordova/auth_cordova_redirect_result.js new file mode 100644 index 00000000..d86e7672 --- /dev/null +++ b/snippets/auth-next/cordova/auth_cordova_redirect_result.js @@ -0,0 +1,27 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/cordova.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_cordova_redirect_result_modular] +import { getAuth, getRedirectResult, GoogleAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +getRedirectResult(auth) + .then((result) => { + const credential = GoogleAuthProvider.credentialFromResult(result); + if (credential) { + // This gives you a Google Access Token. + // You can use it to access the Google API. + const token = credential.accessToken; + // The signed-in user info. + const user = result.user; + // ... + } + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + }); +// [END auth_cordova_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js b/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js new file mode 100644 index 00000000..bd7a0360 --- /dev/null +++ b/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js @@ -0,0 +1,29 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/cordova.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_cordova_sign_in_redirect_modular] +import { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithRedirect(auth, new GoogleAuthProvider()) + .then(() => { + return getRedirectResult(auth); + }) + .then((result) => { + const credential = GoogleAuthProvider.credentialFromResult(result); + + // This gives you a Google Access Token. + // You can use it to access the Google API. + const token = credential.accessToken; + + // The signed-in user info. + const user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + }); +// [END auth_cordova_sign_in_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/cordova/auth_create_google_provider.js b/snippets/auth-next/cordova/auth_create_google_provider.js new file mode 100644 index 00000000..7fb88bc9 --- /dev/null +++ b/snippets/auth-next/cordova/auth_create_google_provider.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/cordova.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_create_google_provider_modular] +import { GoogleAuthProvider } from "firebase/auth"; + +const provider = new GoogleAuthProvider(); +// [END auth_create_google_provider_modular] \ No newline at end of file diff --git a/snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js b/snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js new file mode 100644 index 00000000..8810372f --- /dev/null +++ b/snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js @@ -0,0 +1,49 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/custom-email-handler.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_handle_mgmt_query_params_modular] +import { initializeApp } from "firebase/app"; +import { getAuth } from "firebase/auth"; + +document.addEventListener('DOMContentLoaded', () => { + // TODO: Implement getParameterByName() + + // Get the action to complete. + const mode = getParameterByName('mode'); + // Get the one-time code from the query parameter. + const actionCode = getParameterByName('oobCode'); + // (Optional) Get the continue URL from the query parameter if available. + const continueUrl = getParameterByName('continueUrl'); + // (Optional) Get the language code if available. + const lang = getParameterByName('lang') || 'en'; + + // Configure the Firebase SDK. + // This is the minimum configuration required for the API to be used. + const config = { + 'apiKey': "YOU_API_KEY" // Copy this key from the web initialization + // snippet found in the Firebase console. + }; + const app = initializeApp(config); + const auth = getAuth(app); + + // Handle the user management action. + switch (mode) { + case 'resetPassword': + // Display reset password handler and UI. + handleResetPassword(auth, actionCode, continueUrl, lang); + break; + case 'recoverEmail': + // Display email recovery handler and UI. + handleRecoverEmail(auth, actionCode, lang); + break; + case 'verifyEmail': + // Display email verification handler and UI. + handleVerifyEmail(auth, actionCode, continueUrl, lang); + break; + default: + // Error: invalid mode. + } +}, false); +// [END auth_handle_mgmt_query_params_modular] \ No newline at end of file diff --git a/snippets/auth-next/custom-email-handler/auth_handle_recover_email.js b/snippets/auth-next/custom-email-handler/auth_handle_recover_email.js new file mode 100644 index 00000000..db2bdea8 --- /dev/null +++ b/snippets/auth-next/custom-email-handler/auth_handle_recover_email.js @@ -0,0 +1,36 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/custom-email-handler.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_handle_recover_email_modular] +import { checkActionCode, applyActionCode, sendPasswordResetEmail } from "firebase/auth"; + +function handleRecoverEmail(auth, actionCode, lang) { + // Localize the UI to the selected language as determined by the lang + // parameter. + let restoredEmail = null; + // Confirm the action code is valid. + checkActionCode(auth, actionCode).then((info) => { + // Get the restored email address. + restoredEmail = info['data']['email']; + + // Revert to the old email. + return applyActionCode(auth, actionCode); + }).then(() => { + // Account email reverted to restoredEmail + + // TODO: Display a confirmation message to the user. + + // You might also want to give the user the option to reset their password + // in case the account was compromised: + sendPasswordResetEmail(auth, restoredEmail).then(() => { + // Password reset confirmation sent. Ask user to check their email. + }).catch((error) => { + // Error encountered while sending password reset code. + }); + }).catch((error) => { + // Invalid code. + }); +} +// [END auth_handle_recover_email_modular] \ No newline at end of file diff --git a/snippets/auth-next/custom-email-handler/auth_handle_reset_password.js b/snippets/auth-next/custom-email-handler/auth_handle_reset_password.js new file mode 100644 index 00000000..85f32168 --- /dev/null +++ b/snippets/auth-next/custom-email-handler/auth_handle_reset_password.js @@ -0,0 +1,41 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/custom-email-handler.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_handle_reset_password_modular] +import { verifyPasswordResetCode, confirmPasswordReset } from "firebase/auth"; + +function handleResetPassword(auth, actionCode, continueUrl, lang) { + // Localize the UI to the selected language as determined by the lang + // parameter. + + // Verify the password reset code is valid. + verifyPasswordResetCode(auth, actionCode).then((email) => { + const accountEmail = email; + + // TODO: Show the reset screen with the user's email and ask the user for + // the new password. + const newPassword = "..."; + + // Save the new password. + confirmPasswordReset(auth, actionCode, newPassword).then((resp) => { + // Password reset has been confirmed and new password updated. + + // TODO: Display a link back to the app, or sign-in the user directly + // if the page belongs to the same domain as the app: + // auth.signInWithEmailAndPassword(accountEmail, newPassword); + + // TODO: If a continue URL is available, display a button which on + // click redirects the user back to the app via continueUrl with + // additional state determined from that URL's parameters. + }).catch((error) => { + // Error occurred during confirmation. The code might have expired or the + // password is too weak. + }); + }).catch((error) => { + // Invalid or expired action code. Ask user to try to reset the password + // again. + }); +} +// [END auth_handle_reset_password_modular] \ No newline at end of file diff --git a/snippets/auth-next/custom-email-handler/auth_handle_verify_email.js b/snippets/auth-next/custom-email-handler/auth_handle_verify_email.js new file mode 100644 index 00000000..ca0089f0 --- /dev/null +++ b/snippets/auth-next/custom-email-handler/auth_handle_verify_email.js @@ -0,0 +1,25 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/custom-email-handler.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_handle_verify_email_modular] +function handleVerifyEmail(auth, actionCode, continueUrl, lang) { + // Localize the UI to the selected language as determined by the lang + // parameter. + // Try to apply the email verification code. + applyActionCode(auth, actionCode).then((resp) => { + // Email address has been verified. + + // TODO: Display a confirmation message to the user. + // You could also provide the user with a link back to the app. + + // TODO: If a continue URL is available, display a button which on + // click redirects the user back to the app via continueUrl with + // additional state determined from that URL's parameters. + }).catch((error) => { + // Code is invalid or expired. Ask the user to verify their email address + // again. + }); +} +// [END auth_handle_verify_email_modular] \ No newline at end of file diff --git a/snippets/auth-next/custom/auth_sign_in_custom.js b/snippets/auth-next/custom/auth_sign_in_custom.js new file mode 100644 index 00000000..0e14145f --- /dev/null +++ b/snippets/auth-next/custom/auth_sign_in_custom.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/custom.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_sign_in_custom_modular] +import { getAuth, signInWithCustomToken } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithCustomToken(auth, token) + .then((user) => { + // Signed in + // ... + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // ... + }) +// [END auth_sign_in_custom_modular] \ No newline at end of file diff --git a/snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js b/snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js new file mode 100644 index 00000000..dd6f4de2 --- /dev/null +++ b/snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/email-link-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_email_link_actioncode_settings_modular] +const actionCodeSettings = { + // URL you want to redirect back to. The domain (www.example.com) for this + // URL must be in the authorized domains list in the Firebase Console. + url: 'https://www.example.com/finishSignUp?cartId=1234', + // This must be true. + handleCodeInApp: true, + iOS: { + bundleId: 'com.example.ios' + }, + android: { + packageName: 'com.example.android', + installApp: true, + minimumVersion: '12' + }, + dynamicLinkDomain: 'example.page.link' +}; +// [END auth_email_link_actioncode_settings_modular] \ No newline at end of file diff --git a/snippets/auth-next/email-link-auth/auth_email_link_link.js b/snippets/auth-next/email-link-auth/auth_email_link_link.js new file mode 100644 index 00000000..8c0147ed --- /dev/null +++ b/snippets/auth-next/email-link-auth/auth_email_link_link.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/email-link-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_email_link_link_modular] +import { getAuth, linkWithCredential, EmailAuthProvider } from "firebase/auth"; + +// Construct the email link credential from the current URL. +const credential = EmailAuthProvider.credentialWithLink( + email, window.location.href); + +// Link the credential to the current user. +const auth = getAuth(firebaseApp); +linkWithCredential(auth.currentUser, credential) + .then((usercred) => { + // The provider is now successfully linked. + // The phone user can now sign in with their phone number or email. + }) + .catch((error) => { + // Some error occurred. + }); +// [END auth_email_link_link_modular] \ No newline at end of file diff --git a/snippets/auth-next/email-link-auth/auth_email_link_reauth.js b/snippets/auth-next/email-link-auth/auth_email_link_reauth.js new file mode 100644 index 00000000..e72b1c24 --- /dev/null +++ b/snippets/auth-next/email-link-auth/auth_email_link_reauth.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/email-link-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_email_link_reauth_modular] +import { getAuth, reauthenticateWithCredential, EmailAuthProvider } from "firebase/auth"; + +// Construct the email link credential from the current URL. +const credential = EmailAuthProvider.credentialWithLink( + email, window.location.href); + +// Re-authenticate the user with this credential. +const auth = getAuth(firebaseApp); +reauthenticateWithCredential(auth.currentUser, credential) + .then((usercred) => { + // The user is now successfully re-authenticated and can execute sensitive + // operations. + }) + .catch((error) => { + // Some error occurred. + }); +// [END auth_email_link_reauth_modular] \ No newline at end of file diff --git a/snippets/auth-next/email-link-auth/auth_email_link_send.js b/snippets/auth-next/email-link-auth/auth_email_link_send.js new file mode 100644 index 00000000..6fe2c15e --- /dev/null +++ b/snippets/auth-next/email-link-auth/auth_email_link_send.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/email-link-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_email_link_send_modular] +import { getAuth, sendSignInLinkToEmail } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +sendSignInLinkToEmail(auth, email, actionCodeSettings) + .then(() => { + // The link was successfully sent. Inform the user. + // Save the email locally so you don't need to ask the user for it again + // if they open the link on the same device. + window.localStorage.setItem('emailForSignIn', email); + // ... + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // ... + }); +// [END auth_email_link_send_modular] \ No newline at end of file diff --git a/snippets/auth-next/email-link-auth/email_link_complete.js b/snippets/auth-next/email-link-auth/email_link_complete.js new file mode 100644 index 00000000..af6b28ef --- /dev/null +++ b/snippets/auth-next/email-link-auth/email_link_complete.js @@ -0,0 +1,39 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/email-link-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START email_link_complete_modular] +import { getAuth, isSignInWithEmailLink, signInWithEmailLink } from "firebase/auth"; + +// Confirm the link is a sign-in with email link. +const auth = getAuth(firebaseApp); +if (isSignInWithEmailLink(auth, window.location.href)) { + // Additional state parameters can also be passed via URL. + // This can be used to continue the user's intended action before triggering + // the sign-in operation. + // Get the email if available. This should be available if the user completes + // the flow on the same device where they started it. + let email = window.localStorage.getItem('emailForSignIn'); + if (!email) { + // User opened the link on a different device. To prevent session fixation + // attacks, ask the user to provide the associated email again. For example: + email = window.prompt('Please provide your email for confirmation'); + } + // The client SDK will parse the code from the link for you. + signInWithEmailLink(auth, email, window.location.href) + .then((result) => { + // Clear email from storage. + window.localStorage.removeItem('emailForSignIn'); + // You can access the new user via result.user + // Additional user info profile not available via: + // result.additionalUserInfo.profile == null + // You can check if the user is new or existing: + // result.additionalUserInfo.isNewUser + }) + .catch((error) => { + // Some error occurred, you can inspect the code: error.code + // Common errors could be invalid email and invalid or expired OTPs. + }); +} +// [END email_link_complete_modular] \ No newline at end of file diff --git a/snippets/auth-next/email-link-auth/email_link_diferentiate.js b/snippets/auth-next/email-link-auth/email_link_diferentiate.js new file mode 100644 index 00000000..53bc1f32 --- /dev/null +++ b/snippets/auth-next/email-link-auth/email_link_diferentiate.js @@ -0,0 +1,31 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/email-link-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START email_link_diferentiate_modular] +import { getAuth, fetchSignInMethodsForEmail, EmailAuthProvider} from "firebase/auth"; + +// After asking the user for their email. +const email = window.prompt('Please provide your email'); + +const auth = getAuth(firebaseApp); +fetchSignInMethodsForEmail(auth, email) + .then((signInMethods) => { + // This returns the same array as fetchProvidersForEmail but for email + // provider identified by 'password' string, signInMethods would contain 2 + // different strings: + // 'emailLink' if the user previously signed in with an email/link + // 'password' if the user has a password. + // A user could have both. + if (signInMethods.indexOf(EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD) != -1) { + // User can sign in with email/password. + } + if (signInMethods.indexOf(EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD) != -1) { + // User can sign in with email/link. + } + }) + .catch((error) => { + // Some error occurred, you can inspect the code: error.code + }); +// [END email_link_diferentiate_modular] \ No newline at end of file diff --git a/snippets/auth-next/email/auth_send_email_verification.js b/snippets/auth-next/email/auth_send_email_verification.js new file mode 100644 index 00000000..a5e310c4 --- /dev/null +++ b/snippets/auth-next/email/auth_send_email_verification.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/email.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_send_email_verification_modular] +import { getAuth, sendEmailVerification } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +sendEmailVerification(auth.currentUser) + .then(() => { + // Email verification sent! + // ... + }); +// [END auth_send_email_verification_modular] \ No newline at end of file diff --git a/snippets/auth-next/email/auth_send_password_reset.js b/snippets/auth-next/email/auth_send_password_reset.js new file mode 100644 index 00000000..86458fa1 --- /dev/null +++ b/snippets/auth-next/email/auth_send_password_reset.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/email.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_send_password_reset_modular] +import { getAuth, sendPasswordResetEmail } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +sendPasswordResetEmail(auth, email) + .then(() => { + // Password reset email sent! + // .. + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // .. + }); +// [END auth_send_password_reset_modular] \ No newline at end of file diff --git a/snippets/auth-next/email/auth_signin_password.js b/snippets/auth-next/email/auth_signin_password.js new file mode 100644 index 00000000..d04a492e --- /dev/null +++ b/snippets/auth-next/email/auth_signin_password.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/email.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_signin_password_modular] +import { getAuth, signInWithEmailAndPassword } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithEmailAndPassword(auth, email, password) + .then((user) => { + // Signed in + // ... + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + }); +// [END auth_signin_password_modular] \ No newline at end of file diff --git a/snippets/auth-next/email/auth_signup_password.js b/snippets/auth-next/email/auth_signup_password.js new file mode 100644 index 00000000..de1e38bb --- /dev/null +++ b/snippets/auth-next/email/auth_signup_password.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/email.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_signup_password_modular] +import { getAuth, createUserWithEmailAndPassword } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +createUserWithEmailAndPassword(auth, email, password) + .then((user) => { + // Signed in + // ... + }) + .catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // .. + }); +// [END auth_signup_password_modular] \ No newline at end of file diff --git a/snippets/auth-next/facebook/auth_facebook_callback.js b/snippets/auth-next/facebook/auth_facebook_callback.js new file mode 100644 index 00000000..489cabf9 --- /dev/null +++ b/snippets/auth-next/facebook/auth_facebook_callback.js @@ -0,0 +1,42 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/facebook.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_facebook_callback_modular] +import { getAuth, onAuthStateChanged, signInWithCredential, signOut, FacebookAuthProvider } from "firebase/auth"; +const auth = getAuth(firebaseApp); + +function checkLoginState(response) { + if (response.authResponse) { + // User is signed-in Facebook. + const unsubscribe = onAuthStateChanged(auth, (firebaseUser) => { + unsubscribe(); + // Check if we are already signed-in Firebase with the correct user. + if (!isUserEqual(response.authResponse, firebaseUser)) { + // Build Firebase credential with the Facebook auth token. + const credential = FacebookAuthProvider.credential( + response.authResponse.accessToken); + + // Sign in with the credential from the Facebook user. + signInWithCredential(auth, credential) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = FacebookAuthProvider.credentialFromError(error); + // ... + }); + } else { + // User is already signed-in Firebase with the correct user. + } + }); + } else { + // User is signed-out of Facebook. + signOut(auth); + } +} +// [END auth_facebook_callback_modular] \ No newline at end of file diff --git a/snippets/auth-next/facebook/auth_facebook_checksameuser.js b/snippets/auth-next/facebook/auth_facebook_checksameuser.js new file mode 100644 index 00000000..e4ed4845 --- /dev/null +++ b/snippets/auth-next/facebook/auth_facebook_checksameuser.js @@ -0,0 +1,22 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/facebook.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_facebook_checksameuser_modular] +import { FacebookAuthProvider } from "firebase/auth"; + +function isUserEqual(facebookAuthResponse, firebaseUser) { + if (firebaseUser) { + const providerData = firebaseUser.providerData; + for (let i = 0; i < providerData.length; i++) { + if (providerData[i].providerId === FacebookAuthProvider.PROVIDER_ID && + providerData[i].uid === facebookAuthResponse.userID) { + // We don't need to re-auth the Firebase connection. + return true; + } + } + } + return false; +} +// [END auth_facebook_checksameuser_modular] \ No newline at end of file diff --git a/snippets/auth-next/facebook/auth_facebook_signin_credential.js b/snippets/auth-next/facebook/auth_facebook_signin_credential.js new file mode 100644 index 00000000..56de399b --- /dev/null +++ b/snippets/auth-next/facebook/auth_facebook_signin_credential.js @@ -0,0 +1,26 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/facebook.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_facebook_signin_credential_modular] +import { getAuth, signInWithCredential, FacebookAuthProvider } from "firebase/auth"; + +// Sign in with the credential from the Facebook user. +const auth = getAuth(firebaseApp); +signInWithCredential(auth, credential) + .then((cred) => { + // Signed in + // ... + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = FacebookAuthProvider.credentialFromError(error); + // ... + }); +// [END auth_facebook_signin_credential_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_config.js b/snippets/auth-next/firebaseui/auth_fui_config.js new file mode 100644 index 00000000..2f616a08 --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_config.js @@ -0,0 +1,38 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_config_modular] +const uiConfig = { + callbacks: { + signInSuccessWithAuthResult: function(authResult, redirectUrl) { + // User successfully signed in. + // Return type determines whether we continue the redirect automatically + // or whether we leave that to developer to handle. + return true; + }, + uiShown: function() { + // The widget is rendered. + // Hide the loader. + document.getElementById('loader').style.display = 'none'; + } + }, + // Will use popup for IDP Providers sign-in flow instead of the default, redirect. + signInFlow: 'popup', + signInSuccessUrl: '', + signInOptions: [ + // Leave the lines as is for the providers you want to offer your users. + firebase.auth.GoogleAuthProvider.PROVIDER_ID, + firebase.auth.FacebookAuthProvider.PROVIDER_ID, + firebase.auth.TwitterAuthProvider.PROVIDER_ID, + firebase.auth.GithubAuthProvider.PROVIDER_ID, + firebase.auth.EmailAuthProvider.PROVIDER_ID, + firebase.auth.PhoneAuthProvider.PROVIDER_ID + ], + // Terms of service url. + tosUrl: '', + // Privacy policy url. + privacyPolicyUrl: '' +}; +// [END auth_fui_config_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_config_start.js b/snippets/auth-next/firebaseui/auth_fui_config_start.js new file mode 100644 index 00000000..07472907 --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_config_start.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_config_start_modular] +ui.start('#firebaseui-auth-container', uiConfig); +// [END auth_fui_config_start_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_email_link_result.js b/snippets/auth-next/firebaseui/auth_fui_email_link_result.js new file mode 100644 index 00000000..3487a1b4 --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_email_link_result.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_email_link_result_modular] +// Is there an email link sign-in? +if (ui.isPendingRedirect()) { + ui.start('#firebaseui-auth-container', uiConfig); +} +// This can also be done via: +if (firebase.auth().isSignInWithEmailLink(window.location.href)) { + ui.start('#firebaseui-auth-container', uiConfig); +} +// [END auth_fui_email_link_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_handle_anonymous.js b/snippets/auth-next/firebaseui/auth_fui_handle_anonymous.js new file mode 100644 index 00000000..7a67ae05 --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_handle_anonymous.js @@ -0,0 +1,44 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_handle_anonymous_modular] +// Temp variable to hold the anonymous user data if needed. +const data = null; +// Hold a reference to the anonymous current user. +const anonymousUser = firebase.auth().currentUser; +ui.start('#firebaseui-auth-container', { + // Whether to upgrade anonymous users should be explicitly provided. + // The user must already be signed in anonymously before FirebaseUI is + // rendered. + autoUpgradeAnonymousUsers: true, + signInSuccessUrl: '', + signInOptions: [ + firebase.auth.GoogleAuthProvider.PROVIDER_ID, + firebase.auth.FacebookAuthProvider.PROVIDER_ID, + firebase.auth.EmailAuthProvider.PROVIDER_ID, + firebase.auth.PhoneAuthProvider.PROVIDER_ID + ], + callbacks: { + // signInFailure callback must be provided to handle merge conflicts which + // occur when an existing credential is linked to an anonymous user. + signInFailure: (error) => { + // For merge conflicts, the error.code will be + // 'firebaseui/anonymous-upgrade-merge-conflict'. + if (error.code != 'firebaseui/anonymous-upgrade-merge-conflict') { + return Promise.resolve(); + } + // The credential the user tried to sign in with. + const cred = error.credential; + // Copy data from anonymous user to permanent user and delete anonymous + // user. + // ... + // Finish sign-in after data is copied. + return firebase.auth().signInWithCredential(cred).then(() => { + return; + }); + } + } +}); +// [END auth_fui_handle_anonymous_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_init.js b/snippets/auth-next/firebaseui/auth_fui_init.js new file mode 100644 index 00000000..fc25d632 --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_init.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_init_modular] +const ui = new firebaseui.auth.AuthUI(firebase.auth()); +// [END auth_fui_init_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_email.js b/snippets/auth-next/firebaseui/auth_fui_start_email.js new file mode 100644 index 00000000..7ddabefc --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_start_email.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_start_email_modular] +ui.start('#firebaseui-auth-container', { + signInOptions: [ + firebase.auth.EmailAuthProvider.PROVIDER_ID + ], + // Other config options... +}); +// [END auth_fui_start_email_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_email_link.js b/snippets/auth-next/firebaseui/auth_fui_start_email_link.js new file mode 100644 index 00000000..de07a4e3 --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_start_email_link.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_start_email_link_modular] +ui.start('#firebaseui-auth-container', { + signInOptions: [ + { + provider: firebase.auth.EmailAuthProvider.PROVIDER_ID, + signInMethod: firebase.auth.EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD + } + ], + // Other config options... +}); +// [END auth_fui_start_email_link_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_email_link_options.js b/snippets/auth-next/firebaseui/auth_fui_start_email_link_options.js new file mode 100644 index 00000000..1e7ba122 --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_start_email_link_options.js @@ -0,0 +1,45 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_start_email_link_options_modular] +ui.start('#firebaseui-auth-container', { + signInOptions: [ + { + provider: firebase.auth.EmailAuthProvider.PROVIDER_ID, + signInMethod: firebase.auth.EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD, + // Allow the user the ability to complete sign-in cross device, + // including the mobile apps specified in the ActionCodeSettings + // object below. + forceSameDevice: false, + // Used to define the optional firebase.auth.ActionCodeSettings if + // additional state needs to be passed along request and whether to open + // the link in a mobile app if it is installed. + emailLinkSignIn: () => { + return { + // Additional state showPromo=1234 can be retrieved from URL on + // sign-in completion in signInSuccess callback by checking + // window.location.href. + url: 'https://www.example.com/completeSignIn?showPromo=1234', + // Custom FDL domain. + dynamicLinkDomain: 'example.page.link', + // Always true for email link sign-in. + handleCodeInApp: true, + // Whether to handle link in iOS app if installed. + iOS: { + bundleId: 'com.example.ios' + }, + // Whether to handle link in Android app if opened in an Android + // device. + android: { + packageName: 'com.example.android', + installApp: true, + minimumVersion: '12' + } + }; + } + } + ] +}); +// [END auth_fui_start_email_link_options_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_email_options.js b/snippets/auth-next/firebaseui/auth_fui_start_email_options.js new file mode 100644 index 00000000..8dfffff0 --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_start_email_options.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_start_email_options_modular] +ui.start('#firebaseui-auth-container', { + signInOptions: [ + { + provider: firebase.auth.EmailAuthProvider.PROVIDER_ID, + requireDisplayName: false + } + ] +}); +// [END auth_fui_start_email_options_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_oauth.js b/snippets/auth-next/firebaseui/auth_fui_start_oauth.js new file mode 100644 index 00000000..da946c75 --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_start_oauth.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_start_oauth_modular] +ui.start('#firebaseui-auth-container', { + signInOptions: [ + // List of OAuth providers supported. + firebase.auth.GoogleAuthProvider.PROVIDER_ID, + firebase.auth.FacebookAuthProvider.PROVIDER_ID, + firebase.auth.TwitterAuthProvider.PROVIDER_ID, + firebase.auth.GithubAuthProvider.PROVIDER_ID + ], + // Other config options... +}); +// [END auth_fui_start_oauth_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_oauth_options.js b/snippets/auth-next/firebaseui/auth_fui_start_oauth_options.js new file mode 100644 index 00000000..af787c1f --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_start_oauth_options.js @@ -0,0 +1,37 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_start_oauth_options_modular] +ui.start('#firebaseui-auth-container', { + signInOptions: [ + { + provider: firebase.auth.GoogleAuthProvider.PROVIDER_ID, + scopes: [ + 'https://www.googleapis.com/auth/contacts.readonly' + ], + customParameters: { + // Forces account selection even when one account + // is available. + prompt: 'select_account' + } + }, + { + provider: firebase.auth.FacebookAuthProvider.PROVIDER_ID, + scopes: [ + 'public_profile', + 'email', + 'user_likes', + 'user_friends' + ], + customParameters: { + // Forces password re-entry. + auth_type: 'reauthenticate' + } + }, + firebase.auth.TwitterAuthProvider.PROVIDER_ID, // Twitter does not support scopes. + firebase.auth.EmailAuthProvider.PROVIDER_ID // Other providers don't need to be given as object. + ] +}); +// [END auth_fui_start_oauth_options_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_phone.js b/snippets/auth-next/firebaseui/auth_fui_start_phone.js new file mode 100644 index 00000000..bd6d1b1d --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_start_phone.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_start_phone_modular] +ui.start('#firebaseui-auth-container', { + signInOptions: [ + firebase.auth.PhoneAuthProvider.PROVIDER_ID + ], + // Other config options... +}); +// [END auth_fui_start_phone_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_phone_options.js b/snippets/auth-next/firebaseui/auth_fui_start_phone_options.js new file mode 100644 index 00000000..8ae0de1d --- /dev/null +++ b/snippets/auth-next/firebaseui/auth_fui_start_phone_options.js @@ -0,0 +1,36 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/firebaseui.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_fui_start_phone_options_modular] +ui.start('#firebaseui-auth-container', { + signInOptions: [ + { + provider: firebase.auth.PhoneAuthProvider.PROVIDER_ID, + recaptchaParameters: { + type: 'image', // 'audio' + size: 'normal', // 'invisible' or 'compact' + badge: 'bottomleft' //' bottomright' or 'inline' applies to invisible. + }, + defaultCountry: 'GB', // Set default country to the United Kingdom (+44). + // For prefilling the national number, set defaultNationNumber. + // This will only be observed if only phone Auth provider is used since + // for multiple providers, the NASCAR screen will always render first + // with a 'sign in with phone number' button. + defaultNationalNumber: '1234567890', + // You can also pass the full phone number string instead of the + // 'defaultCountry' and 'defaultNationalNumber'. However, in this case, + // the first country ID that matches the country code will be used to + // populate the country selector. So for countries that share the same + // country code, the selected country may not be the expected one. + // In that case, pass the 'defaultCountry' instead to ensure the exact + // country is selected. The 'defaultCountry' and 'defaultNationaNumber' + // will always have higher priority than 'loginHint' which will be ignored + // in their favor. In this case, the default country will be 'GB' even + // though 'loginHint' specified the country code as '+1'. + loginHint: '+11234567890' + } + ] +}); +// [END auth_fui_start_phone_options_modular] \ No newline at end of file diff --git a/snippets/auth-next/google-signin/auth_google_build_signin.js b/snippets/auth-next/google-signin/auth_google_build_signin.js new file mode 100644 index 00000000..a462cb9e --- /dev/null +++ b/snippets/auth-next/google-signin/auth_google_build_signin.js @@ -0,0 +1,24 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/google-signin.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_google_build_signin_modular] +import { getAuth, signInWithCredential, GoogleAuthProvider } from "firebase/auth"; + +// Build Firebase credential with the Google ID token. +const credential = GoogleAuthProvider.credential(id_token); + +// Sign in with credential from the Google user. +const auth = getAuth(firebaseApp); +signInWithCredential(auth, credential).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = GoogleAuthProvider.credentialFromError(error); + // ... +}); +// [END auth_google_build_signin_modular] \ No newline at end of file diff --git a/snippets/auth-next/google-signin/auth_google_callback.js b/snippets/auth-next/google-signin/auth_google_callback.js new file mode 100644 index 00000000..c79fc89f --- /dev/null +++ b/snippets/auth-next/google-signin/auth_google_callback.js @@ -0,0 +1,37 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/google-signin.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_google_callback_modular] +import { getAuth, onAuthStateChanged, signInWithCredential, GoogleAuthProvider } from "firebase/auth"; +const auth = getAuth(firebaseApp); + +function onSignIn(googleUser) { + console.log('Google Auth Response', googleUser); + // We need to register an Observer on Firebase Auth to make sure auth is initialized. + const unsubscribe = onAuthStateChanged(auth, (firebaseUser) => { + unsubscribe(); + // Check if we are already signed-in Firebase with the correct user. + if (!isUserEqual(googleUser, firebaseUser)) { + // Build Firebase credential with the Google ID token. + const credential = GoogleAuthProvider.credential( + googleUser.getAuthResponse().id_token); + + // Sign in with credential from the Google user. + signInWithCredential(auth, credential).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The credential that was used. + const credential = GoogleAuthProvider.credentialFromError(error); + // ... + }); + } else { + console.log('User already signed-in Firebase.'); + } + }); +} +// [END auth_google_callback_modular] \ No newline at end of file diff --git a/snippets/auth-next/google-signin/auth_google_checksameuser.js b/snippets/auth-next/google-signin/auth_google_checksameuser.js new file mode 100644 index 00000000..e2a7cad9 --- /dev/null +++ b/snippets/auth-next/google-signin/auth_google_checksameuser.js @@ -0,0 +1,22 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/google-signin.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_google_checksameuser_modular] +import { GoogleAuthProvider } from "firebase/auth"; + +function isUserEqual(googleUser, firebaseUser) { + if (firebaseUser) { + const providerData = firebaseUser.providerData; + for (let i = 0; i < providerData.length; i++) { + if (providerData[i].providerId === GoogleAuthProvider.PROVIDER_ID && + providerData[i].uid === googleUser.getBasicProfile().getId()) { + // We don't need to reauth the Firebase connection. + return true; + } + } + } + return false; +} +// [END auth_google_checksameuser_modular] \ No newline at end of file diff --git a/snippets/auth-next/google-signin/auth_google_signin_credential.js b/snippets/auth-next/google-signin/auth_google_signin_credential.js new file mode 100644 index 00000000..6c8a5641 --- /dev/null +++ b/snippets/auth-next/google-signin/auth_google_signin_credential.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/google-signin.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_google_signin_credential_modular] +signInWithCredential(auth, credential).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The credential that was used. + const credential = GoogleAuthProvider.credentialFromError(error); + // ... +}); +// [END auth_google_signin_credential_modular] \ No newline at end of file diff --git a/snippets/auth-next/index/auth_make_email_credential.js b/snippets/auth-next/index/auth_make_email_credential.js new file mode 100644 index 00000000..7009633b --- /dev/null +++ b/snippets/auth-next/index/auth_make_email_credential.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_make_email_credential_modular] +import { EmailAuthProvider } from "firebase/auth"; + +const credential = EmailAuthProvider.credential(email, password); +// [END auth_make_email_credential_modular] \ No newline at end of file diff --git a/snippets/auth-next/index/auth_make_facebook_credential.js b/snippets/auth-next/index/auth_make_facebook_credential.js new file mode 100644 index 00000000..7a68e3b7 --- /dev/null +++ b/snippets/auth-next/index/auth_make_facebook_credential.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_make_facebook_credential_modular] +import { FacebookAuthProvider } from "firebase/auth"; + +const credential = FacebookAuthProvider.credential( + response.authResponse.accessToken); +// [END auth_make_facebook_credential_modular] \ No newline at end of file diff --git a/snippets/auth-next/index/auth_make_google_credential.js b/snippets/auth-next/index/auth_make_google_credential.js new file mode 100644 index 00000000..007bb7eb --- /dev/null +++ b/snippets/auth-next/index/auth_make_google_credential.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_make_google_credential_modular] +import { GoogleAuthProvider } from "firebase/auth"; + +const credential = GoogleAuthProvider.credential( + googleUser.getAuthResponse().id_token); +// [END auth_make_google_credential_modular] \ No newline at end of file diff --git a/snippets/auth-next/index/auth_sign_out.js b/snippets/auth-next/index/auth_sign_out.js new file mode 100644 index 00000000..9387b791 --- /dev/null +++ b/snippets/auth-next/index/auth_sign_out.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_sign_out_modular] +import { getAuth, signOut } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signOut(auth).then(() => { + // Sign-out successful. +}).catch((error) => { + // An error happened. +}); +// [END auth_sign_out_modular] \ No newline at end of file diff --git a/snippets/auth-next/index/auth_state_listener.js b/snippets/auth-next/index/auth_state_listener.js new file mode 100644 index 00000000..04f58e21 --- /dev/null +++ b/snippets/auth-next/index/auth_state_listener.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_state_listener_modular] +import { getAuth, onAuthStateChanged } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +onAuthStateChanged(auth, (user) => { + if (user) { + // User is signed in, see docs for a list of available properties + // https://firebase.google.com/docs/reference/js/firebase.User + const uid = user.uid; + // ... + } else { + // User is signed out + // ... + } +}); +// [END auth_state_listener_modular] \ No newline at end of file diff --git a/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js b/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js new file mode 100644 index 00000000..fdffb99e --- /dev/null +++ b/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/link-multiple-accounts.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_anonymous_link_modular] +import { getAuth, linkWithCredential } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +linkWithCredential(auth.currentUser, credential) + .then((usercred) => { + const user = usercred.user; + console.log("Anonymous account successfully upgraded", user); + }).catch((error) => { + console.log("Error upgrading anonymous account", error); + }); +// [END auth_anonymous_link_modular] \ No newline at end of file diff --git a/snippets/auth-next/link-multiple-accounts/auth_get_providers.js b/snippets/auth-next/link-multiple-accounts/auth_get_providers.js new file mode 100644 index 00000000..2550bdd7 --- /dev/null +++ b/snippets/auth-next/link-multiple-accounts/auth_get_providers.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/link-multiple-accounts.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_get_providers_modular] +import { GoogleAuthProvider, FacebookAuthProvider, TwitterAuthProvider, GithubAuthProvider } from "firebase/auth"; + +const googleProvider = new GoogleAuthProvider(); +const facebookProvider = new FacebookAuthProvider(); +const twitterProvider = new TwitterAuthProvider(); +const githubProvider = new GithubAuthProvider(); +// [END auth_get_providers_modular] \ No newline at end of file diff --git a/snippets/auth-next/link-multiple-accounts/auth_get_redirect_result.js b/snippets/auth-next/link-multiple-accounts/auth_get_redirect_result.js new file mode 100644 index 00000000..2118d9ba --- /dev/null +++ b/snippets/auth-next/link-multiple-accounts/auth_get_redirect_result.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/link-multiple-accounts.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_get_redirect_result_modular] +import { getRedirectResult } from "firebase/auth"; +getRedirectResult(auth).then((result) => { + const credential = GoogleAuthProvider.credentialFromResult(result); + if (credential) { + // Accounts successfully linked. + const user = result.user; + // ... + } +}).catch((error) => { + // Handle Errors here. + // ... +}); +// [END auth_get_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js b/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js new file mode 100644 index 00000000..b7ff7374 --- /dev/null +++ b/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/link-multiple-accounts.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_link_with_popup_modular] +import { getAuth, linkWithPopup, GoogleAuthProvider } from "firebase/auth"; +const provider = new GoogleAuthProvider(); + +const auth = getAuth(firebaseApp); +linkWithPopup(auth.currentUser, provider).then((result) => { + // Accounts successfully linked. + const credential = GoogleAuthProvider.credentialFromResult(result); + const user = result.user; + // ... +}).catch((error) => { + // Handle Errors here. + // ... +}); +// [END auth_link_with_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js b/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js new file mode 100644 index 00000000..4df66560 --- /dev/null +++ b/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js @@ -0,0 +1,14 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/link-multiple-accounts.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_link_with_redirect_modular] +import { getAuth, linkWithRedirect, GoogleAuthProvider } from "firebase/auth"; +const provider = new GoogleAuthProvider(); + +const auth = getAuth(firebaseApp); +linkWithRedirect(auth.currentUser, provider) + .then(/* ... */) + .catch(/* ... */); +// [END auth_link_with_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/link-multiple-accounts/auth_make_email_credential.js b/snippets/auth-next/link-multiple-accounts/auth_make_email_credential.js new file mode 100644 index 00000000..e78c54e1 --- /dev/null +++ b/snippets/auth-next/link-multiple-accounts/auth_make_email_credential.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/link-multiple-accounts.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_make_email_credential_modular] +import { EmailAuthProvider } from "firebase/auth"; + +const credential = EmailAuthProvider.credential(email, password); +// [END auth_make_email_credential_modular] \ No newline at end of file diff --git a/snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js b/snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js new file mode 100644 index 00000000..1f7205f2 --- /dev/null +++ b/snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js @@ -0,0 +1,49 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/link-multiple-accounts.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_merge_accounts_modular] +import { getAuth, signInWithCredential, linkWithCredential, OAuthProvider } from "firebase/auth"; + +// The implementation of how you store your user data depends on your application +const repo = new MyUserDataRepo(); + +// Get reference to the currently signed-in user +const auth = getAuth(firebaseApp); +const prevUser = auth.currentUser; + +// Get the data which you will want to merge. This should be done now +// while the app is still signed in as this user. +const prevUserData = repo.get(prevUser); + +// Delete the user's data now, we will restore it if the merge fails +repo.delete(prevUser); + +// Sign in user with the account you want to link to +signInWithCredential(auth, newCredential).then((result) => { + console.log("Sign In Success", result); + const currentUser = result.user; + const currentUserData = repo.get(currentUser); + + // Merge prevUser and currentUser data stored in Firebase. + // Note: How you handle this is specific to your application + const mergedData = repo.merge(prevUserData, currentUserData); + + const credential = OAuthProvider.credentialFromResult(result); + return linkWithCredential(prevUser, credential) + .then((linkResult) => { + // Sign in with the newly linked credential + const linkCredential = OAuthProvider.credentialFromResult(linkResult); + return signInWithCredential(auth, linkCredential); + }) + .then((signInResult) => { + // Save the merged data to the new user + repo.set(signInResult.user, mergedData); + }); +}).catch((error) => { + // If there are errors we want to undo the data merge/deletion + console.log("Sign In Error", error); + repo.set(prevUser, prevUserData); +}); +// [END auth_merge_accounts_modular] \ No newline at end of file diff --git a/snippets/auth-next/link-multiple-accounts/auth_simple_link.js b/snippets/auth-next/link-multiple-accounts/auth_simple_link.js new file mode 100644 index 00000000..4aef5f6d --- /dev/null +++ b/snippets/auth-next/link-multiple-accounts/auth_simple_link.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/link-multiple-accounts.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_simple_link_modular] +import { getAuth, linkWithCredential } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +linkWithCredential(auth.currentUser, credential) + .then((usercred) => { + const user = usercred.user; + console.log("Account linking success", user); + }).catch((error) => { + console.log("Account linking error", error); + }); +// [END auth_simple_link_modular] \ No newline at end of file diff --git a/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js b/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js new file mode 100644 index 00000000..0140810a --- /dev/null +++ b/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/link-multiple-accounts.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_unlink_provider_modular] +import { getAuth, unlink } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +unlink(auth.currentUser, providerId).then(() => { + // Auth provider unlinked from account + // ... +}).catch((error) => { + // An error happened + // ... +}); +// [END auth_unlink_provider_modular] \ No newline at end of file diff --git a/snippets/auth-next/microsoft-oauth/auth_msf_redirect_result.js b/snippets/auth-next/microsoft-oauth/auth_msf_redirect_result.js new file mode 100644 index 00000000..9b892ec2 --- /dev/null +++ b/snippets/auth-next/microsoft-oauth/auth_msf_redirect_result.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/microsoft-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_msf_redirect_result_modular] +import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +getRedirectResult(auth) + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); +// [END auth_msf_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_create_provider.js b/snippets/auth-next/microsoft-oauth/auth_msft_create_provider.js new file mode 100644 index 00000000..bbde8267 --- /dev/null +++ b/snippets/auth-next/microsoft-oauth/auth_msft_create_provider.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/microsoft-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_msft_create_provider_modular] +import { OAuthProvider } from "firebase/auth"; + +const provider = new OAuthProvider('microsoft.com'); +// [END auth_msft_create_provider_modular] \ No newline at end of file diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js b/snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js new file mode 100644 index 00000000..67a8ba9a --- /dev/null +++ b/snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js @@ -0,0 +1,25 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/microsoft-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_msft_link_popup_modular] +import { getAuth, linkWithPopup, OAuthProvider } from "firebase/auth"; + +const provider = new OAuthProvider('microsoft.com'); +const auth = getAuth(firebaseApp); + +linkWithPopup(auth.currentUser, provider) + .then((result) => { + // Microsoft credential is linked to the current user. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); +// [END auth_msft_link_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_provider_params.js b/snippets/auth-next/microsoft-oauth/auth_msft_provider_params.js new file mode 100644 index 00000000..dea75ee7 --- /dev/null +++ b/snippets/auth-next/microsoft-oauth/auth_msft_provider_params.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/microsoft-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_msft_provider_params_modular] +provider.setCustomParameters({ + // Force re-consent. + prompt: 'consent', + // Target specific email with login hint. + login_hint: 'user@firstadd.onmicrosoft.com' +}); +// [END auth_msft_provider_params_modular] \ No newline at end of file diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_provider_params_tenant.js b/snippets/auth-next/microsoft-oauth/auth_msft_provider_params_tenant.js new file mode 100644 index 00000000..82abfe9b --- /dev/null +++ b/snippets/auth-next/microsoft-oauth/auth_msft_provider_params_tenant.js @@ -0,0 +1,14 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/microsoft-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_msft_provider_params_tenant_modular] +provider.setCustomParameters({ + // Optional "tenant" parameter in case you are using an Azure AD tenant. + // eg. '8eaef023-2b34-4da1-9baa-8bc8c9d6a490' or 'contoso.onmicrosoft.com' + // or "common" for tenant-independent tokens. + // The default value is "common". + tenant: 'TENANT_ID' +}); +// [END auth_msft_provider_params_tenant_modular] \ No newline at end of file diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js b/snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js new file mode 100644 index 00000000..a15c3759 --- /dev/null +++ b/snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js @@ -0,0 +1,26 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/microsoft-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_msft_reauth_popup_modular] +import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth"; + +const provider = new OAuthProvider('microsoft.com'); +const auth = getAuth(firebaseApp); +reauthenticateWithPopup(auth.currentUser, provider) + .then((result) => { + // User is re-authenticated with fresh tokens minted and + // should be able to perform sensitive operations like account + // deletion and email or password update. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); +// [END auth_msft_reauth_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js b/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js new file mode 100644 index 00000000..93c34d0a --- /dev/null +++ b/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/microsoft-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_msft_signin_popup_modular] +import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithPopup(auth, provider) + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); +// [END auth_msft_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js new file mode 100644 index 00000000..7edec614 --- /dev/null +++ b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/microsoft-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_msft_signin_redirect_modular] +import { getAuth, signInWithRedirect } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithRedirect(auth, provider); +// [END auth_msft_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js b/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js new file mode 100644 index 00000000..fbed7d6b --- /dev/null +++ b/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/service-worker-sessions.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_svc_get_idtoken_modular] +import { getAuth, getIdToken } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +getIdToken(auth.currentUser) + .then((idToken) => { + // idToken can be passed back to server. + }) + .catch((error) => { + // Error occurred. + }); +// [END auth_svc_get_idtoken_modular] \ No newline at end of file diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_intercept.js b/snippets/auth-next/service-worker-sessions/auth_svc_intercept.js new file mode 100644 index 00000000..349ffd92 --- /dev/null +++ b/snippets/auth-next/service-worker-sessions/auth_svc_intercept.js @@ -0,0 +1,81 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/service-worker-sessions.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_svc_intercept_modular] +const getOriginFromUrl = (url) => { + // https://stackoverflow.com/questions/1420881/how-to-extract-base-url-from-a-string-in-javascript + const pathArray = url.split('/'); + const protocol = pathArray[0]; + const host = pathArray[2]; + return protocol + '//' + host; +}; + +// Get underlying body if available. Works for text and json bodies. +const getBodyContent = (req) => { + return Promise.resolve().then(() => { + if (req.method !== 'GET') { + if (req.headers.get('Content-Type').indexOf('json') !== -1) { + return req.json() + .then((json) => { + return JSON.stringify(json); + }); + } else { + return req.text(); + } + } + }).catch((error) => { + // Ignore error. + }); +}; + +self.addEventListener('fetch', (event) => { + /** @type {FetchEvent} */ + let evt = event; + + const requestProcessor = (idToken) => { + let req = evt.request; + let processRequestPromise = Promise.resolve(); + // For same origin https requests, append idToken to header. + if (self.location.origin == getOriginFromUrl(evt.request.url) && + (self.location.protocol == 'https:' || + self.location.hostname == 'localhost') && + idToken) { + // Clone headers as request headers are immutable. + const headers = new Headers(); + req.headers.forEach((val, key) => { + headers.append(key, val); + }) + // Add ID token to header. + headers.append('Authorization', 'Bearer ' + idToken); + processRequestPromise = getBodyContent(req).then((body) => { + try { + req = new Request(req.url, { + method: req.method, + headers: headers, + mode: 'same-origin', + credentials: req.credentials, + cache: req.cache, + redirect: req.redirect, + referrer: req.referrer, + body, + // bodyUsed: req.bodyUsed, + // context: req.context + }); + } catch (e) { + // This will fail for CORS requests. We just continue with the + // fetch caching logic below and do not pass the ID token. + } + }); + } + return processRequestPromise.then(() => { + return fetch(req); + }); + }; + // Fetch the resource after checking for the ID token. + // This can also be integrated with existing logic to serve cached files + // in offline mode. + evt.respondWith(getIdTokenPromise().then(requestProcessor, requestProcessor)); +}); +// [END auth_svc_intercept_modular] \ No newline at end of file diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js b/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js new file mode 100644 index 00000000..9003240d --- /dev/null +++ b/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/service-worker-sessions.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_svc_listen_activate_modular] +self.addEventListener('activate', event => { + event.waitUntil(clients.claim()); +}); +// [END auth_svc_listen_activate_modular] \ No newline at end of file diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_register.js b/snippets/auth-next/service-worker-sessions/auth_svc_register.js new file mode 100644 index 00000000..1b0b19c1 --- /dev/null +++ b/snippets/auth-next/service-worker-sessions/auth_svc_register.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/service-worker-sessions.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_svc_register_modular] +// Install servicerWorker if supported on sign-in/sign-up page. +if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/service-worker.js', {scope: '/'}); +} +// [END auth_svc_register_modular] \ No newline at end of file diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js b/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js new file mode 100644 index 00000000..14db554d --- /dev/null +++ b/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/service-worker-sessions.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_svc_sign_in_email_modular] +import { getAuth, signInWithEmailAndPassword } from "firebase/auth"; + +// Sign in screen. +const auth = getAuth(firebaseApp); +signInWithEmailAndPassword(auth, email, password) + .then((result) => { + // Redirect to profile page after sign-in. The service worker will detect + // this and append the ID token to the header. + window.location.assign('/profile'); + }) + .catch((error) => { + // Error occurred. + }); +// [END auth_svc_sign_in_email_modular] \ No newline at end of file diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js b/snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js new file mode 100644 index 00000000..c927fc4f --- /dev/null +++ b/snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js @@ -0,0 +1,35 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/service-worker-sessions.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_svc_subscribe_modular] +import { initializeApp } from "firebase/app"; +import { getAuth, onAuthStateChanged, getIdToken } from "firebase/auth"; + +// Initialize the Firebase app in the service worker script. +initializeApp(config); + +/** + * Returns a promise that resolves with an ID token if available. + * @return {!Promise} The promise that resolves with an ID token if + * available. Otherwise, the promise resolves with null. + */ +const auth = getAuth(firebaseApp); +const getIdTokenPromise = () => { + return new Promise((resolve, reject) => { + const unsubscribe = onAuthStateChanged(auth, (user) => { + unsubscribe(); + if (user) { + getIdToken(user).then((idToken) => { + resolve(idToken); + }, (error) => { + resolve(null); + }); + } else { + resolve(null); + } + }); + }); +}; +// [END auth_svc_subscribe_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider.js new file mode 100644 index 00000000..3b7c4b93 --- /dev/null +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/yahoo-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_yahoo_create_provider_modular] +import { OAuthProvider } from "firebase/auth"; + +const provider = new OAuthProvider('yahoo.com'); +// [END auth_yahoo_create_provider_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_params.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_params.js new file mode 100644 index 00000000..83e28c35 --- /dev/null +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_params.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/yahoo-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_yahoo_create_provider_params_modular] +provider.setCustomParameters({ + // Prompt user to re-authenticate to Yahoo. + prompt: 'login', + // Localize to French. + language: 'fr' +}); +// [END auth_yahoo_create_provider_params_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_scopes.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_scopes.js new file mode 100644 index 00000000..bb216718 --- /dev/null +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_scopes.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/yahoo-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_yahoo_create_provider_scopes_modular] +// Request access to Yahoo Mail API. +provider.addScope('mail-r'); +// Request read/write access to user contacts. +// This must be preconfigured in the app's API permissions. +provider.addScope('sdct-w'); +// [END auth_yahoo_create_provider_scopes_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js new file mode 100644 index 00000000..fbdaaeb1 --- /dev/null +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js @@ -0,0 +1,24 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/yahoo-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_yahoo_link_popup_modular] +import { getAuth, linkWithPopup, OAuthProvider } from "firebase/auth"; + +const provider = new OAuthProvider('yahoo.com'); +const auth = getAuth(firebaseApp); +linkWithPopup(auth.currentUser, provider) + .then((result) => { + // Yahoo credential is linked to the current user. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); +// [END auth_yahoo_link_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js new file mode 100644 index 00000000..d14b58e3 --- /dev/null +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js @@ -0,0 +1,26 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/yahoo-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_yahoo_reauth_popup_modular] +import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth"; + +const provider = new OAuthProvider('yahoo.com'); +const auth = getAuth(firebaseApp); +reauthenticateWithPopup(auth.currentUser, provider) + .then((result) => { + // User is re-authenticated with fresh tokens minted and + // should be able to perform sensitive operations like account + // deletion and email or password update. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); +// [END auth_yahoo_reauth_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_redirect_result.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_redirect_result.js new file mode 100644 index 00000000..f7ed546b --- /dev/null +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_redirect_result.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/yahoo-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_yahoo_redirect_result_modular] +import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +getRedirectResult(auth) + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); +// [END auth_yahoo_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js new file mode 100644 index 00000000..2bd94b16 --- /dev/null +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/yahoo-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_yahoo_signin_popup_modular] +import { getAuth, signInWithPopup,OAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithPopup(auth, provider) + .then((result) => { + // User is signed in. + // IdP data available in result.additionalUserInfo.profile. + + // Get the OAuth access token and ID Token + const credential = OAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + const idToken = credential.idToken; + }) + .catch((error) => { + // Handle error. + }); +// [END auth_yahoo_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js new file mode 100644 index 00000000..98ae3029 --- /dev/null +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/yahoo-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_yahoo_signin_redirect_modular] +import { getAuth, signInWithRedirect } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithRedirect(auth, provider); +// [END auth_yahoo_signin_redirect_modular] \ No newline at end of file From e5c4de0357d5a2cc43e631a481087c9f0f6f7238 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 15 Dec 2020 11:52:01 +0000 Subject: [PATCH 049/235] Fix disable markers --- auth-next/anonymous.js | 2 +- auth-next/apple.js | 2 +- auth-next/auth-state-persistence.js | 2 +- auth-next/cordova.js | 2 +- auth-next/custom-email-handler.js | 2 +- auth-next/custom.js | 2 +- auth-next/email-link-auth.js | 2 +- auth-next/email.js | 2 +- auth-next/facebook.js | 2 +- auth-next/google-signin.js | 2 +- auth-next/index.js | 2 +- auth-next/link-multiple-accounts.js | 2 +- auth-next/microsoft-oauth.js | 2 +- auth-next/service-worker-sessions.js | 2 +- auth-next/yahoo-oauth.js | 2 +- firestore-next/emulator-suite.js | 2 +- firestore-next/test.firestore.js | 2 +- firestore-next/test.solution-aggregation.js | 2 +- firestore-next/test.solution-arrays.js | 2 +- firestore-next/test.solution-counters.js | 2 +- firestore-next/test.solution-geoqueries.js | 2 +- functions-next/callable.js | 2 +- functions-next/emulator-suite.js | 2 +- perf-next/index.js | 2 +- remoteconfig-next/index.js | 2 +- scripts/separate-snippets.ts | 2 ++ 26 files changed, 27 insertions(+), 25 deletions(-) diff --git a/auth-next/anonymous.js b/auth-next/anonymous.js index 59619a93..ff8967b2 100644 --- a/auth-next/anonymous.js +++ b/auth-next/anonymous.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/apple.js b/auth-next/apple.js index f5620031..5796f7d8 100644 --- a/auth-next/apple.js +++ b/auth-next/apple.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/auth-state-persistence.js b/auth-next/auth-state-persistence.js index c128e5b7..ea62f3bc 100644 --- a/auth-next/auth-state-persistence.js +++ b/auth-next/auth-state-persistence.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/cordova.js b/auth-next/cordova.js index 6847ce7b..fffdea99 100644 --- a/auth-next/cordova.js +++ b/auth-next/cordova.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/custom-email-handler.js b/auth-next/custom-email-handler.js index 69aad664..a54575e8 100644 --- a/auth-next/custom-email-handler.js +++ b/auth-next/custom-email-handler.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/custom.js b/auth-next/custom.js index b9457a61..f16f8ab6 100644 --- a/auth-next/custom.js +++ b/auth-next/custom.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/email-link-auth.js b/auth-next/email-link-auth.js index 50bf3753..13cc225b 100644 --- a/auth-next/email-link-auth.js +++ b/auth-next/email-link-auth.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/email.js b/auth-next/email.js index 57d5308d..bdce4063 100644 --- a/auth-next/email.js +++ b/auth-next/email.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/facebook.js b/auth-next/facebook.js index 84a33568..27d87877 100644 --- a/auth-next/facebook.js +++ b/auth-next/facebook.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/google-signin.js b/auth-next/google-signin.js index a087055c..3c13500e 100644 --- a/auth-next/google-signin.js +++ b/auth-next/google-signin.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/index.js b/auth-next/index.js index 52e4bdeb..8e9a75c7 100644 --- a/auth-next/index.js +++ b/auth-next/index.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/link-multiple-accounts.js b/auth-next/link-multiple-accounts.js index 6a861ddd..764b499f 100644 --- a/auth-next/link-multiple-accounts.js +++ b/auth-next/link-multiple-accounts.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/microsoft-oauth.js b/auth-next/microsoft-oauth.js index 508cd323..80352b4f 100644 --- a/auth-next/microsoft-oauth.js +++ b/auth-next/microsoft-oauth.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/service-worker-sessions.js b/auth-next/service-worker-sessions.js index 0934cc4a..90dc15fe 100644 --- a/auth-next/service-worker-sessions.js +++ b/auth-next/service-worker-sessions.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/auth-next/yahoo-oauth.js b/auth-next/yahoo-oauth.js index 83531eae..389ed305 100644 --- a/auth-next/yahoo-oauth.js +++ b/auth-next/yahoo-oauth.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/firestore-next/emulator-suite.js b/firestore-next/emulator-suite.js index 05997344..cbcea744 100644 --- a/firestore-next/emulator-suite.js +++ b/firestore-next/emulator-suite.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] function onDocumentReady(firebaseApp) { diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 98e856ed..2401ee35 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] const { expect } = require('chai'); diff --git a/firestore-next/test.solution-aggregation.js b/firestore-next/test.solution-aggregation.js index 06556023..f56f0b57 100644 --- a/firestore-next/test.solution-aggregation.js +++ b/firestore-next/test.solution-aggregation.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] // [START sample_doc] diff --git a/firestore-next/test.solution-arrays.js b/firestore-next/test.solution-arrays.js index 5353b7ed..15dd78e8 100644 --- a/firestore-next/test.solution-arrays.js +++ b/firestore-next/test.solution-arrays.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] const postsWithArray = [ diff --git a/firestore-next/test.solution-counters.js b/firestore-next/test.solution-counters.js index 9f6b2c37..fc284092 100644 --- a/firestore-next/test.solution-counters.js +++ b/firestore-next/test.solution-counters.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] const { FirebaseFirestore } = require('firebase/firestore'); diff --git a/firestore-next/test.solution-geoqueries.js b/firestore-next/test.solution-geoqueries.js index 9560623b..eb9f21fe 100644 --- a/firestore-next/test.solution-geoqueries.js +++ b/firestore-next/test.solution-geoqueries.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] const { FirebaseFirestore } = require('firebase/firestore'); diff --git a/functions-next/callable.js b/functions-next/callable.js index 9c5065bf..193a3c2e 100644 --- a/functions-next/callable.js +++ b/functions-next/callable.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] export function callAddMessage(firebaseApp) { diff --git a/functions-next/emulator-suite.js b/functions-next/emulator-suite.js index db085b57..d19fea7d 100644 --- a/functions-next/emulator-suite.js +++ b/functions-next/emulator-suite.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/perf-next/index.js b/perf-next/index.js index af6a08db..7b7f7b5f 100644 --- a/perf-next/index.js +++ b/perf-next/index.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/remoteconfig-next/index.js b/remoteconfig-next/index.js index b5240973..364bcd17 100644 --- a/remoteconfig-next/index.js +++ b/remoteconfig-next/index.js @@ -1,4 +1,4 @@ -// [SNIPPETS_REGISTRY disabled] +// [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] import { initializeApp } from "firebase/app"; diff --git a/scripts/separate-snippets.ts b/scripts/separate-snippets.ts index 575d08fe..4705e9ab 100644 --- a/scripts/separate-snippets.ts +++ b/scripts/separate-snippets.ts @@ -1,3 +1,5 @@ +// [SNIPPET_REGISTRY disabled] + import * as cp from "child_process"; import * as fs from "fs"; import * as path from "path"; From fbc53e4331afd144e6df65cfb71e26a93f5dda4c Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 16 Dec 2020 10:42:13 +0000 Subject: [PATCH 050/235] Fix package.json for auth-next --- auth-next/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth-next/package.json b/auth-next/package.json index 3b90165e..058a14c8 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^0.900.4" + "firebase": "exp" } } From ef0af0f5f19a6ea5745c324307bf4fce0d6c7071 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 17 Dec 2020 10:04:01 +0000 Subject: [PATCH 051/235] Fix geo typos --- firestore-next/test.solution-geoqueries.js | 2 +- firestore/test.solution-geoqueries.js | 4 ++-- .../test-solution-geoqueries/fs_geo_query_hashes.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore-next/test.solution-geoqueries.js b/firestore-next/test.solution-geoqueries.js index eb9f21fe..a948733c 100644 --- a/firestore-next/test.solution-geoqueries.js +++ b/firestore-next/test.solution-geoqueries.js @@ -38,7 +38,7 @@ async function queryHashes(done) { const radiusInKm = 50; // Each item in 'bounds' represents a startAt/endAt pair. We have to issue - // a separate query for each pair. There can be up to 9 pais of bounds + // a separate query for each pair. There can be up to 9 pairs of bounds // depending on overlap, but in most cases there are 4. const bounds = geofire.geohashQueryBounds(center, radiusInKm); const promises = []; diff --git a/firestore/test.solution-geoqueries.js b/firestore/test.solution-geoqueries.js index 73465b84..7ec90b74 100644 --- a/firestore/test.solution-geoqueries.js +++ b/firestore/test.solution-geoqueries.js @@ -16,7 +16,7 @@ function addHash(done) { const lng = 0.1278; const hash = geofire.geohashForLocation([lat, lng]); - // Add the h and the lat/lng to the document. We will use the hash + // Add the hash and the lat/lng to the document. We will use the hash // for queries and the lat/lng for distance comparisons. const londonRef = db.collection('cities').doc('LON'); londonRef.update({ @@ -38,7 +38,7 @@ function queryHashes(done) { const radiusInKm = 50; // Each item in 'bounds' represents a startAt/endAt pair. We have to issue - // a separate query for each pair. There can be up to 9 pais of bounds + // a separate query for each pair. There can be up to 9 pairs of bounds // depending on overlap, but in most cases there are 4. const bounds = geofire.geohashQueryBounds(center, radiusInKm); const promises = []; diff --git a/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js b/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js index 2de46c75..fd213fb3 100644 --- a/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js +++ b/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js @@ -11,7 +11,7 @@ const center = [51.5074, 0.1278]; const radiusInKm = 50; // Each item in 'bounds' represents a startAt/endAt pair. We have to issue -// a separate query for each pair. There can be up to 9 pais of bounds +// a separate query for each pair. There can be up to 9 pairs of bounds // depending on overlap, but in most cases there are 4. const bounds = geofire.geohashQueryBounds(center, radiusInKm); const promises = []; From 14027d058ae910cf2c7578531cde1ef9b1e17c5d Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 21 Dec 2020 02:46:58 -0800 Subject: [PATCH 052/235] Auto-update dependencies. (#73) --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/auth/package.json b/auth/package.json index 77466264..97182df1 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.0", + "firebase": "^8.2.1", "firebaseui": "^4.7.1" } } diff --git a/database/package.json b/database/package.json index 529a6030..2c58101a 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.0" + "firebase": "^8.2.1" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index e531cfc0..0780a79c 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.0" + "firebase": "^8.2.1" } } diff --git a/firestore/package.json b/firestore/package.json index 87002065..3800a011 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.0", + "firebase": "^8.2.1", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index cb6724d1..b9ba6340 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.0" + "firebase": "^8.2.1" } } diff --git a/installations/package.json b/installations/package.json index 7ebf0472..0b8ea7ef 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.0" + "firebase": "^8.2.1" } } diff --git a/perf/package.json b/perf/package.json index 281beee7..d27b16ab 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.0" + "firebase": "^8.2.1" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 1177c27d..fb9b928b 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.0" + "firebase": "^8.2.1" } } From f4fd1d2d260762d1e0b4a550cc29b82b38818041 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 21 Dec 2020 05:18:31 -0800 Subject: [PATCH 053/235] Auto-update dependencies. (#74) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index f79e54d4..7c5911bb 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From 6acc24ed7382d6c7ef802463c6914e2912da6dcc Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 23 Dec 2020 15:18:54 +0000 Subject: [PATCH 054/235] Add basic eslint --- .eslintrc.json | 19 +++++++++++++++++++ .github/workflows/test.yml | 3 +++ package.json | 3 +++ 3 files changed, 25 insertions(+) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..2a16144c --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,19 @@ +{ + "env": { + "browser": true, + "commonjs": true, + "es2021": true + }, + "parserOptions": { + "ecmaVersion": 12, + "sourceType": "module" + }, + "rules": { + "arrow-parens": ["error", "always"], + "arrow-spacing": ["error"], + "no-const-assign": ["error"], + "prefer-const": ["error"], + "spaced-comment": ["error", "always"], + "semi": ["error", "always"] + } +} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f2ac9c9e..b619cd36 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,6 +31,9 @@ jobs: npm install npm run lerna-bootstrap + - name: Lint snippets + run: npm run lint + - name: Compile snippets run: npm run lerna-compile diff --git a/package.json b/package.json index 641918cb..5722ddaa 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,14 @@ "version": "1.0.0", "scripts": { "snippets": "npx ts-node scripts/separate-snippets.ts", + "lint": "git ls-files | grep -v 'snippets/' | grep '.js$' | xargs npx eslint", + "format": "npm run lint -- --fix", "lerna-bootstrap": "lerna bootstrap --no-ci", "lerna-compile": "lerna run compile" }, "license": "Apache-2.0", "devDependencies": { + "eslint": "^7.16.0", "lerna": "^3.22.1", "ts-node": "^9.0.0", "typescript": "^3.8.3" From 578630d2a2299f635ed49d167ed7bb246ec23b70 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 23 Dec 2020 15:19:22 +0000 Subject: [PATCH 055/235] Fix lint errors --- auth-next/anonymous.js | 2 +- auth-next/custom.js | 2 +- auth-next/link-multiple-accounts.js | 10 ++-- auth-next/service-worker-sessions.js | 6 +- auth/anonymous.js | 2 +- auth/custom.js | 2 +- auth/firebaseui.js | 4 +- auth/link-multiple-accounts.js | 10 ++-- auth/service-worker-sessions.js | 6 +- database/emulator-suite.js | 4 +- database/read-and-write.js | 2 +- firestore-next/test.firestore.js | 18 +++--- firestore-next/test.solution-aggregation.js | 4 +- firestore-next/test.solution-arrays.js | 2 +- firestore-next/test.solution-counters.js | 4 +- firestore-next/test.solution-geoqueries.js | 2 +- firestore/emulator-suite.js | 2 +- firestore/test.firestore.js | 62 ++++++++++----------- firestore/test.solution-aggregation.js | 6 +- firestore/test.solution-arrays.js | 8 +-- firestore/test.solution-counters.js | 10 ++-- firestore/test.solution-geoqueries.js | 4 +- 22 files changed, 86 insertions(+), 86 deletions(-) diff --git a/auth-next/anonymous.js b/auth-next/anonymous.js index ff8967b2..95b175c3 100644 --- a/auth-next/anonymous.js +++ b/auth-next/anonymous.js @@ -22,6 +22,6 @@ function anonSignIn() { const errorCode = error.code; const errorMessage = error.message; // ... - }) + }); // [END auth_anon_sign_in] } diff --git a/auth-next/custom.js b/auth-next/custom.js index f16f8ab6..c85db493 100644 --- a/auth-next/custom.js +++ b/auth-next/custom.js @@ -25,6 +25,6 @@ function signInCustom() { const errorCode = error.code; const errorMessage = error.message; // ... - }) + }); // [END auth_sign_in_custom] } diff --git a/auth-next/link-multiple-accounts.js b/auth-next/link-multiple-accounts.js index 764b499f..c8dd003c 100644 --- a/auth-next/link-multiple-accounts.js +++ b/auth-next/link-multiple-accounts.js @@ -16,21 +16,21 @@ MyUserDataRepo.prototype.merge = function(data1, data2) { return { ...data1, ...data2, - } -} + }; +}; MyUserDataRepo.prototype.set = function(user, data) { // TODO(you): How you implement this is specific to your application! -} +}; MyUserDataRepo.prototype.delete = function(user) { // TODO(you): How you implement this is specific to your application! -} +}; MyUserDataRepo.prototype.get = function(user) { // TODO(you): How you implement this is specific to your application! return {}; -} +}; function getProviders() { // [START auth_get_providers] diff --git a/auth-next/service-worker-sessions.js b/auth-next/service-worker-sessions.js index 90dc15fe..3be8c82d 100644 --- a/auth-next/service-worker-sessions.js +++ b/auth-next/service-worker-sessions.js @@ -94,7 +94,7 @@ function svcIntercept() { self.addEventListener('fetch', (event) => { /** @type {FetchEvent} */ - let evt = event; + const evt = event; const requestProcessor = (idToken) => { let req = evt.request; @@ -108,7 +108,7 @@ function svcIntercept() { const headers = new Headers(); req.headers.forEach((val, key) => { headers.append(key, val); - }) + }); // Add ID token to header. headers.append('Authorization', 'Bearer ' + idToken); processRequestPromise = getBodyContent(req).then((body) => { @@ -145,7 +145,7 @@ function svcIntercept() { function svcListenActivate(clients) { // [START auth_svc_listen_activate] - self.addEventListener('activate', event => { + self.addEventListener('activate', (event) => { event.waitUntil(clients.claim()); }); // [END auth_svc_listen_activate] diff --git a/auth/anonymous.js b/auth/anonymous.js index 42d817dc..ee618c3d 100644 --- a/auth/anonymous.js +++ b/auth/anonymous.js @@ -14,6 +14,6 @@ function anonSignIn() { var errorCode = error.code; var errorMessage = error.message; // ... - }) + }); // [END auth_anon_sign_in] } diff --git a/auth/custom.js b/auth/custom.js index 1d1a6037..dc02990e 100644 --- a/auth/custom.js +++ b/auth/custom.js @@ -16,6 +16,6 @@ function signInCustom() { var errorCode = error.code; var errorMessage = error.message; // ... - }) + }); // [END auth_sign_in_custom] } diff --git a/auth/firebaseui.js b/auth/firebaseui.js index fde03e67..2a359d5a 100644 --- a/auth/firebaseui.js +++ b/auth/firebaseui.js @@ -4,7 +4,7 @@ import firebase from "firebase/app"; import "firebase/auth"; -import * as firebaseui from "firebaseui" +import * as firebaseui from "firebaseui"; // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/firebaseui.md @@ -189,7 +189,7 @@ function fuiStartPhoneOptions() { recaptchaParameters: { type: 'image', // 'audio' size: 'normal', // 'invisible' or 'compact' - badge: 'bottomleft' //' bottomright' or 'inline' applies to invisible. + badge: 'bottomleft' // ' bottomright' or 'inline' applies to invisible. }, defaultCountry: 'GB', // Set default country to the United Kingdom (+44). // For prefilling the national number, set defaultNationNumber. diff --git a/auth/link-multiple-accounts.js b/auth/link-multiple-accounts.js index a0a53f70..b6419431 100644 --- a/auth/link-multiple-accounts.js +++ b/auth/link-multiple-accounts.js @@ -13,21 +13,21 @@ MyUserDataRepo.prototype.merge = function(data1, data2) { return { ...data1, ...data2, - } -} + }; +}; MyUserDataRepo.prototype.set = function(user, data) { // TODO(you): How you implement this is specific to your application! -} +}; MyUserDataRepo.prototype.delete = function(user) { // TODO(you): How you implement this is specific to your application! -} +}; MyUserDataRepo.prototype.get = function(user) { // TODO(you): How you implement this is specific to your application! return {}; -} +}; function getProviders() { // [START auth_get_providers] diff --git a/auth/service-worker-sessions.js b/auth/service-worker-sessions.js index b151374c..babbf91e 100644 --- a/auth/service-worker-sessions.js +++ b/auth/service-worker-sessions.js @@ -82,7 +82,7 @@ function svcIntercept() { self.addEventListener('fetch', (event) => { /** @type {FetchEvent} */ - let evt = event; + const evt = event; const requestProcessor = (idToken) => { let req = evt.request; @@ -96,7 +96,7 @@ function svcIntercept() { const headers = new Headers(); req.headers.forEach((val, key) => { headers.append(key, val); - }) + }); // Add ID token to header. headers.append('Authorization', 'Bearer ' + idToken); processRequestPromise = getBodyContent(req).then((body) => { @@ -133,7 +133,7 @@ function svcIntercept() { function svcListenActivate(clients) { // [START auth_svc_listen_activate] - self.addEventListener('activate', event => { + self.addEventListener('activate', (event) => { event.waitUntil(clients.claim()); }); // [END auth_svc_listen_activate] diff --git a/database/emulator-suite.js b/database/emulator-suite.js index a900cb6e..8fe739e4 100644 --- a/database/emulator-suite.js +++ b/database/emulator-suite.js @@ -6,7 +6,7 @@ import firebase from "firebase/app"; import "firebase/database"; function onDocumentReady() { - //[START rtdb_emulator_connect] + // [START rtdb_emulator_connect] var db = firebase.database(); if (location.hostname === "localhost") { // Point to the RTDB emulator running on localhost. @@ -16,7 +16,7 @@ function onDocumentReady() { } function flushRealtimeDatabase() { - //[START rtdb_emulator_flush] + // [START rtdb_emulator_flush] // With a database Reference, write null to clear the database. firebase.database().ref().set(null); // [END rtdb_emulator_flush] diff --git a/database/read-and-write.js b/database/read-and-write.js index c2de45a9..24b87b61 100644 --- a/database/read-and-write.js +++ b/database/read-and-write.js @@ -39,7 +39,7 @@ function socialListenStarCount() { // [START rtdb_social_listen_star_count] var starCountRef = firebase.database().ref('posts/' + postId + '/starCount'); - starCountRef.on('value', (snapshot) =>{ + starCountRef.on('value', (snapshot) => { const data = snapshot.val(); updateStarCount(postElement, data); }); diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 2401ee35..445f35b3 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -22,13 +22,13 @@ var cityConverter = { name: city.name, state: city.state, country: city.country - } + }; }, fromFirestore: function(snapshot, options){ const data = snapshot.data(options); - return new City(data.name, data.state, data.country) + return new City(data.name, data.state, data.country); } -} +}; // [END city_custom_object] describe("firestore", () => { @@ -107,7 +107,7 @@ describe("firestore", () => { // [START enable_network] const { enableNetwork } = require("firebase/firestore"); - await enableNetwork(db) + await enableNetwork(db); // Do online actions // [START_EXCLUDE] console.log("Network enabled!"); @@ -191,7 +191,7 @@ describe("firestore", () => { const unsubscribe = onSnapshot(q, (snapshot) => { console.log("Current users born before 1900:"); snapshot.forEach(function (userSnapshot) { - console.log(userSnapshot.data()) + console.log(userSnapshot.data()); }); }); // [END listen_for_users] @@ -224,7 +224,7 @@ describe("firestore", () => { const alovelaceDocumentRef = doc(db, 'users/alovelace'); // [END doc_reference_alternative] - }) + }); it("should reference a document in a subcollection", () => { // [START subcollection_reference] @@ -269,7 +269,7 @@ describe("firestore", () => { // Use a City instance method console.log(city.toString()); } else { - console.log("No such document!") + console.log("No such document!"); } // [END get_custom_object] }); @@ -358,7 +358,7 @@ describe("firestore", () => { const { collection, query, orderBy, limit, getDocs, writeBatch } = require("firebase/firestore"); function deleteCollection(db, collectionRef, batchSize) { - const q = query(collectionRef, orderBy('__name__'), limit(batchSize)) + const q = query(collectionRef, orderBy('__name__'), limit(batchSize)); return new Promise(function(resolve) { deleteQueryBatch(db, q, batchSize, resolve); @@ -506,7 +506,7 @@ describe("firestore", () => { population: increment(50) }); // [END update_document_increment] - }) + }); it("should delete a document", async () => { // [START delete_document] diff --git a/firestore-next/test.solution-aggregation.js b/firestore-next/test.solution-aggregation.js index f56f0b57..82e1d602 100644 --- a/firestore-next/test.solution-aggregation.js +++ b/firestore-next/test.solution-aggregation.js @@ -6,7 +6,7 @@ const arinellDoc = { name: 'Arinell Pizza', avgRating: 4.65, numRatings: 683 -} +}; // [END sample_doc] describe("firestore-solution-arrays", () => { @@ -38,6 +38,6 @@ describe("firestore-solution-arrays", () => { const ratingsRef = collection(doc(collection(db, "restaurants"), "arinell-pizza"), "ratings"); const ratingsDocs = await getDocs(ratingsRef); // [END get_collection_ratings] - }) + }); }); }); diff --git a/firestore-next/test.solution-arrays.js b/firestore-next/test.solution-arrays.js index 15dd78e8..7986ef6f 100644 --- a/firestore-next/test.solution-arrays.js +++ b/firestore-next/test.solution-arrays.js @@ -41,7 +41,7 @@ const postsWithMapAdvanced = [ } } // [END post_with_map_advanced] -] +]; describe("firestore-solution-arrays", () => { const { FirebaseFirestore } = require("firebase/firestore"); diff --git a/firestore-next/test.solution-counters.js b/firestore-next/test.solution-counters.js index fc284092..a76cfc24 100644 --- a/firestore-next/test.solution-counters.js +++ b/firestore-next/test.solution-counters.js @@ -47,7 +47,7 @@ async function getCount(ref) { const snapshot = await getDocs(collection(ref, 'shards')); let totalCount = 0; - snapshot.forEach(doc => { + snapshot.forEach((doc) => { totalCount += doc.data().count; }); @@ -82,7 +82,7 @@ describe("firestore-solution-counters", () => { const { collection, doc } = require("firebase/firestore"); const ref = doc(collection(db, 'counters')); - await createCounter(ref, 10) + await createCounter(ref, 10); await incrementCounter(db, ref, 10); }); diff --git a/firestore-next/test.solution-geoqueries.js b/firestore-next/test.solution-geoqueries.js index a948733c..c9497478 100644 --- a/firestore-next/test.solution-geoqueries.js +++ b/firestore-next/test.solution-geoqueries.js @@ -89,7 +89,7 @@ describe("firestore-solution-geoqueries", () => { describe("solution-geoqueries", () => { it("should add a hash to a doc", (done) => { - addHash(done) + addHash(done); }); it("should query hashes", (done) => { diff --git a/firestore/emulator-suite.js b/firestore/emulator-suite.js index 49d0ae5c..714d38e7 100644 --- a/firestore/emulator-suite.js +++ b/firestore/emulator-suite.js @@ -2,7 +2,7 @@ import firebase from "firebase/app"; import 'firebase/firestore'; function onDocumentReady() { - //[START fs_emulator_connect] + // [START fs_emulator_connect] // Firebase previously initialized using firebase.initializeApp(). var db = firebase.firestore(); if (location.hostname === "localhost") { diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index 66ade99b..d2c7602d 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -22,13 +22,13 @@ var cityConverter = { name: city.name, state: city.state, country: city.country - } + }; }, fromFirestore: function(snapshot, options){ const data = snapshot.data(options); - return new City(data.name, data.state, data.country) + return new City(data.name, data.state, data.country); } -} +}; // [END city_custom_object] describe("firestore", () => { @@ -41,7 +41,7 @@ describe("firestore", () => { }; var app = firebase.initializeApp(config); db = firebase.firestore(app); - //firebase.firestore.setLogLevel("debug"); + // firebase.firestore.setLogLevel("debug"); }); it("should be able to set the cache size", () => { @@ -179,7 +179,7 @@ describe("firestore", () => { .onSnapshot(function(snapshot) { console.log("Current users born before 1900:"); snapshot.forEach(function (userSnapshot) { - console.log(userSnapshot.data()) + console.log(userSnapshot.data()); }); }); // [END listen_for_users] @@ -206,7 +206,7 @@ describe("firestore", () => { // [START doc_reference_alternative] var alovelaceDocumentRef = db.doc('users/alovelace'); // [END doc_reference_alternative] - }) + }); it("should reference a document in a subcollection", () => { // [START subcollection_reference] @@ -257,9 +257,9 @@ describe("firestore", () => { // Use a City instance method console.log(city.toString()); } else { - console.log("No such document!") + console.log("No such document!"); }}).catch(function(error) { - console.log("Error getting document:", error) + console.log("Error getting document:", error); }); // [END get_custom_object] return output; @@ -505,7 +505,7 @@ describe("firestore", () => { population: firebase.firestore.FieldValue.increment(50) }); // [END update_document_increment] - }) + }); it("should delete a document", () => { var output = @@ -695,7 +695,7 @@ describe("firestore", () => { }); // [END get_multiple_all] return output; - }) + }); it("should listen on multiple documents #UNVERIFIED", (done) => { var unsubscribe = @@ -759,9 +759,9 @@ describe("firestore", () => { // [START handle_listen_errors] db.collection("cities") .onSnapshot(function(snapshot) { - //... + // ... }, function(error) { - //... + // ... }); // [END handle_listen_errors] unsubscribe(); @@ -856,9 +856,9 @@ describe("firestore", () => { it("should handle other wheres", () => { var citiesRef = db.collection("cities"); // [START example_filters] - citiesRef.where("state", "==", "CA") - citiesRef.where("population", "<", 100000) - citiesRef.where("name", ">=", "San Francisco") + citiesRef.where("state", "==", "CA"); + citiesRef.where("population", "<", 100000); + citiesRef.where("name", ">=", "San Francisco"); // [END example_filters] // [START simple_query_not_equal] @@ -869,7 +869,7 @@ describe("firestore", () => { it("should handle array-contains where", () => { var citiesRef = db.collection("cities"); // [START array_contains_filter] - citiesRef.where("regions", "array-contains", "west_coast") + citiesRef.where("regions", "array-contains", "west_coast"); // [END array_contains_filter] }); @@ -925,35 +925,35 @@ describe("firestore", () => { it("should order and limit", () => { var citiesRef = db.collection("cities"); // [START order_and_limit] - citiesRef.orderBy("name").limit(3) + citiesRef.orderBy("name").limit(3); // [END order_and_limit] }); it("should order descending", () => { var citiesRef = db.collection("cities"); // [START order_and_limit_desc] - citiesRef.orderBy("name", "desc").limit(3) + citiesRef.orderBy("name", "desc").limit(3); // [END order_and_limit_desc] }); it("should order descending by other field", () => { var citiesRef = db.collection("cities"); // [START order_multiple] - citiesRef.orderBy("state").orderBy("population", "desc") + citiesRef.orderBy("state").orderBy("population", "desc"); // [END order_multiple] }); it("should where and order by with limit", () => { var citiesRef = db.collection("cities"); // [START filter_and_order] - citiesRef.where("population", ">", 100000).orderBy("population").limit(2) + citiesRef.where("population", ">", 100000).orderBy("population").limit(2); // [END filter_and_order] }); it("should where and order on same field", () => { var citiesRef = db.collection("cities"); // [START valid_filter_and_order] - citiesRef.where("population", ">", 100000).orderBy("population") + citiesRef.where("population", ">", 100000).orderBy("population"); // [END valid_filter_and_order] }); @@ -961,7 +961,7 @@ describe("firestore", () => { var citiesRef = db.collection("cities"); expect(() => { // [START invalid_filter_and_order] - citiesRef.where("population", ">", 100000).orderBy("country") + citiesRef.where("population", ">", 100000).orderBy("country"); // [END invalid_filter_and_order] }).to.throw; }); @@ -969,14 +969,14 @@ describe("firestore", () => { it("should handle startAt", () => { var citiesRef = db.collection("cities"); // [START order_and_start] - citiesRef.orderBy("population").startAt(1000000) + citiesRef.orderBy("population").startAt(1000000); // [END order_and_start] }); it("should handle endAt", () => { var citiesRef = db.collection("cities"); // [START order_and_end] - citiesRef.orderBy("population").endAt(1000000) + citiesRef.orderBy("population").endAt(1000000); // [END order_and_end] }); @@ -1001,13 +1001,13 @@ describe("firestore", () => { db.collection("cities") .orderBy("name") .orderBy("state") - .startAt("Springfield") + .startAt("Springfield"); // Will return "Springfield, Missouri" and "Springfield, Wisconsin" db.collection("cities") .orderBy("name") .orderBy("state") - .startAt("Springfield", "Missouri") + .startAt("Springfield", "Missouri"); // [END start_multiple_orderby] }); @@ -1106,8 +1106,8 @@ describe("firestore", () => { var ratingRef = restaurantRef.collection('ratings').doc(); // In a transaction, add the new rating and update the aggregate totals - return db.runTransaction(transaction => { - return transaction.get(restaurantRef).then(res => { + return db.runTransaction((transaction) => { + return transaction.get(restaurantRef).then((res) => { if (!res.exists) { throw "Document does not exist!"; } @@ -1125,7 +1125,7 @@ describe("firestore", () => { avgRating: newAvgRating }); transaction.set(ratingRef, { rating: rating }); - }) + }); }); } // [END add_rating_transaction] @@ -1136,8 +1136,8 @@ describe("firestore", () => { name: 'Arinell Pizza', avgRating: 4.63, numRatings: 683 - }).then(res => { - return addRating(ref, 5.0) + }).then((res) => { + return addRating(ref, 5.0); }); }); }); diff --git a/firestore/test.solution-aggregation.js b/firestore/test.solution-aggregation.js index 4895e8ff..571498a9 100644 --- a/firestore/test.solution-aggregation.js +++ b/firestore/test.solution-aggregation.js @@ -6,7 +6,7 @@ var arinellDoc = { name: 'Arinell Pizza', avgRating: 4.65, numRatings: 683 -} +}; // [END sample_doc] describe("firestore-solution-arrays", () => { @@ -31,8 +31,8 @@ describe("firestore-solution-arrays", () => { db.collection("restaurants") .doc("arinell-pizza") .collection("ratings") - .get() + .get(); // [END get_collection_ratings] - }) + }); }); }); diff --git a/firestore/test.solution-arrays.js b/firestore/test.solution-arrays.js index 74bf17c7..8a1ee65b 100644 --- a/firestore/test.solution-arrays.js +++ b/firestore/test.solution-arrays.js @@ -1,7 +1,7 @@ import firebase from 'firebase/app'; import 'firebase/firestore'; -let postsWithArray = [ +const postsWithArray = [ // [START post_with_array] // Sample document in the 'posts' collection. { @@ -15,7 +15,7 @@ let postsWithArray = [ // [END post_with_array] ]; -let postsWithMap = [ +const postsWithMap = [ // [START post_with_map] // Sample document in the 'posts' collection { @@ -29,7 +29,7 @@ let postsWithMap = [ // [END post_with_map] ]; -let postsWithMapAdvanced = [ +const postsWithMapAdvanced = [ // [START post_with_map_advanced] // The value of each entry in 'categories' is a unix timestamp { @@ -41,7 +41,7 @@ let postsWithMapAdvanced = [ } } // [END post_with_map_advanced] -] +]; describe("firestore-solution-arrays", () => { var db; diff --git a/firestore/test.solution-counters.js b/firestore/test.solution-counters.js index c9eed2c4..c8c62fe6 100644 --- a/firestore/test.solution-counters.js +++ b/firestore/test.solution-counters.js @@ -12,7 +12,7 @@ function createCounter(ref, num_shards) { // Initialize each shard with count=0 for (let i = 0; i < num_shards; i++) { - let shardRef = ref.collection('shards').doc(i.toString()); + const shardRef = ref.collection('shards').doc(i.toString()); batch.set(shardRef, { count: 0 }); } @@ -35,9 +35,9 @@ function incrementCounter(db, ref, num_shards) { // [START get_count] function getCount(ref) { // Sum the count of each shard in the subcollection - return ref.collection('shards').get().then(snapshot => { + return ref.collection('shards').get().then((snapshot) => { let total_count = 0; - snapshot.forEach(doc => { + snapshot.forEach((doc) => { total_count += doc.data().count; }); @@ -65,7 +65,7 @@ describe("firestore-solution-counters", () => { it("should increment a counter", () => { // Create a counter, then increment it - let ref = db.collection('counters').doc(); + const ref = db.collection('counters').doc(); return createCounter(ref, 10).then(() => { return incrementCounter(db, ref, 10); }); @@ -73,7 +73,7 @@ describe("firestore-solution-counters", () => { it("should get the count of a counter", () => { // Create a counter, increment it, then get the count - let ref = db.collection('counters').doc(); + const ref = db.collection('counters').doc(); return createCounter(ref, 10).then(() => { return incrementCounter(db, ref, 10); }).then(() => { diff --git a/firestore/test.solution-geoqueries.js b/firestore/test.solution-geoqueries.js index 7ec90b74..4464f1ad 100644 --- a/firestore/test.solution-geoqueries.js +++ b/firestore/test.solution-geoqueries.js @@ -75,7 +75,7 @@ function queryHashes(done) { // [START_EXCLUDE] done(matchingDocs); // [END_EXCLUDE] - }) + }); // [END fs_geo_query_hashes] } @@ -93,7 +93,7 @@ describe("firestore-solution-geoqueries", () => { describe("solution-geoqueries", () => { it("should add a hash to a doc", (done) => { - addHash(done) + addHash(done); }); it("should query hashes", (done) => { From ad7c85424c44ba5f4e62dc729e87e1482694c1d2 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 23 Dec 2020 15:19:42 +0000 Subject: [PATCH 056/235] Regenerate snippets --- snippets/auth-next/anonymous/auth_anon_sign_in.js | 2 +- snippets/auth-next/custom/auth_sign_in_custom.js | 2 +- .../auth-next/service-worker-sessions/auth_svc_intercept.js | 4 ++-- .../service-worker-sessions/auth_svc_listen_activate.js | 2 +- .../firestore-next/test-firestore/city_custom_object.js | 6 +++--- snippets/firestore-next/test-firestore/delete_collection.js | 2 +- snippets/firestore-next/test-firestore/enable_network.js | 2 +- snippets/firestore-next/test-firestore/get_custom_object.js | 2 +- snippets/firestore-next/test-firestore/listen_for_users.js | 2 +- .../firestore-next/test-solution-aggregation/sample_doc.js | 2 +- snippets/firestore-next/test-solution-counters/get_count.js | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/snippets/auth-next/anonymous/auth_anon_sign_in.js b/snippets/auth-next/anonymous/auth_anon_sign_in.js index f9c8f8e9..7195632f 100644 --- a/snippets/auth-next/anonymous/auth_anon_sign_in.js +++ b/snippets/auth-next/anonymous/auth_anon_sign_in.js @@ -15,5 +15,5 @@ signInAnonymously(auth) const errorCode = error.code; const errorMessage = error.message; // ... - }) + }); // [END auth_anon_sign_in_modular] \ No newline at end of file diff --git a/snippets/auth-next/custom/auth_sign_in_custom.js b/snippets/auth-next/custom/auth_sign_in_custom.js index 0e14145f..c22ed725 100644 --- a/snippets/auth-next/custom/auth_sign_in_custom.js +++ b/snippets/auth-next/custom/auth_sign_in_custom.js @@ -16,5 +16,5 @@ signInWithCustomToken(auth, token) const errorCode = error.code; const errorMessage = error.message; // ... - }) + }); // [END auth_sign_in_custom_modular] \ No newline at end of file diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_intercept.js b/snippets/auth-next/service-worker-sessions/auth_svc_intercept.js index 349ffd92..b14ccbed 100644 --- a/snippets/auth-next/service-worker-sessions/auth_svc_intercept.js +++ b/snippets/auth-next/service-worker-sessions/auth_svc_intercept.js @@ -32,7 +32,7 @@ const getBodyContent = (req) => { self.addEventListener('fetch', (event) => { /** @type {FetchEvent} */ - let evt = event; + const evt = event; const requestProcessor = (idToken) => { let req = evt.request; @@ -46,7 +46,7 @@ self.addEventListener('fetch', (event) => { const headers = new Headers(); req.headers.forEach((val, key) => { headers.append(key, val); - }) + }); // Add ID token to header. headers.append('Authorization', 'Bearer ' + idToken); processRequestPromise = getBodyContent(req).then((body) => { diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js b/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js index 9003240d..a51cfedb 100644 --- a/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js +++ b/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START auth_svc_listen_activate_modular] -self.addEventListener('activate', event => { +self.addEventListener('activate', (event) => { event.waitUntil(clients.claim()); }); // [END auth_svc_listen_activate_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/city_custom_object.js b/snippets/firestore-next/test-firestore/city_custom_object.js index 72e0ac32..4335d06e 100644 --- a/snippets/firestore-next/test-firestore/city_custom_object.js +++ b/snippets/firestore-next/test-firestore/city_custom_object.js @@ -22,11 +22,11 @@ var cityConverter = { name: city.name, state: city.state, country: city.country - } + }; }, fromFirestore: function(snapshot, options){ const data = snapshot.data(options); - return new City(data.name, data.state, data.country) + return new City(data.name, data.state, data.country); } -} +}; // [END city_custom_object_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/delete_collection.js b/snippets/firestore-next/test-firestore/delete_collection.js index 44768293..d9d6c70a 100644 --- a/snippets/firestore-next/test-firestore/delete_collection.js +++ b/snippets/firestore-next/test-firestore/delete_collection.js @@ -11,7 +11,7 @@ import { collection, query, orderBy, limit, getDocs, writeBatch } from "firebase/firestore"; function deleteCollection(db, collectionRef, batchSize) { - const q = query(collectionRef, orderBy('__name__'), limit(batchSize)) + const q = query(collectionRef, orderBy('__name__'), limit(batchSize)); return new Promise(function(resolve) { deleteQueryBatch(db, q, batchSize, resolve); diff --git a/snippets/firestore-next/test-firestore/enable_network.js b/snippets/firestore-next/test-firestore/enable_network.js index 7530c318..e6d59889 100644 --- a/snippets/firestore-next/test-firestore/enable_network.js +++ b/snippets/firestore-next/test-firestore/enable_network.js @@ -6,7 +6,7 @@ // [START enable_network_modular] import { enableNetwork } from "firebase/firestore"; -await enableNetwork(db) +await enableNetwork(db); // Do online actions // [START_EXCLUDE] console.log("Network enabled!"); diff --git a/snippets/firestore-next/test-firestore/get_custom_object.js b/snippets/firestore-next/test-firestore/get_custom_object.js index 3ec28381..92b27330 100644 --- a/snippets/firestore-next/test-firestore/get_custom_object.js +++ b/snippets/firestore-next/test-firestore/get_custom_object.js @@ -14,6 +14,6 @@ if (docSnap.exists()) { // Use a City instance method console.log(city.toString()); } else { - console.log("No such document!") + console.log("No such document!"); } // [END get_custom_object_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_for_users.js b/snippets/firestore-next/test-firestore/listen_for_users.js index 0e3ede36..4a8de4a9 100644 --- a/snippets/firestore-next/test-firestore/listen_for_users.js +++ b/snippets/firestore-next/test-firestore/listen_for_users.js @@ -10,7 +10,7 @@ const q = query(collection(db, "users"), where("born", "<", 1900)); const unsubscribe = onSnapshot(q, (snapshot) => { console.log("Current users born before 1900:"); snapshot.forEach(function (userSnapshot) { - console.log(userSnapshot.data()) + console.log(userSnapshot.data()); }); }); // [END listen_for_users_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-aggregation/sample_doc.js b/snippets/firestore-next/test-solution-aggregation/sample_doc.js index dfc54ebf..651b4d37 100644 --- a/snippets/firestore-next/test-solution-aggregation/sample_doc.js +++ b/snippets/firestore-next/test-solution-aggregation/sample_doc.js @@ -8,5 +8,5 @@ const arinellDoc = { name: 'Arinell Pizza', avgRating: 4.65, numRatings: 683 -} +}; // [END sample_doc_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-counters/get_count.js b/snippets/firestore-next/test-solution-counters/get_count.js index 04434fcd..614173c9 100644 --- a/snippets/firestore-next/test-solution-counters/get_count.js +++ b/snippets/firestore-next/test-solution-counters/get_count.js @@ -11,7 +11,7 @@ async function getCount(ref) { const snapshot = await getDocs(collection(ref, 'shards')); let totalCount = 0; - snapshot.forEach(doc => { + snapshot.forEach((doc) => { totalCount += doc.data().count; }); From d595de7d9b89b8504523f3c35a5e144a219e6c71 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Wed, 23 Dec 2020 08:21:20 -0800 Subject: [PATCH 057/235] Fix geofire meters / km mixup (#76) --- firestore-next/test.solution-geoqueries.js | 9 +++++---- firestore/test.solution-geoqueries.js | 10 +++++----- .../test-solution-geoqueries/fs_geo_query_hashes.js | 9 +++++---- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/firestore-next/test.solution-geoqueries.js b/firestore-next/test.solution-geoqueries.js index c9497478..1293229e 100644 --- a/firestore-next/test.solution-geoqueries.js +++ b/firestore-next/test.solution-geoqueries.js @@ -35,12 +35,12 @@ async function queryHashes(done) { // Find cities within 50km of London const center = [51.5074, 0.1278]; - const radiusInKm = 50; + const radiusInM = 50 * 1000; // Each item in 'bounds' represents a startAt/endAt pair. We have to issue // a separate query for each pair. There can be up to 9 pairs of bounds // depending on overlap, but in most cases there are 4. - const bounds = geofire.geohashQueryBounds(center, radiusInKm); + const bounds = geofire.geohashQueryBounds(center, radiusInM); const promises = []; for (const b of bounds) { const q = query( @@ -63,8 +63,9 @@ async function queryHashes(done) { // We have to filter out a few false positives due to GeoHash // accuracy, but most will match - const distance = geofire.distanceBetween([lat, lng], center); - if (distance <= radiusInKm) { + const distanceInKm = geofire.distanceBetween([lat, lng], center); + const distanceInM = distanceInKm * 1000; + if (distanceInM <= radiusInM) { matchingDocs.push(doc); } } diff --git a/firestore/test.solution-geoqueries.js b/firestore/test.solution-geoqueries.js index 4464f1ad..61cb13b5 100644 --- a/firestore/test.solution-geoqueries.js +++ b/firestore/test.solution-geoqueries.js @@ -10,7 +10,6 @@ var db; function addHash(done) { // [START fs_geo_add_hash] - // Compute the GeoHash for a lat/lng point const lat = 51.5074; const lng = 0.1278; @@ -35,12 +34,12 @@ function queryHashes(done) { // [START fs_geo_query_hashes] // Find cities within 50km of London const center = [51.5074, 0.1278]; - const radiusInKm = 50; + const radiusInM = 50 * 1000; // Each item in 'bounds' represents a startAt/endAt pair. We have to issue // a separate query for each pair. There can be up to 9 pairs of bounds // depending on overlap, but in most cases there are 4. - const bounds = geofire.geohashQueryBounds(center, radiusInKm); + const bounds = geofire.geohashQueryBounds(center, radiusInM); const promises = []; for (const b of bounds) { const q = db.collection('cities') @@ -62,8 +61,9 @@ function queryHashes(done) { // We have to filter out a few false positives due to GeoHash // accuracy, but most will match - const distance = geofire.distanceBetween([lat, lng], center); - if (distance <= radiusInKm) { + const distanceInKm = geofire.distanceBetween([lat, lng], center); + const distanceInM = distanceInKm * 1000; + if (distanceInM <= radiusInM) { matchingDocs.push(doc); } } diff --git a/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js b/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js index fd213fb3..1230a989 100644 --- a/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js +++ b/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js @@ -8,12 +8,12 @@ import { collection, query, orderBy, startAt, endAt, getDocs } from 'firebase/fi // Find cities within 50km of London const center = [51.5074, 0.1278]; -const radiusInKm = 50; +const radiusInM = 50 * 1000; // Each item in 'bounds' represents a startAt/endAt pair. We have to issue // a separate query for each pair. There can be up to 9 pairs of bounds // depending on overlap, but in most cases there are 4. -const bounds = geofire.geohashQueryBounds(center, radiusInKm); +const bounds = geofire.geohashQueryBounds(center, radiusInM); const promises = []; for (const b of bounds) { const q = query( @@ -36,8 +36,9 @@ for (const snap of snapshots) { // We have to filter out a few false positives due to GeoHash // accuracy, but most will match - const distance = geofire.distanceBetween([lat, lng], center); - if (distance <= radiusInKm) { + const distanceInKm = geofire.distanceBetween([lat, lng], center); + const distanceInM = distanceInKm * 1000; + if (distanceInM <= radiusInM) { matchingDocs.push(doc); } } From b1950d6c88a1875a46a1a3e2d27c70e373abfcd9 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 23 Dec 2020 18:37:16 +0000 Subject: [PATCH 058/235] Phone Auth snippets (current) --- auth/phone-auth.js | 118 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 auth/phone-auth.js diff --git a/auth/phone-auth.js b/auth/phone-auth.js new file mode 100644 index 00000000..f5d6981a --- /dev/null +++ b/auth/phone-auth.js @@ -0,0 +1,118 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// Mask the global 'window' for this snippet file +const window = { + recaptchaVerifier: undefined +}; + +function setLanguageCode() { + // [START auth_set_language_code] + firebase.auth().languageCode = 'it'; + // To apply the default browser preference instead of explicitly setting it. + // firebase.auth().useDeviceLanguage(); + // [END auth_set_language_code] +} + +function recaptchaVerifierInvisible() { + function onSignInSubmit() { + // TODO(you): Implement + } + + // [START auth_phone_recaptcha_verifier_invisible] + window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('sign-in-button', { + 'size': 'invisible', + 'callback': (response) => { + // reCAPTCHA solved, allow signInWithPhoneNumber. + onSignInSubmit(); + } + }); + // [END auth_phone_recaptcha_verifier_invisible] +} + +function recaptchaVerifierVisible() { + // [START auth_phone_recaptcha_verifier_visible] + window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container', { + 'size': 'normal', + 'callback': (response) => { + // reCAPTCHA solved, allow signInWithPhoneNumber. + // ... + }, + 'expired-callback': () => { + // Response expired. Ask user to solve reCAPTCHA again. + // ... + } + }); + // [END auth_phone_recaptcha_verifier_visible] +} + +function recaptchaVerifierSimple() { + // [START auth_phone_recaptcha_verifier_simple] + window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container'); + // [END auth_phone_recaptcha_verifier_simple] +} + +function recaptchaRender() { + /** @type {firebase.auth.RecaptchaVerifier} */ + const recaptchaVerifier = window.recaptchaVerifier; + + // [START auth_phone_recaptcha_render] + recaptchaVerifier.render().then((widgetId) => { + window.recaptchaWidgetId = widgetId; + }); + // [END auth_phone_recaptcha_render] +} + +function phoneSignIn() { + function getPhoneNumberFromUserInput() { + return "+15558675309"; + } + + // [START auth_phone_signin] + const phoneNumber = getPhoneNumberFromUserInput(); + const appVerifier = window.recaptchaVerifier; + firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier) + .then((confirmationResult) => { + // SMS sent. Prompt user to type the code from the message, then sign the + // user in with confirmationResult.confirm(code). + window.confirmationResult = confirmationResult; + // ... + }).catch((error) => { + // Error; SMS not sent + // ... + }); + // [END auth_phone_signin] +} + +function verifyCode() { + function getCodeFromUserInput() { + return "1234"; + } + + /** @type {firebase.auth.ConfirmationResult} */ + const confirmationResult = undefined; + + // [START auth_phone_verify_code] + const code = getCodeFromUserInput(); + confirmationResult.confirm(code).then((result) => { + // User signed in successfully. + const user = result.user; + // ... + }).catch((error) => { + // User couldn't sign in (bad verification code?) + // ... + }); + // [END auth_phone_verify_code] +} + +function getRecaptchaResponse() { + const recaptchaWidgetId = "..."; + const grecaptcha = {}; + + // [START auth_get_recaptcha_response] + const recaptchaResponse = grecaptcha.getResponse(recaptchaWidgetId); + // [END auth_get_recaptcha_response] +} From 21758bbbbe04aa0327c13790a074c425127073b1 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 23 Dec 2020 18:45:25 +0000 Subject: [PATCH 059/235] Phone auth vNext --- auth-next/phone-auth.js | 143 ++++++++++++++++++ .../phone-auth/auth_get_recaptcha_response.js | 8 + .../phone-auth/auth_phone_recaptcha_render.js | 10 ++ ...auth_phone_recaptcha_verifier_invisible.js | 17 +++ .../auth_phone_recaptcha_verifier_simple.js | 11 ++ .../auth_phone_recaptcha_verifier_visible.js | 21 +++ .../auth-next/phone-auth/auth_phone_signin.js | 23 +++ .../phone-auth/auth_phone_verify_code.js | 16 ++ .../phone-auth/auth_set_language_code.js | 13 ++ 9 files changed, 262 insertions(+) create mode 100644 auth-next/phone-auth.js create mode 100644 snippets/auth-next/phone-auth/auth_get_recaptcha_response.js create mode 100644 snippets/auth-next/phone-auth/auth_phone_recaptcha_render.js create mode 100644 snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js create mode 100644 snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js create mode 100644 snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js create mode 100644 snippets/auth-next/phone-auth/auth_phone_signin.js create mode 100644 snippets/auth-next/phone-auth/auth_phone_verify_code.js create mode 100644 snippets/auth-next/phone-auth/auth_set_language_code.js diff --git a/auth-next/phone-auth.js b/auth-next/phone-auth.js new file mode 100644 index 00000000..87917811 --- /dev/null +++ b/auth-next/phone-auth.js @@ -0,0 +1,143 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +// Mask the global 'window' for this snippet file +const window = { + recaptchaVerifier: undefined +}; + +function setLanguageCode() { + // [START auth_set_language_code] + const { getAuth } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + auth.languageCode = 'it'; + // To apply the default browser preference instead of explicitly setting it. + // firebase.auth().useDeviceLanguage(); + // [END auth_set_language_code] +} + +function recaptchaVerifierInvisible() { + function onSignInSubmit() { + // TODO(you): Implement + } + + // [START auth_phone_recaptcha_verifier_invisible] + const { getAuth, RecaptchaVerifier } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + window.recaptchaVerifier = new RecaptchaVerifier('sign-in-button', { + 'size': 'invisible', + 'callback': (response) => { + // reCAPTCHA solved, allow signInWithPhoneNumber. + onSignInSubmit(); + } + }, auth); + // [END auth_phone_recaptcha_verifier_invisible] +} + +function recaptchaVerifierVisible() { + // [START auth_phone_recaptcha_verifier_visible] + const { getAuth, RecaptchaVerifier } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', { + 'size': 'normal', + 'callback': (response) => { + // reCAPTCHA solved, allow signInWithPhoneNumber. + // ... + }, + 'expired-callback': () => { + // Response expired. Ask user to solve reCAPTCHA again. + // ... + } + }, auth); + // [END auth_phone_recaptcha_verifier_visible] +} + +function recaptchaVerifierSimple() { + // [START auth_phone_recaptcha_verifier_simple] + const { getAuth, RecaptchaVerifier } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', {}, auth); + // [END auth_phone_recaptcha_verifier_simple] +} + +function recaptchaRender() { + const { RecaptchaVerifier } = require("firebase/auth"); + + /** @type {RecaptchaVerifier} */ + const recaptchaVerifier = window.recaptchaVerifier; + + // [START auth_phone_recaptcha_render] + recaptchaVerifier.render().then((widgetId) => { + window.recaptchaWidgetId = widgetId; + }); + // [END auth_phone_recaptcha_render] +} + +function phoneSignIn() { + function getPhoneNumberFromUserInput() { + return "+15558675309"; + } + + // [START auth_phone_signin] + const { getAuth, signInWithPhoneNumber } = require("firebase/auth"); + + const phoneNumber = getPhoneNumberFromUserInput(); + const appVerifier = window.recaptchaVerifier; + + const auth = getAuth(firebaseApp); + signInWithPhoneNumber(auth, phoneNumber, appVerifier) + .then((confirmationResult) => { + // SMS sent. Prompt user to type the code from the message, then sign the + // user in with confirmationResult.confirm(code). + window.confirmationResult = confirmationResult; + // ... + }).catch((error) => { + // Error; SMS not sent + // ... + }); + // [END auth_phone_signin] +} + +function verifyCode() { + function getCodeFromUserInput() { + return "1234"; + } + + // TODO(samstern): Import ConfirmationResult type + /** @type {*} */ + const confirmationResult = undefined; + + // [START auth_phone_verify_code] + const code = getCodeFromUserInput(); + confirmationResult.confirm(code).then((result) => { + // User signed in successfully. + const user = result.user; + // ... + }).catch((error) => { + // User couldn't sign in (bad verification code?) + // ... + }); + // [END auth_phone_verify_code] +} + +function getRecaptchaResponse() { + const recaptchaWidgetId = "..."; + const grecaptcha = {}; + + // [START auth_get_recaptcha_response] + const recaptchaResponse = grecaptcha.getResponse(recaptchaWidgetId); + // [END auth_get_recaptcha_response] +} + diff --git a/snippets/auth-next/phone-auth/auth_get_recaptcha_response.js b/snippets/auth-next/phone-auth/auth_get_recaptcha_response.js new file mode 100644 index 00000000..83a31ed1 --- /dev/null +++ b/snippets/auth-next/phone-auth/auth_get_recaptcha_response.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/phone-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_get_recaptcha_response_modular] +const recaptchaResponse = grecaptcha.getResponse(recaptchaWidgetId); +// [END auth_get_recaptcha_response_modular] \ No newline at end of file diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_render.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_render.js new file mode 100644 index 00000000..0bbceb0d --- /dev/null +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_render.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/phone-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_phone_recaptcha_render_modular] +recaptchaVerifier.render().then((widgetId) => { + window.recaptchaWidgetId = widgetId; +}); +// [END auth_phone_recaptcha_render_modular] \ No newline at end of file diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js new file mode 100644 index 00000000..2be4c94b --- /dev/null +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/phone-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_phone_recaptcha_verifier_invisible_modular] +import { getAuth, RecaptchaVerifier } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +window.recaptchaVerifier = new RecaptchaVerifier('sign-in-button', { + 'size': 'invisible', + 'callback': (response) => { + // reCAPTCHA solved, allow signInWithPhoneNumber. + onSignInSubmit(); + } +}, auth); +// [END auth_phone_recaptcha_verifier_invisible_modular] \ No newline at end of file diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js new file mode 100644 index 00000000..e36af4f5 --- /dev/null +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/phone-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_phone_recaptcha_verifier_simple_modular] +import { getAuth, RecaptchaVerifier } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', {}, auth); +// [END auth_phone_recaptcha_verifier_simple_modular] \ No newline at end of file diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js new file mode 100644 index 00000000..a3f4e28c --- /dev/null +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/phone-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_phone_recaptcha_verifier_visible_modular] +import { getAuth, RecaptchaVerifier } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', { + 'size': 'normal', + 'callback': (response) => { + // reCAPTCHA solved, allow signInWithPhoneNumber. + // ... + }, + 'expired-callback': () => { + // Response expired. Ask user to solve reCAPTCHA again. + // ... + } +}, auth); +// [END auth_phone_recaptcha_verifier_visible_modular] \ No newline at end of file diff --git a/snippets/auth-next/phone-auth/auth_phone_signin.js b/snippets/auth-next/phone-auth/auth_phone_signin.js new file mode 100644 index 00000000..1c9ecb69 --- /dev/null +++ b/snippets/auth-next/phone-auth/auth_phone_signin.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/phone-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_phone_signin_modular] +import { getAuth, signInWithPhoneNumber } from "firebase/auth"; + +const phoneNumber = getPhoneNumberFromUserInput(); +const appVerifier = window.recaptchaVerifier; + +const auth = getAuth(firebaseApp); +signInWithPhoneNumber(auth, phoneNumber, appVerifier) + .then((confirmationResult) => { + // SMS sent. Prompt user to type the code from the message, then sign the + // user in with confirmationResult.confirm(code). + window.confirmationResult = confirmationResult; + // ... + }).catch((error) => { + // Error; SMS not sent + // ... + }); +// [END auth_phone_signin_modular] \ No newline at end of file diff --git a/snippets/auth-next/phone-auth/auth_phone_verify_code.js b/snippets/auth-next/phone-auth/auth_phone_verify_code.js new file mode 100644 index 00000000..51265141 --- /dev/null +++ b/snippets/auth-next/phone-auth/auth_phone_verify_code.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/phone-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_phone_verify_code_modular] +const code = getCodeFromUserInput(); +confirmationResult.confirm(code).then((result) => { + // User signed in successfully. + const user = result.user; + // ... +}).catch((error) => { + // User couldn't sign in (bad verification code?) + // ... +}); +// [END auth_phone_verify_code_modular] \ No newline at end of file diff --git a/snippets/auth-next/phone-auth/auth_set_language_code.js b/snippets/auth-next/phone-auth/auth_set_language_code.js new file mode 100644 index 00000000..5f904381 --- /dev/null +++ b/snippets/auth-next/phone-auth/auth_set_language_code.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/phone-auth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_set_language_code_modular] +import { getAuth } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +auth.languageCode = 'it'; +// To apply the default browser preference instead of explicitly setting it. +// firebase.auth().useDeviceLanguage(); +// [END auth_set_language_code_modular] \ No newline at end of file From 156cdedf948712d4662aa5dd83466ba6a8b78ea9 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 23 Dec 2020 18:45:32 +0000 Subject: [PATCH 060/235] Project ID Cleanup --- auth-next/anonymous.js | 2 +- auth-next/apple.js | 2 +- auth-next/auth-state-persistence.js | 2 +- auth-next/cordova.js | 2 +- auth-next/custom-email-handler.js | 2 +- auth-next/custom.js | 2 +- auth-next/email-link-auth.js | 2 +- auth-next/email.js | 2 +- auth-next/facebook.js | 2 +- auth-next/google-signin.js | 2 +- auth-next/index.js | 2 +- auth-next/link-multiple-accounts.js | 2 +- auth-next/microsoft-oauth.js | 2 +- auth-next/service-worker-sessions.js | 2 +- auth-next/yahoo-oauth.js | 2 +- functions-next/emulator-suite.js | 2 +- perf-next/index.js | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/auth-next/anonymous.js b/auth-next/anonymous.js index 95b175c3..56a56c39 100644 --- a/auth-next/anonymous.js +++ b/auth-next/anonymous.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/apple.js b/auth-next/apple.js index 5796f7d8..177aa065 100644 --- a/auth-next/apple.js +++ b/auth-next/apple.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/auth-state-persistence.js b/auth-next/auth-state-persistence.js index ea62f3bc..cef52522 100644 --- a/auth-next/auth-state-persistence.js +++ b/auth-next/auth-state-persistence.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/cordova.js b/auth-next/cordova.js index fffdea99..ec637576 100644 --- a/auth-next/cordova.js +++ b/auth-next/cordova.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/custom-email-handler.js b/auth-next/custom-email-handler.js index a54575e8..eccb9219 100644 --- a/auth-next/custom-email-handler.js +++ b/auth-next/custom-email-handler.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/custom.js b/auth-next/custom.js index c85db493..6ecdbe18 100644 --- a/auth-next/custom.js +++ b/auth-next/custom.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/email-link-auth.js b/auth-next/email-link-auth.js index 13cc225b..a2ec5cf5 100644 --- a/auth-next/email-link-auth.js +++ b/auth-next/email-link-auth.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/email.js b/auth-next/email.js index bdce4063..368ad8a8 100644 --- a/auth-next/email.js +++ b/auth-next/email.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/facebook.js b/auth-next/facebook.js index 27d87877..9f1723fa 100644 --- a/auth-next/facebook.js +++ b/auth-next/facebook.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/google-signin.js b/auth-next/google-signin.js index 3c13500e..4c9df7e5 100644 --- a/auth-next/google-signin.js +++ b/auth-next/google-signin.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/index.js b/auth-next/index.js index 8e9a75c7..33b382fd 100644 --- a/auth-next/index.js +++ b/auth-next/index.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/link-multiple-accounts.js b/auth-next/link-multiple-accounts.js index c8dd003c..0c612af9 100644 --- a/auth-next/link-multiple-accounts.js +++ b/auth-next/link-multiple-accounts.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/microsoft-oauth.js b/auth-next/microsoft-oauth.js index 80352b4f..a0f38348 100644 --- a/auth-next/microsoft-oauth.js +++ b/auth-next/microsoft-oauth.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/service-worker-sessions.js b/auth-next/service-worker-sessions.js index 3be8c82d..b9d87cbf 100644 --- a/auth-next/service-worker-sessions.js +++ b/auth-next/service-worker-sessions.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/auth-next/yahoo-oauth.js b/auth-next/yahoo-oauth.js index 389ed305..e5e69569 100644 --- a/auth-next/yahoo-oauth.js +++ b/auth-next/yahoo-oauth.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/functions-next/emulator-suite.js b/functions-next/emulator-suite.js index d19fea7d..48b6c681 100644 --- a/functions-next/emulator-suite.js +++ b/functions-next/emulator-suite.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); diff --git a/perf-next/index.js b/perf-next/index.js index 7b7f7b5f..96545d31 100644 --- a/perf-next/index.js +++ b/perf-next/index.js @@ -4,7 +4,7 @@ import { initializeApp } from "firebase/app"; const firebaseApp = initializeApp({ - projectId: '### CLOUD FUNCTIONS PROJECT ID ###', + projectId: '### PROJECT ID ###', apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', }); From c6fdfade032ca2cbec73e9d918d4cbed6078f6dc Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 28 Dec 2020 06:38:07 -0800 Subject: [PATCH 061/235] Simplify snippet script (#78) --- scripts/separate-snippets.ts | 119 +++++++++++++++++++++++++---------- 1 file changed, 87 insertions(+), 32 deletions(-) diff --git a/scripts/separate-snippets.ts b/scripts/separate-snippets.ts index 4705e9ab..8172dd31 100644 --- a/scripts/separate-snippets.ts +++ b/scripts/separate-snippets.ts @@ -31,27 +31,27 @@ function isBlank(line: string) { } /** - * Turns a series of source lines into a standalone snippet file by: - * - Converting require statements into top-level imports. - * - Adjusting indentation to left-align all content - * - Removing any blank lines at the starts - * - Adding a suffix to snippet names - * - * @param lines the lines containing the snippet (including START/END comments) - * @param sourceFile the source file where the original snippet lives - * @param snippetSuffix the suffix (such as _modular) + * Replace all const { foo } = require('bar') with import { foo } from 'bar'; */ -function processSnippet( - lines: string[], - sourceFile: string, - snippetSuffix: string -): string { - const outputLines: string[] = []; - +function replaceRequireWithImport(lines: string[]) { + const outputLines = []; for (const line of lines) { if (line.match(RE_REQUIRE)) { outputLines.push(line.replace(RE_REQUIRE, `import {$1} from $2`)); - } else if (line.match(RE_START_SNIPPET)) { + } else { + outputLines.push(line); + } + } + return outputLines; +} + +/** + * Change all [START foo] and [END foo] to be [START foosuffix] and [END foosuffix] + */ +function addSuffixToSnippetNames(lines: string[], snippetSuffix: string) { + const outputLines = []; + for (const line of lines) { + if (line.match(RE_START_SNIPPET)) { outputLines.push(line.replace(RE_START_SNIPPET, `[START $1${snippetSuffix}]`)); } else if (line.match(RE_END_SNIPPET)) { outputLines.push( @@ -61,29 +61,66 @@ function processSnippet( outputLines.push(line); } } + return outputLines; +} - // Adjust indentation of the otherLines so that they're left aligned - const nonBlankLines = outputLines.filter((l) => !isBlank(l)); +/** + * Remove all left-padding so that the least indented line is left-aligned. + */ +function adjustIndentation(lines: string[]) { + const nonBlankLines = lines.filter((l) => !isBlank(l)); const indentSizes = nonBlankLines.map((l) => l.length - l.trimLeft().length); const minIndent = Math.min(...indentSizes); - const adjustedOutputLines: string[] = []; - for (const line of outputLines) { + const outputLines = []; + for (const line of lines) { if (isBlank(line)) { - adjustedOutputLines.push(""); + outputLines.push(""); } else { - adjustedOutputLines.push(line.substr(minIndent)); + outputLines.push(line.substr(minIndent)); } } + return outputLines; +} - // Special case: if the first line after the comments is blank we want to remove it - const firstNonComment = adjustedOutputLines.findIndex( +/** + * If the first line after leading comments is blank, remove it. + */ +function removeFirstLineAfterComments(lines: string[]) { + const outputLines = [...lines]; + + const firstNonComment = outputLines.findIndex( (l) => !l.startsWith("//") ); if (isBlank(outputLines[firstNonComment])) { - adjustedOutputLines.splice(firstNonComment, 1); + outputLines.splice(firstNonComment, 1); } + return outputLines; +} + +/** + * Turns a series of source lines into a standalone snippet file by running + * a series of transformations. + * + * @param lines the lines containing the snippet (including START/END comments) + * @param sourceFile the source file where the original snippet lives (used in preamble) + * @param snippetSuffix the suffix (such as _modular) + */ +function processSnippet( + lines: string[], + sourceFile: string, + snippetSuffix: string +): string { + let outputLines = [...lines]; + + // Perform transformations individually, in order + outputLines = replaceRequireWithImport(outputLines); + outputLines = addSuffixToSnippetNames(outputLines, snippetSuffix); + outputLines = adjustIndentation(outputLines); + outputLines = removeFirstLineAfterComments(outputLines); + + // Add a preamble to every snippet const preambleLines = [ `// This snippet file was generated by processing the source file:`, `// ${sourceFile}`, @@ -91,7 +128,7 @@ function processSnippet( `// To make edits to the snippets in this file, please edit the source`, ``, ]; - const content = [...preambleLines, ...adjustedOutputLines].join("\n"); + const content = [...preambleLines, ...outputLines].join("\n"); return content; } @@ -121,17 +158,23 @@ function collectSnippets(filePath: string): SnippetsConfig { map: {}, }; + // If a file does not have '// [SNIPPETS_SEPARATION enabled]' in it then + // we don't process it for this script. config.enabled = lines.some((l) => !!l.match(RE_SNIPPETS_SEPARATION)); if (!config.enabled) { return config; } + // If the file contains '// [SNIPPETS_SUFFIX _banana]' we use _banana (or whatever) + // as the suffix. Otherwise we default to _modular. const suffixLine = lines.find((l) => !!l.match(RE_SNIPPETS_SUFFIX)); if (suffixLine) { const m = suffixLine.match(RE_SNIPPETS_SUFFIX); config.suffix = m[1]; } + // A temporary array holding the names of snippets we're currently within. + // This allows for handling nested snippets. let inSnippetNames = []; for (const line of lines) { @@ -139,22 +182,31 @@ function collectSnippets(filePath: string): SnippetsConfig { const endMatch = line.match(RE_END_SNIPPET); if (startMatch) { + // When we find a new [START foo] tag we are now inside snippet 'foo'. + // Until we find an [END foo] tag. All lines we see between now and then + // are part of the snippet content. const snippetName = startMatch[1]; - config.map[snippetName] = []; - config.map[snippetName].push(line); - + config.map[snippetName] = [line]; inSnippetNames.push(snippetName); } else if (endMatch) { + // When we find a new [END foo] tag we are now exiting snippet 'foo'. const snippetName = endMatch[1]; - config.map[snippetName].push(line); + // If we were not aware that we were inside this snippet (no previous START) + // then we hard throw. if (!inSnippetNames.includes(snippetName)) { throw new Error( `Unrecognized END tag ${snippetName} in ${filePath}.` ); } + + // Collect this line as the final line of the snippet and then + // remove this snippet name from the list we're tracking. + config.map[snippetName].push(line); inSnippetNames.splice(inSnippetNames.indexOf(snippetName), 1); } else if (inSnippetNames.length > 0) { + // Any line that is not START or END is appended to the list of + // lines for all the snippets we're currently tracking. for (const snippetName of inSnippetNames) { config.map[snippetName].push(line); } @@ -189,11 +241,14 @@ async function main() { for (const snippetName in config.map) { const newFilePath = path.join(snippetDir, `${snippetName}.js`); + + const snippetLines = config.map[snippetName]; const content = processSnippet( - config.map[snippetName], + snippetLines, filePath, config.suffix ); + fs.writeFileSync(newFilePath, content); } } From a6ecc6cc9b1beb73583a5180292e9680630005d9 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 29 Dec 2020 12:28:06 +0000 Subject: [PATCH 062/235] Add/standardize OAuth provider snippets (#79) * Add/standardize OAuth provider snippets * Regenerate snippets * Fix placeholder * Add some shared snippets * Yell about duplicate snippets * Add snippets README back --- SNIPPETS.md | 26 ++++++ auth-next/facebook.js | 79 ++++++++++++++++- auth-next/github.js | 85 +++++++++++++++++++ auth-next/google-signin.js | 70 +++++++++++++++ auth-next/index.js | 42 +++++++++ auth-next/microsoft-oauth.js | 32 ++----- auth-next/phone-auth.js | 11 --- auth-next/twitter.js | 83 ++++++++++++++++++ auth-next/yahoo-oauth.js | 58 ++++++------- auth/facebook.js | 82 +++++++++++++++++- auth/github.js | 78 +++++++++++++++++ auth/google-signin.js | 70 +++++++++++++++ auth/index.js | 34 ++++++++ auth/microsoft-oauth.js | 63 ++++++-------- auth/phone-auth.js | 8 -- auth/twitter.js | 78 +++++++++++++++++ auth/yahoo-oauth.js | 74 ++++++++-------- package.json | 3 +- placeholder.js | 6 ++ scripts/separate-snippets.ts | 6 +- snippets/README.md | 26 ------ .../facebook/auth_facebook_provider_create.js | 10 +++ .../facebook/auth_facebook_provider_params.js | 10 +++ .../facebook/auth_facebook_provider_scopes.js | 8 ++ .../auth_facebook_signin_credential.js | 4 +- .../facebook/auth_facebook_signin_popup.js | 32 +++++++ .../auth_facebook_signin_redirect_result.js | 27 ++++++ .../auth-next/firebaseui/auth_fui_config.js | 38 --------- .../firebaseui/auth_fui_config_start.js | 8 -- .../firebaseui/auth_fui_email_link_result.js | 15 ---- .../firebaseui/auth_fui_handle_anonymous.js | 44 ---------- .../auth-next/firebaseui/auth_fui_init.js | 8 -- .../firebaseui/auth_fui_start_email.js | 13 --- .../firebaseui/auth_fui_start_email_link.js | 16 ---- .../auth_fui_start_email_link_options.js | 45 ---------- .../auth_fui_start_email_options.js | 15 ---- .../firebaseui/auth_fui_start_oauth.js | 17 ---- .../auth_fui_start_oauth_options.js | 37 -------- .../firebaseui/auth_fui_start_phone.js | 13 --- .../auth_fui_start_phone_options.js | 36 -------- .../github/auth_github_provider_create.js | 10 +++ .../github/auth_github_provider_params.js | 10 +++ .../github/auth_github_provider_scopes.js | 8 ++ .../github/auth_github_signin_popup.js | 29 +++++++ .../auth_github_signin_redirect_result.js | 31 +++++++ .../auth_google_provider_create.js | 10 +++ .../auth_google_provider_params.js | 10 +++ .../auth_google_provider_scopes.js | 8 ++ .../google-signin/auth_google_signin_popup.js | 28 ++++++ .../auth_google_signin_redirect_result.js | 28 ++++++ .../auth_set_language_code.js | 2 +- .../auth-next/index/auth_signin_credential.js | 24 ++++++ .../auth-next/index/auth_signin_redirect.js | 11 +++ .../auth_msft_provider_scopes.js | 9 ++ ...js => auth_msft_signin_redirect_result.js} | 4 +- .../twitter/auth_twitter_provider_create.js | 10 +++ .../twitter/auth_twitter_provider_params.js | 10 +++ .../twitter/auth_twitter_signin_popup.js | 31 +++++++ .../auth_twitter_signin_redirect_result.js | 31 +++++++ ...vider.js => auth_yahoo_provider_create.js} | 4 +- ...arams.js => auth_yahoo_provider_params.js} | 4 +- ...copes.js => auth_yahoo_provider_scopes.js} | 4 +- .../yahoo-oauth/auth_yahoo_signin_popup.js | 8 +- ...s => auth_yahoo_signin_redirect_result.js} | 10 +-- snippets/placeholder.js | 3 - snippets/placeholder/coming_soon.js | 8 ++ 66 files changed, 1241 insertions(+), 514 deletions(-) create mode 100644 SNIPPETS.md create mode 100644 auth-next/github.js create mode 100644 auth-next/twitter.js create mode 100644 auth/github.js create mode 100644 auth/twitter.js create mode 100644 placeholder.js delete mode 100644 snippets/README.md create mode 100644 snippets/auth-next/facebook/auth_facebook_provider_create.js create mode 100644 snippets/auth-next/facebook/auth_facebook_provider_params.js create mode 100644 snippets/auth-next/facebook/auth_facebook_provider_scopes.js create mode 100644 snippets/auth-next/facebook/auth_facebook_signin_popup.js create mode 100644 snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_config.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_config_start.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_email_link_result.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_handle_anonymous.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_init.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_start_email.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_start_email_link.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_start_email_link_options.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_start_email_options.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_start_oauth.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_start_oauth_options.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_start_phone.js delete mode 100644 snippets/auth-next/firebaseui/auth_fui_start_phone_options.js create mode 100644 snippets/auth-next/github/auth_github_provider_create.js create mode 100644 snippets/auth-next/github/auth_github_provider_params.js create mode 100644 snippets/auth-next/github/auth_github_provider_scopes.js create mode 100644 snippets/auth-next/github/auth_github_signin_popup.js create mode 100644 snippets/auth-next/github/auth_github_signin_redirect_result.js create mode 100644 snippets/auth-next/google-signin/auth_google_provider_create.js create mode 100644 snippets/auth-next/google-signin/auth_google_provider_params.js create mode 100644 snippets/auth-next/google-signin/auth_google_provider_scopes.js create mode 100644 snippets/auth-next/google-signin/auth_google_signin_popup.js create mode 100644 snippets/auth-next/google-signin/auth_google_signin_redirect_result.js rename snippets/auth-next/{phone-auth => index}/auth_set_language_code.js (93%) create mode 100644 snippets/auth-next/index/auth_signin_credential.js create mode 100644 snippets/auth-next/index/auth_signin_redirect.js create mode 100644 snippets/auth-next/microsoft-oauth/auth_msft_provider_scopes.js rename snippets/auth-next/microsoft-oauth/{auth_msf_redirect_result.js => auth_msft_signin_redirect_result.js} (87%) create mode 100644 snippets/auth-next/twitter/auth_twitter_provider_create.js create mode 100644 snippets/auth-next/twitter/auth_twitter_provider_params.js create mode 100644 snippets/auth-next/twitter/auth_twitter_signin_popup.js create mode 100644 snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js rename snippets/auth-next/yahoo-oauth/{auth_yahoo_create_provider.js => auth_yahoo_provider_create.js} (75%) rename snippets/auth-next/yahoo-oauth/{auth_yahoo_create_provider_params.js => auth_yahoo_provider_params.js} (75%) rename snippets/auth-next/yahoo-oauth/{auth_yahoo_create_provider_scopes.js => auth_yahoo_provider_scopes.js} (78%) rename snippets/auth-next/yahoo-oauth/{auth_yahoo_redirect_result.js => auth_yahoo_signin_redirect_result.js} (68%) delete mode 100644 snippets/placeholder.js create mode 100644 snippets/placeholder/coming_soon.js diff --git a/SNIPPETS.md b/SNIPPETS.md new file mode 100644 index 00000000..7d0f6876 --- /dev/null +++ b/SNIPPETS.md @@ -0,0 +1,26 @@ +# Generated Snippets + +## Overview + +The `snippets` directory contains snippets generated by the `separate-snippets` script. +Snippets in this folder should **never** be updated directly instead please +edit the source file (indicated by a comment at the top). + +## Regenerating the Snippets + +Run `npm run snippets` from the root of this repository. + +## Using the Separator + +For a file to be included in the separator script it must contain a comment like this: + +```js +// [SNIPPETS_SEPARATION enabled] +``` + +By default separated snippets will have their name suffixed with `_modular` +but you can override this with a commment: + +```js +// [SNIPPETS_SUFFIX _banana] +``` diff --git a/auth-next/facebook.js b/auth-next/facebook.js index 9f1723fa..0ec084bd 100644 --- a/auth-next/facebook.js +++ b/auth-next/facebook.js @@ -9,6 +9,79 @@ const firebaseApp = initializeApp({ authDomain: '### FIREBASE AUTH DOMAIN ###', }); +function facebookProvider() { + // [START auth_facebook_provider_create] + const { FacebookAuthProvider } = require("firebase/auth"); + + const provider = new FacebookAuthProvider(); + // [END auth_facebook_provider_create] + + // / [START auth_facebook_provider_scopes] + provider.addScope('user_birthday'); + // [END auth_facebook_provider_scopes] + + // [START auth_facebook_provider_params] + provider.setCustomParameters({ + 'display': 'popup' + }); + // [END auth_facebook_provider_params] +} + +function facebookSignInPopup(provider) { + // [START auth_facebook_signin_popup] + const { getAuth, signInWithPopup, FacebookAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithPopup(auth, provider) + .then((result) => { + // The signed-in user info. + const user = result.user; + + // This gives you a Facebook Access Token. You can use it to access the Facebook API. + const credential = FacebookAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + + // ... + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = FacebookAuthProvider.credentialFromError(error); + + // ... + }); + // [END auth_facebook_signin_popup] +} + +function facebookSignInRedirectResult() { + // [START auth_facebook_signin_redirect_result] + const { getAuth, getRedirectResult, FacebookAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + getRedirectResult(auth) + .then((result) => { + // This gives you a Facebook Access Token. You can use it to access the Facebook API. + const credential = FacebookAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + + const user = result.user; + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // AuthCredential type that was used. + const credential = FacebookAuthProvider.credentialFromError(error); + // ... + }); + // [END auth_facebook_signin_redirect_result] +} + function checkLoginState_wrapper() { // See real implementation below function isUserEqual(x, y) { @@ -31,7 +104,6 @@ function checkLoginState_wrapper() { response.authResponse.accessToken); // Sign in with the credential from the Facebook user. - // [START auth_facebook_signin_credential] signInWithCredential(auth, credential) .catch((error) => { // Handle Errors here. @@ -43,7 +115,6 @@ function checkLoginState_wrapper() { const credential = FacebookAuthProvider.credentialFromError(error); // ... }); - // [END auth_facebook_signin_credential] } else { // User is already signed-in Firebase with the correct user. } @@ -84,9 +155,9 @@ function authWithCredential(credential) { // Sign in with the credential from the Facebook user. const auth = getAuth(firebaseApp); signInWithCredential(auth, credential) - .then((cred) => { + .then((result) => { // Signed in - // ... + const credential = FacebookAuthProvider.credentialFromResult(result); }) .catch((error) => { // Handle Errors here. diff --git a/auth-next/github.js b/auth-next/github.js new file mode 100644 index 00000000..d59b0f42 --- /dev/null +++ b/auth-next/github.js @@ -0,0 +1,85 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +function githubProvider() { + // [START auth_github_provider_create] + const { GithubAuthProvider } = require("firebase/auth"); + + const provider = new GithubAuthProvider(); + // [END auth_github_provider_create] + + // [START auth_github_provider_scopes] + provider.addScope('repo'); + // [END auth_github_provider_scopes] + + // [START auth_github_provider_params] + provider.setCustomParameters({ + 'allow_signup': 'false' + }); + // [END auth_github_provider_params] +} + +function githubSignInPopup(provider) { + // [START auth_github_signin_popup] + const { getAuth, signInWithPopup, GithubAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithPopup(auth, provider) + .then((result) => { + // This gives you a GitHub Access Token. You can use it to access the GitHub API. + const credential = GithubAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + + // The signed-in user info. + const user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = GithubAuthProvider.credentialFromError(error); + // ... + }); + // [END auth_github_signin_popup] +} + +function githubSignInRedirectResult() { + // [START auth_github_signin_redirect_result] + const { getAuth, getRedirectResult, GithubAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + getRedirectResult(auth) + .then((result) => { + const credential = GithubAuthProvider.credentialFromResult(result); + if (credential) { + // This gives you a GitHub Access Token. You can use it to access the GitHub API. + const token = credential.accessToken; + // ... + } + + // The signed-in user info. + const user = result.user; + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = GithubAuthProvider.credentialFromError(error); + // ... + }); + // [END auth_github_signin_redirect_result] +} + diff --git a/auth-next/google-signin.js b/auth-next/google-signin.js index 4c9df7e5..4661212b 100644 --- a/auth-next/google-signin.js +++ b/auth-next/google-signin.js @@ -11,6 +11,76 @@ const firebaseApp = initializeApp({ // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/google-signin.md +function googleProvider() { + // [START auth_google_provider_create] + const { GoogleAuthProvider } = require("firebase/auth"); + + const provider = new GoogleAuthProvider(); + // [END auth_google_provider_create] + + // [START auth_google_provider_scopes] + provider.addScope('https://www.googleapis.com/auth/contacts.readonly'); + // [END auth_google_provider_scopes] + + // [START auth_google_provider_params] + provider.setCustomParameters({ + 'login_hint': 'user@example.com' + }); + // [END auth_google_provider_params] +} + +function googleSignInPopup(provider) { + // [START auth_google_signin_popup] + const { getAuth, signInWithPopup, GoogleAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithPopup(auth, provider) + .then((result) => { + // This gives you a Google Access Token. You can use it to access the Google API. + const credential = GoogleAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + // The signed-in user info. + const user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = GoogleAuthProvider.credentialFromError(error); + // ... + }); + // [END auth_google_signin_popup] +} + +function googleSignInRedirectResult() { + // [START auth_google_signin_redirect_result] + const { getAuth, getRedirectResult, GoogleAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + getRedirectResult(auth) + .then((result) => { + // This gives you a Google Access Token. You can use it to access Google APIs. + const credential = GoogleAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + + // The signed-in user info. + const user = result.user; + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = GoogleAuthProvider.credentialFromError(error); + // ... + }); + // [END auth_google_signin_redirect_result] +} + function googleBuildAndSignIn(id_token) { // [START auth_google_build_signin] const { getAuth, signInWithCredential, GoogleAuthProvider } = require("firebase/auth"); diff --git a/auth-next/index.js b/auth-next/index.js index 33b382fd..bf5bec57 100644 --- a/auth-next/index.js +++ b/auth-next/index.js @@ -70,3 +70,45 @@ function authStateListener() { }); // [END auth_state_listener] } + +function setLanguageCode() { + // [START auth_set_language_code] + const { getAuth } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + auth.languageCode = 'it'; + // To apply the default browser preference instead of explicitly setting it. + // firebase.auth().useDeviceLanguage(); + // [END auth_set_language_code] +} + +function authWithCredential(credential) { + // [START auth_signin_credential] + const { getAuth, signInWithCredential } = require("firebase/auth"); + + // Sign in with the credential from the user. + const auth = getAuth(firebaseApp); + signInWithCredential(auth, credential) + .then((result) => { + // Signed in + // ... + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // ... + }); + // [END auth_signin_credential] +} + +function signInRedirect(provider) { + // [START auth_signin_redirect] + const { getAuth, signInWithRedirect } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithRedirect(auth, provider); + // [END auth_signin_redirect] +} diff --git a/auth-next/microsoft-oauth.js b/auth-next/microsoft-oauth.js index a0f38348..0179ffc6 100644 --- a/auth-next/microsoft-oauth.js +++ b/auth-next/microsoft-oauth.js @@ -18,11 +18,11 @@ function msftCreateProvider() { const provider = new OAuthProvider('microsoft.com'); // [END auth_msft_create_provider] - return provider; -} + // [START auth_msft_provider_scopes] + provider.addScope('mail.read'); + provider.addScope('calendars.read'); + // [END auth_msft_provider_scopes] -function msftProviderParams() { - const provider = msftCreateProvider(); // [START auth_msft_provider_params] provider.setCustomParameters({ // Force re-consent. @@ -31,10 +31,7 @@ function msftProviderParams() { login_hint: 'user@firstadd.onmicrosoft.com' }); // [END auth_msft_provider_params] -} -function msftProviderParamsTenant() { - const provider = msftCreateProvider(); // [START auth_msft_provider_params_tenant] provider.setCustomParameters({ // Optional "tenant" parameter in case you are using an Azure AD tenant. @@ -46,16 +43,7 @@ function msftProviderParamsTenant() { // [END auth_msft_provider_params_tenant] } -function msftProviderScopes() { - const provider = msftCreateProvider(); - // [START auth_msft_provider_scopes - provider.addScope('mail.read'); - provider.addScope('calendars.read'); - // [END auth_msft_provider_scopes -} - -function msftSigninPopup() { - const provider = msftCreateProvider(); +function msftSignInPopup(provider) { // [START auth_msft_signin_popup] const { getAuth, signInWithPopup, OAuthProvider } = require("firebase/auth"); @@ -76,9 +64,7 @@ function msftSigninPopup() { // [END auth_msft_signin_popup] } -function msftSignInRedirect() { - const provider = msftCreateProvider(); - +function msftSignInRedirect(provider) { // [START auth_msft_signin_redirect] const { getAuth, signInWithRedirect } = require("firebase/auth"); @@ -87,8 +73,8 @@ function msftSignInRedirect() { // [END auth_msft_signin_redirect] } -function msftRedirectResult() { - // [START auth_msf_redirect_result] +function msftSignInRedirectResult() { + // [START auth_msft_signin_redirect_result] const { getAuth, getRedirectResult, OAuthProvider } = require("firebase/auth"); const auth = getAuth(firebaseApp); @@ -105,7 +91,7 @@ function msftRedirectResult() { .catch((error) => { // Handle error. }); - // [END auth_msf_redirect_result] + // [END auth_msft_signin_redirect_result] } function msftLinkWithPopup() { diff --git a/auth-next/phone-auth.js b/auth-next/phone-auth.js index 87917811..510dd219 100644 --- a/auth-next/phone-auth.js +++ b/auth-next/phone-auth.js @@ -14,17 +14,6 @@ const window = { recaptchaVerifier: undefined }; -function setLanguageCode() { - // [START auth_set_language_code] - const { getAuth } = require("firebase/auth"); - - const auth = getAuth(firebaseApp); - auth.languageCode = 'it'; - // To apply the default browser preference instead of explicitly setting it. - // firebase.auth().useDeviceLanguage(); - // [END auth_set_language_code] -} - function recaptchaVerifierInvisible() { function onSignInSubmit() { // TODO(you): Implement diff --git a/auth-next/twitter.js b/auth-next/twitter.js new file mode 100644 index 00000000..6e204cb3 --- /dev/null +++ b/auth-next/twitter.js @@ -0,0 +1,83 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +function twitterProvider() { + // [START auth_twitter_provider_create] + const { TwitterAuthProvider } = require("firebase/auth"); + + const provider = new TwitterAuthProvider(); + // [END auth_twitter_provider_create] + + // [START auth_twitter_provider_params] + provider.setCustomParameters({ + 'lang': 'es' + }); + // [END auth_twitter_provider_params] +} + +function twitterSignInPopup(provider) { + // [START auth_twitter_signin_popup] + const { getAuth, signInWithPopup, TwitterAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + signInWithPopup(auth, provider) + .then((result) => { + // This gives you a the Twitter OAuth 1.0 Access Token and Secret. + // You can use these server side with your app's credentials to access the Twitter API. + const credential = TwitterAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + const secret = credential.secret; + + // The signed-in user info. + const user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = TwitterAuthProvider.credentialFromError(error); + // ... + }); + // [END auth_twitter_signin_popup] +} + +function twitterSignInRedirectResult() { + // [START auth_twitter_signin_redirect_result] + const { getAuth, getRedirectResult, TwitterAuthProvider } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + getRedirectResult(auth) + .then((result) => { + // This gives you a the Twitter OAuth 1.0 Access Token and Secret. + // You can use these server side with your app's credentials to access the Twitter API. + const credential = TwitterAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + const secret = credential.secret; + // ... + + // The signed-in user info. + const user = result.user; + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = TwitterAuthProvider.credentialFromError(error); + // ... + }); + // [END auth_twitter_signin_redirect_result] +} + diff --git a/auth-next/yahoo-oauth.js b/auth-next/yahoo-oauth.js index e5e69569..e03c9bba 100644 --- a/auth-next/yahoo-oauth.js +++ b/auth-next/yahoo-oauth.js @@ -11,51 +11,42 @@ const firebaseApp = initializeApp({ // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/yahoo-oauth.md -function yahooCreateProvider() { - // [START auth_yahoo_create_provider] +function yahooProvider() { + // [START auth_yahoo_provider_create] const { OAuthProvider } = require("firebase/auth"); const provider = new OAuthProvider('yahoo.com'); - // [END auth_yahoo_create_provider] + // [END auth_yahoo_provider_create] - return provider; -} + // [START auth_yahoo_provider_scopes] + // Request access to Yahoo Mail API. + provider.addScope('mail-r'); + // Request read/write access to user contacts. + // This must be preconfigured in the app's API permissions. + provider.addScope('sdct-w'); + // [END auth_yahoo_provider_scopes] -function yahooCreateProviderParams() { - const provider = yahooCreateProvider(); - // [START auth_yahoo_create_provider_params] + // [START auth_yahoo_provider_params] provider.setCustomParameters({ // Prompt user to re-authenticate to Yahoo. prompt: 'login', // Localize to French. language: 'fr' }); - // [END auth_yahoo_create_provider_params] -} - -function yahooCreateProviderScopes() { - const provider = yahooCreateProvider(); - // [START auth_yahoo_create_provider_scopes] - // Request access to Yahoo Mail API. - provider.addScope('mail-r'); - // Request read/write access to user contacts. - // This must be preconfigured in the app's API permissions. - provider.addScope('sdct-w'); - // [END auth_yahoo_create_provider_scopes] + // [END auth_yahoo_provider_params] } -function yahooSignInPopup() { - const provider = yahooCreateProvider(); +function yahooSignInPopup(provider) { // [START auth_yahoo_signin_popup] - const { getAuth, signInWithPopup,OAuthProvider } = require("firebase/auth"); + const { getAuth, signInWithPopup, OAuthProvider } = require("firebase/auth"); const auth = getAuth(firebaseApp); signInWithPopup(auth, provider) .then((result) => { - // User is signed in. - // IdP data available in result.additionalUserInfo.profile. + // IdP data available in result.additionalUserInfo.profile + // ... - // Get the OAuth access token and ID Token + // Yahoo OAuth access token and ID token can be retrieved by calling: const credential = OAuthProvider.credentialFromResult(result); const accessToken = credential.accessToken; const idToken = credential.idToken; @@ -66,8 +57,7 @@ function yahooSignInPopup() { // [END auth_yahoo_signin_popup] } -function yahooSignInRedirect() { - const provider = yahooCreateProvider(); +function yahooSignInRedirect(provider) { // [START auth_yahoo_signin_redirect] const { getAuth, signInWithRedirect } = require("firebase/auth"); @@ -76,17 +66,17 @@ function yahooSignInRedirect() { // [END auth_yahoo_signin_redirect] } -function yahooRedirectResult() { - // [START auth_yahoo_redirect_result] +function yahooSigninRedirectResult() { + // [START auth_yahoo_signin_redirect_result] const { getAuth, getRedirectResult, OAuthProvider } = require("firebase/auth"); const auth = getAuth(firebaseApp); getRedirectResult(auth) .then((result) => { - // User is signed in. - // IdP data available in result.additionalUserInfo.profile. + // IdP data available in result.additionalUserInfo.profile + // ... - // Get the OAuth access token and ID Token + // Yahoo OAuth access token and ID token can be retrieved by calling: const credential = OAuthProvider.credentialFromResult(result); const accessToken = credential.accessToken; const idToken = credential.idToken; @@ -94,7 +84,7 @@ function yahooRedirectResult() { .catch((error) => { // Handle error. }); - // [END auth_yahoo_redirect_result] + // [END auth_yahoo_signin_redirect_result] } function yahooLinkPopup() { diff --git a/auth/facebook.js b/auth/facebook.js index b7a055b0..3e5c5b14 100644 --- a/auth/facebook.js +++ b/auth/facebook.js @@ -4,6 +4,81 @@ import firebase from "firebase/app"; import "firebase/auth"; +function facebookProvider() { + // [START auth_facebook_provider_create] + var provider = new firebase.auth.FacebookAuthProvider(); + // [END auth_facebook_provider_create] + + // / [START auth_facebook_provider_scopes] + provider.addScope('user_birthday'); + // [END auth_facebook_provider_scopes] + + // [START auth_facebook_provider_params] + provider.setCustomParameters({ + 'display': 'popup' + }); + // [END auth_facebook_provider_params] +} + +function facebookSignInPopup(provider) { + // [START auth_facebook_signin_popup] + firebase + .auth() + .signInWithPopup(provider) + .then((result) => { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // The signed-in user info. + var user = result.user; + + // This gives you a Facebook Access Token. You can use it to access the Facebook API. + var accessToken = credential.accessToken; + + // ... + }) + .catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + + // ... + }); + // [END auth_facebook_signin_popup] +} + +function facebookSignInRedirectResult() { + // [START auth_facebook_signin_redirect_result] + firebase.auth() + .getRedirectResult() + .then((result) => { + if (result.credential) { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // This gives you a Facebook Access Token. You can use it to access the Facebook API. + var token = credential.accessToken; + // ... + } + // The signed-in user info. + var user = result.user; + }).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + // [END auth_facebook_signin_redirect_result] +} + // [START auth_facebook_callback] function checkLoginState(response) { if (response.authResponse) { @@ -17,7 +92,6 @@ function checkLoginState(response) { response.authResponse.accessToken); // Sign in with the credential from the Facebook user. - // [START auth_facebook_signin_credential] firebase.auth().signInWithCredential(credential) .catch((error) => { // Handle Errors here. @@ -29,7 +103,6 @@ function checkLoginState(response) { var credential = error.credential; // ... }); - // [END auth_facebook_signin_credential] } else { // User is already signed-in Firebase with the correct user. } @@ -61,8 +134,9 @@ function authWithCredential(credential) { // [START auth_facebook_signin_credential] // Sign in with the credential from the Facebook user. firebase.auth().signInWithCredential(credential) - .then((cred) => { - // Signed in + .then((result) => { + // Signed in + var credential = result.credential; // ... }) .catch((error) => { diff --git a/auth/github.js b/auth/github.js new file mode 100644 index 00000000..bf2db5bf --- /dev/null +++ b/auth/github.js @@ -0,0 +1,78 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +function githubProvider() { + // [START auth_github_provider_create] + var provider = new firebase.auth.GithubAuthProvider(); + // [END auth_github_provider_create] + + // [START auth_github_provider_scopes] + provider.addScope('repo'); + // [END auth_github_provider_scopes] + + // [START auth_github_provider_params] + provider.setCustomParameters({ + 'allow_signup': 'false' + }); + // [END auth_github_provider_params] +} + +function githubSignInPopup(provider) { + // [START auth_github_signin_popup] + firebase + .auth() + .signInWithPopup(provider) + .then((result) => { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // This gives you a GitHub Access Token. You can use it to access the GitHub API. + var token = credential.accessToken; + + // The signed-in user info. + var user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + // [END auth_github_signin_popup] +} + +function githubSignInRedirectResult() { + // [START auth_github_signin_redirect_result] + firebase.auth() + .getRedirectResult() + .then((result) => { + if (result.credential) { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // This gives you a GitHub Access Token. You can use it to access the GitHub API. + var token = credential.accessToken; + // ... + } + + // The signed-in user info. + var user = result.user; + }).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + // [END auth_github_signin_redirect_result] +} diff --git a/auth/google-signin.js b/auth/google-signin.js index 3323d2a5..908a32e1 100644 --- a/auth/google-signin.js +++ b/auth/google-signin.js @@ -6,6 +6,76 @@ import "firebase/auth"; // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/google-signin.md +function googleProvider() { + // [START auth_google_provider_create] + var provider = new firebase.auth.GoogleAuthProvider(); + // [END auth_google_provider_create] + + // [START auth_google_provider_scopes] + provider.addScope('https://www.googleapis.com/auth/contacts.readonly'); + // [END auth_google_provider_scopes] + + // [START auth_google_provider_params] + provider.setCustomParameters({ + 'login_hint': 'user@example.com' + }); + // [END auth_google_provider_params] +} + +function googleSignInPopup(provider) { + // [START auth_google_signin_popup] + firebase.auth() + .signInWithPopup(provider) + .then((result) => { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // This gives you a Google Access Token. You can use it to access the Google API. + var token = credential.accessToken; + // The signed-in user info. + var user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + // [END auth_google_signin_popup] +} + +function googleSignInRedirectResult() { + // [START auth_google_signin_redirect_result] + firebase.auth() + .getRedirectResult() + .then((result) => { + if (result.credential) { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // This gives you a Google Access Token. You can use it to access the Google API. + var token = credential.accessToken; + // ... + } + // The signed-in user info. + var user = result.user; + }).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + // [END auth_google_signin_redirect_result] +} + function googleBuildAndSignIn(id_token) { // [START auth_google_build_signin] // Build Firebase credential with the Google ID token. diff --git a/auth/index.js b/auth/index.js index d57d704f..cae8831b 100644 --- a/auth/index.js +++ b/auth/index.js @@ -53,3 +53,37 @@ function authStateListener() { }); // [END auth_state_listener] } + +function setLanguageCode() { + // [START auth_set_language_code] + firebase.auth().languageCode = 'it'; + // To apply the default browser preference instead of explicitly setting it. + // firebase.auth().useDeviceLanguage(); + // [END auth_set_language_code] +} + +function authWithCredential(credential) { + // [START auth_signin_credential] + // Sign in with the credential from the user. + firebase.auth() + .signInWithCredential(credential) + .then((result) => { + // Signed in + // ... + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // ... + }); + // [END auth_signin_credential] +} + +function signInRedirect(provider) { + // [START auth_signin_redirect] + firebase.auth().signInWithRedirect(provider); + // [END auth_signin_redirect] +} diff --git a/auth/microsoft-oauth.js b/auth/microsoft-oauth.js index 32d83156..23289353 100644 --- a/auth/microsoft-oauth.js +++ b/auth/microsoft-oauth.js @@ -6,16 +6,16 @@ import "firebase/auth"; // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/microsoft-oauth.md -function msftCreateProvider() { - // [START auth_msft_create_provider] +function microsoftProvider() { + // [START auth_msft_provider_create] var provider = new firebase.auth.OAuthProvider('microsoft.com'); - // [END auth_msft_create_provider] + // [END auth_msft_provider_create] - return provider; -} + // [START auth_msft_provider_scopes] + provider.addScope('mail.read'); + provider.addScope('calendars.read'); + // [END auth_msft_provider_scopes] -function msftProviderParams() { - var provider = msftCreateProvider(); // [START auth_msft_provider_params] provider.setCustomParameters({ // Force re-consent. @@ -24,10 +24,7 @@ function msftProviderParams() { login_hint: 'user@firstadd.onmicrosoft.com' }); // [END auth_msft_provider_params] -} -function msftProviderParamsTenant() { - var provider = msftCreateProvider(); // [START auth_msft_provider_params_tenant] provider.setCustomParameters({ // Optional "tenant" parameter in case you are using an Azure AD tenant. @@ -39,25 +36,19 @@ function msftProviderParamsTenant() { // [END auth_msft_provider_params_tenant] } -function msftProviderScopes() { - var provider = msftCreateProvider(); - // [START auth_msft_provider_scopes - provider.addScope('mail.read'); - provider.addScope('calendars.read'); - // [END auth_msft_provider_scopes -} - -function msftSigninPopup() { - var provider = msftCreateProvider(); +function msftSignInPopup(provider) { // [START auth_msft_signin_popup] firebase.auth().signInWithPopup(provider) .then((result) => { - // User is signed in. // IdP data available in result.additionalUserInfo.profile. - // OAuth access token can also be retrieved: - // result.credential.accessToken - // OAuth ID token can also be retrieved: - // result.credential.idToken + // ... + + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // OAuth access and id tokens can also be retrieved: + var accessToken = credential.accessToken; + var idToken = credential.idToken; }) .catch((error) => { // Handle error. @@ -65,28 +56,30 @@ function msftSigninPopup() { // [END auth_msft_signin_popup] } -function msftSignInRedirect() { - var provider = msftCreateProvider(); +function msftSignInRedirect(provider) { // [START auth_msft_signin_redirect] firebase.auth().signInWithRedirect(provider); // [END auth_msft_signin_redirect] } -function msftRedirectResult() { - // [START auth_msf_redirect_result] +function msftSignInRedirectResult() { + // [START auth_msft_signin_redirect_result] firebase.auth().getRedirectResult() .then((result) => { - // User is signed in. // IdP data available in result.additionalUserInfo.profile. - // OAuth access token can also be retrieved: - // result.credential.accessToken - // OAuth ID token can also be retrieved: - // result.credential.idToken + // ... + + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // OAuth access and id tokens can also be retrieved: + var accessToken = credential.accessToken; + var idToken = credential.idToken; }) .catch((error) => { // Handle error. }); - // [END auth_msf_redirect_result] + // [END auth_msft_signin_redirect_result] } function msftLinkWithPopup() { diff --git a/auth/phone-auth.js b/auth/phone-auth.js index f5d6981a..1b9549a9 100644 --- a/auth/phone-auth.js +++ b/auth/phone-auth.js @@ -9,14 +9,6 @@ const window = { recaptchaVerifier: undefined }; -function setLanguageCode() { - // [START auth_set_language_code] - firebase.auth().languageCode = 'it'; - // To apply the default browser preference instead of explicitly setting it. - // firebase.auth().useDeviceLanguage(); - // [END auth_set_language_code] -} - function recaptchaVerifierInvisible() { function onSignInSubmit() { // TODO(you): Implement diff --git a/auth/twitter.js b/auth/twitter.js new file mode 100644 index 00000000..b1ca2581 --- /dev/null +++ b/auth/twitter.js @@ -0,0 +1,78 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +function twitterProvider() { + // [START auth_twitter_provider_create] + var provider = new firebase.auth.TwitterAuthProvider(); + // [END auth_twitter_provider_create] + + // [START auth_twitter_provider_params] + provider.setCustomParameters({ + 'lang': 'es' + }); + // [END auth_twitter_provider_params] +} + +function twitterSignInPopup(provider) { + // [START auth_twitter_signin_popup] + firebase + .auth() + .signInWithPopup(provider) + .then((result) => { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // This gives you a the Twitter OAuth 1.0 Access Token and Secret. + // You can use these server side with your app's credentials to access the Twitter API. + var token = credential.accessToken; + var secret = credential.secret; + + // The signed-in user info. + var user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + // [END auth_twitter_signin_popup] +} + +function twitterSignInRedirectResult() { + // [START auth_twitter_signin_redirect_result] + firebase.auth() + .getRedirectResult() + .then((result) => { + if (result.credential) { + /** @type {firebase.auth.OAuthCredential} */ + var credential = result.credential; + + // This gives you a the Twitter OAuth 1.0 Access Token and Secret. + // You can use these server side with your app's credentials to access the Twitter API. + var token = credential.accessToken; + var secret = credential.secret; + // ... + } + + // The signed-in user info. + var user = result.user; + }).catch((error) => { + // Handle Errors here. + var errorCode = error.code; + var errorMessage = error.message; + // The email of the user's account used. + var email = error.email; + // The firebase.auth.AuthCredential type that was used. + var credential = error.credential; + // ... + }); + // [END auth_twitter_signin_redirect_result] +} diff --git a/auth/yahoo-oauth.js b/auth/yahoo-oauth.js index f7ae147f..92529bf0 100644 --- a/auth/yahoo-oauth.js +++ b/auth/yahoo-oauth.js @@ -6,48 +6,42 @@ import "firebase/auth"; // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/yahoo-oauth.md -function yahooCreateProvider() { - // [START auth_yahoo_create_provider] +function yahooProvider() { + // [START auth_yahoo_provider_create] var provider = new firebase.auth.OAuthProvider('yahoo.com'); - // [END auth_yahoo_create_provider] + // [END auth_yahoo_provider_create] - return provider; -} + // [START auth_yahoo_provider_scopes] + // Request access to Yahoo Mail API. + provider.addScope('mail-r'); + // Request read/write access to user contacts. + // This must be preconfigured in the app's API permissions. + provider.addScope('sdct-w'); + // [END auth_yahoo_provider_scopes] -function yahooCreateProviderParams() { - var provider = yahooCreateProvider(); - // [START auth_yahoo_create_provider_params] + // [START auth_yahoo_provider_params] provider.setCustomParameters({ // Prompt user to re-authenticate to Yahoo. prompt: 'login', // Localize to French. language: 'fr' }); - // [END auth_yahoo_create_provider_params] + // [END auth_yahoo_provider_params] } -function yahooCreateProviderScopes() { - var provider = yahooCreateProvider(); - // [START auth_yahoo_create_provider_scopes] - // Request access to Yahoo Mail API. - provider.addScope('mail-r'); - // Request read/write access to user contacts. - // This must be preconfigured in the app's API permissions. - provider.addScope('sdct-w'); - // [END auth_yahoo_create_provider_scopes] -} - -function yahooSignInPopup() { - var provider = yahooCreateProvider(); +function yahooSignInPopup(provider) { // [START auth_yahoo_signin_popup] firebase.auth().signInWithPopup(provider) .then((result) => { - // User is signed in. - // IdP data available in result.additionalUserInfo.profile. - // Yahoo OAuth access token can be retrieved by calling: - // result.credential.accessToken - // Yahoo OAuth ID token can be retrieved by calling: - // result.credential.idToken + // IdP data available in result.additionalUserInfo.profile + // ... + + /** @type {firebase.auth.OAuthCredential} */ + const credential = result.credential; + + // Yahoo OAuth access token and ID token can be retrieved by calling: + var accessToken = credential.accessToken; + var idToken = credential.idToken; }) .catch((error) => { // Handle error. @@ -55,28 +49,30 @@ function yahooSignInPopup() { // [END auth_yahoo_signin_popup] } -function yahooSignInRedirect() { - var provider = yahooCreateProvider(); +function yahooSignInRedirect(provider) { // [START auth_yahoo_signin_redirect] firebase.auth().signInWithRedirect(provider); // [END auth_yahoo_signin_redirect] } -function yahooRedirectResult() { - // [START auth_yahoo_redirect_result] +function yahooSigninRedirectResult() { + // [START auth_yahoo_signin_redirect_result] firebase.auth().getRedirectResult() .then((result) => { - // User is signed in. - // IdP data available in result.additionalUserInfo.profile. - // Yahoo OAuth access token can be retrieved by calling: - // result.credential.accessToken - // Yahoo OAuth ID token can be retrieved by calling: - // result.credential.idToken + // IdP data available in result.additionalUserInfo.profile + // ... + + /** @type {firebase.auth.OAuthCredential} */ + const credential = result.credential; + + // Yahoo OAuth access token and ID token can be retrieved by calling: + var accessToken = credential.accessToken; + var idToken = credential.idToken; }) .catch((error) => { // Handle error. }); - // [END auth_yahoo_redirect_result] + // [END auth_yahoo_signin_redirect_result] } function yahooLinkPopup() { diff --git a/package.json b/package.json index 5722ddaa..6eb29b72 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "snippets-web", "version": "1.0.0", "scripts": { - "snippets": "npx ts-node scripts/separate-snippets.ts", + "snippets": "rimraf snippets && ts-node scripts/separate-snippets.ts", "lint": "git ls-files | grep -v 'snippets/' | grep '.js$' | xargs npx eslint", "format": "npm run lint -- --fix", "lerna-bootstrap": "lerna bootstrap --no-ci", @@ -12,6 +12,7 @@ "devDependencies": { "eslint": "^7.16.0", "lerna": "^3.22.1", + "rimraf": "^3.0.2", "ts-node": "^9.0.0", "typescript": "^3.8.3" } diff --git a/placeholder.js b/placeholder.js new file mode 100644 index 00000000..3d1a70e5 --- /dev/null +++ b/placeholder.js @@ -0,0 +1,6 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +// [START coming_soon] +// TODO: Snippet coming soon! +// [END coming_soon] diff --git a/scripts/separate-snippets.ts b/scripts/separate-snippets.ts index 8172dd31..dbc89c52 100644 --- a/scripts/separate-snippets.ts +++ b/scripts/separate-snippets.ts @@ -92,7 +92,7 @@ function removeFirstLineAfterComments(lines: string[]) { const firstNonComment = outputLines.findIndex( (l) => !l.startsWith("//") ); - if (isBlank(outputLines[firstNonComment])) { + if (firstNonComment >= 0 && isBlank(outputLines[firstNonComment])) { outputLines.splice(firstNonComment, 1); } @@ -186,6 +186,10 @@ function collectSnippets(filePath: string): SnippetsConfig { // Until we find an [END foo] tag. All lines we see between now and then // are part of the snippet content. const snippetName = startMatch[1]; + if (config.map[snippetName] !== undefined) { + throw new Error(`Detected more than one snippet with the tag ${snippetName}!`); + } + config.map[snippetName] = [line]; inSnippetNames.push(snippetName); } else if (endMatch) { diff --git a/snippets/README.md b/snippets/README.md deleted file mode 100644 index 8c1d1139..00000000 --- a/snippets/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# Generated Snippets - -## Overview - -This directory contains snippets generated by the `separate-snippets` script. -Snippets in this folder should **never** be updated directly instead please -edit the source file (indicated by a comment at the top). - -## Regenerating the Snippets - -Run `npm run snippets` from the root of this repository. - -## Using the Separator - -For a file to be included in the separator script it must contain a comment like this: - -```js -// [SNIPPETS_SEPARATION enabled] -``` - -By default separated snippets will have their name suffixed with `_modular` -but you can override this with a commment: - -```js -// [SNIPPETS_SUFFIX _banana] -``` diff --git a/snippets/auth-next/facebook/auth_facebook_provider_create.js b/snippets/auth-next/facebook/auth_facebook_provider_create.js new file mode 100644 index 00000000..93913be7 --- /dev/null +++ b/snippets/auth-next/facebook/auth_facebook_provider_create.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/facebook.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_facebook_provider_create_modular] +import { FacebookAuthProvider } from "firebase/auth"; + +const provider = new FacebookAuthProvider(); +// [END auth_facebook_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth-next/facebook/auth_facebook_provider_params.js b/snippets/auth-next/facebook/auth_facebook_provider_params.js new file mode 100644 index 00000000..04c8532b --- /dev/null +++ b/snippets/auth-next/facebook/auth_facebook_provider_params.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/facebook.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_facebook_provider_params_modular] +provider.setCustomParameters({ + 'display': 'popup' +}); +// [END auth_facebook_provider_params_modular] \ No newline at end of file diff --git a/snippets/auth-next/facebook/auth_facebook_provider_scopes.js b/snippets/auth-next/facebook/auth_facebook_provider_scopes.js new file mode 100644 index 00000000..ba67a6f3 --- /dev/null +++ b/snippets/auth-next/facebook/auth_facebook_provider_scopes.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/facebook.js +// +// To make edits to the snippets in this file, please edit the source + +// / [START auth_facebook_provider_scopes_modular] +provider.addScope('user_birthday'); +// [END auth_facebook_provider_scopes_modular] \ No newline at end of file diff --git a/snippets/auth-next/facebook/auth_facebook_signin_credential.js b/snippets/auth-next/facebook/auth_facebook_signin_credential.js index 56de399b..a5d8e551 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_credential.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_credential.js @@ -9,9 +9,9 @@ import { getAuth, signInWithCredential, FacebookAuthProvider } from "firebase/au // Sign in with the credential from the Facebook user. const auth = getAuth(firebaseApp); signInWithCredential(auth, credential) - .then((cred) => { + .then((result) => { // Signed in - // ... + const credential = FacebookAuthProvider.credentialFromResult(result); }) .catch((error) => { // Handle Errors here. diff --git a/snippets/auth-next/facebook/auth_facebook_signin_popup.js b/snippets/auth-next/facebook/auth_facebook_signin_popup.js new file mode 100644 index 00000000..65cc1fd1 --- /dev/null +++ b/snippets/auth-next/facebook/auth_facebook_signin_popup.js @@ -0,0 +1,32 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/facebook.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_facebook_signin_popup_modular] +import { getAuth, signInWithPopup, FacebookAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithPopup(auth, provider) + .then((result) => { + // The signed-in user info. + const user = result.user; + + // This gives you a Facebook Access Token. You can use it to access the Facebook API. + const credential = FacebookAuthProvider.credentialFromResult(result); + const accessToken = credential.accessToken; + + // ... + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = FacebookAuthProvider.credentialFromError(error); + + // ... + }); +// [END auth_facebook_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js b/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js new file mode 100644 index 00000000..a70191dc --- /dev/null +++ b/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js @@ -0,0 +1,27 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/facebook.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_facebook_signin_redirect_result_modular] +import { getAuth, getRedirectResult, FacebookAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +getRedirectResult(auth) + .then((result) => { + // This gives you a Facebook Access Token. You can use it to access the Facebook API. + const credential = FacebookAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + + const user = result.user; + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // AuthCredential type that was used. + const credential = FacebookAuthProvider.credentialFromError(error); + // ... + }); +// [END auth_facebook_signin_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_config.js b/snippets/auth-next/firebaseui/auth_fui_config.js deleted file mode 100644 index 2f616a08..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_config.js +++ /dev/null @@ -1,38 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_config_modular] -const uiConfig = { - callbacks: { - signInSuccessWithAuthResult: function(authResult, redirectUrl) { - // User successfully signed in. - // Return type determines whether we continue the redirect automatically - // or whether we leave that to developer to handle. - return true; - }, - uiShown: function() { - // The widget is rendered. - // Hide the loader. - document.getElementById('loader').style.display = 'none'; - } - }, - // Will use popup for IDP Providers sign-in flow instead of the default, redirect. - signInFlow: 'popup', - signInSuccessUrl: '', - signInOptions: [ - // Leave the lines as is for the providers you want to offer your users. - firebase.auth.GoogleAuthProvider.PROVIDER_ID, - firebase.auth.FacebookAuthProvider.PROVIDER_ID, - firebase.auth.TwitterAuthProvider.PROVIDER_ID, - firebase.auth.GithubAuthProvider.PROVIDER_ID, - firebase.auth.EmailAuthProvider.PROVIDER_ID, - firebase.auth.PhoneAuthProvider.PROVIDER_ID - ], - // Terms of service url. - tosUrl: '', - // Privacy policy url. - privacyPolicyUrl: '' -}; -// [END auth_fui_config_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_config_start.js b/snippets/auth-next/firebaseui/auth_fui_config_start.js deleted file mode 100644 index 07472907..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_config_start.js +++ /dev/null @@ -1,8 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_config_start_modular] -ui.start('#firebaseui-auth-container', uiConfig); -// [END auth_fui_config_start_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_email_link_result.js b/snippets/auth-next/firebaseui/auth_fui_email_link_result.js deleted file mode 100644 index 3487a1b4..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_email_link_result.js +++ /dev/null @@ -1,15 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_email_link_result_modular] -// Is there an email link sign-in? -if (ui.isPendingRedirect()) { - ui.start('#firebaseui-auth-container', uiConfig); -} -// This can also be done via: -if (firebase.auth().isSignInWithEmailLink(window.location.href)) { - ui.start('#firebaseui-auth-container', uiConfig); -} -// [END auth_fui_email_link_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_handle_anonymous.js b/snippets/auth-next/firebaseui/auth_fui_handle_anonymous.js deleted file mode 100644 index 7a67ae05..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_handle_anonymous.js +++ /dev/null @@ -1,44 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_handle_anonymous_modular] -// Temp variable to hold the anonymous user data if needed. -const data = null; -// Hold a reference to the anonymous current user. -const anonymousUser = firebase.auth().currentUser; -ui.start('#firebaseui-auth-container', { - // Whether to upgrade anonymous users should be explicitly provided. - // The user must already be signed in anonymously before FirebaseUI is - // rendered. - autoUpgradeAnonymousUsers: true, - signInSuccessUrl: '', - signInOptions: [ - firebase.auth.GoogleAuthProvider.PROVIDER_ID, - firebase.auth.FacebookAuthProvider.PROVIDER_ID, - firebase.auth.EmailAuthProvider.PROVIDER_ID, - firebase.auth.PhoneAuthProvider.PROVIDER_ID - ], - callbacks: { - // signInFailure callback must be provided to handle merge conflicts which - // occur when an existing credential is linked to an anonymous user. - signInFailure: (error) => { - // For merge conflicts, the error.code will be - // 'firebaseui/anonymous-upgrade-merge-conflict'. - if (error.code != 'firebaseui/anonymous-upgrade-merge-conflict') { - return Promise.resolve(); - } - // The credential the user tried to sign in with. - const cred = error.credential; - // Copy data from anonymous user to permanent user and delete anonymous - // user. - // ... - // Finish sign-in after data is copied. - return firebase.auth().signInWithCredential(cred).then(() => { - return; - }); - } - } -}); -// [END auth_fui_handle_anonymous_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_init.js b/snippets/auth-next/firebaseui/auth_fui_init.js deleted file mode 100644 index fc25d632..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_init.js +++ /dev/null @@ -1,8 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_init_modular] -const ui = new firebaseui.auth.AuthUI(firebase.auth()); -// [END auth_fui_init_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_email.js b/snippets/auth-next/firebaseui/auth_fui_start_email.js deleted file mode 100644 index 7ddabefc..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_start_email.js +++ /dev/null @@ -1,13 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_start_email_modular] -ui.start('#firebaseui-auth-container', { - signInOptions: [ - firebase.auth.EmailAuthProvider.PROVIDER_ID - ], - // Other config options... -}); -// [END auth_fui_start_email_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_email_link.js b/snippets/auth-next/firebaseui/auth_fui_start_email_link.js deleted file mode 100644 index de07a4e3..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_start_email_link.js +++ /dev/null @@ -1,16 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_start_email_link_modular] -ui.start('#firebaseui-auth-container', { - signInOptions: [ - { - provider: firebase.auth.EmailAuthProvider.PROVIDER_ID, - signInMethod: firebase.auth.EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD - } - ], - // Other config options... -}); -// [END auth_fui_start_email_link_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_email_link_options.js b/snippets/auth-next/firebaseui/auth_fui_start_email_link_options.js deleted file mode 100644 index 1e7ba122..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_start_email_link_options.js +++ /dev/null @@ -1,45 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_start_email_link_options_modular] -ui.start('#firebaseui-auth-container', { - signInOptions: [ - { - provider: firebase.auth.EmailAuthProvider.PROVIDER_ID, - signInMethod: firebase.auth.EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD, - // Allow the user the ability to complete sign-in cross device, - // including the mobile apps specified in the ActionCodeSettings - // object below. - forceSameDevice: false, - // Used to define the optional firebase.auth.ActionCodeSettings if - // additional state needs to be passed along request and whether to open - // the link in a mobile app if it is installed. - emailLinkSignIn: () => { - return { - // Additional state showPromo=1234 can be retrieved from URL on - // sign-in completion in signInSuccess callback by checking - // window.location.href. - url: 'https://www.example.com/completeSignIn?showPromo=1234', - // Custom FDL domain. - dynamicLinkDomain: 'example.page.link', - // Always true for email link sign-in. - handleCodeInApp: true, - // Whether to handle link in iOS app if installed. - iOS: { - bundleId: 'com.example.ios' - }, - // Whether to handle link in Android app if opened in an Android - // device. - android: { - packageName: 'com.example.android', - installApp: true, - minimumVersion: '12' - } - }; - } - } - ] -}); -// [END auth_fui_start_email_link_options_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_email_options.js b/snippets/auth-next/firebaseui/auth_fui_start_email_options.js deleted file mode 100644 index 8dfffff0..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_start_email_options.js +++ /dev/null @@ -1,15 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_start_email_options_modular] -ui.start('#firebaseui-auth-container', { - signInOptions: [ - { - provider: firebase.auth.EmailAuthProvider.PROVIDER_ID, - requireDisplayName: false - } - ] -}); -// [END auth_fui_start_email_options_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_oauth.js b/snippets/auth-next/firebaseui/auth_fui_start_oauth.js deleted file mode 100644 index da946c75..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_start_oauth.js +++ /dev/null @@ -1,17 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_start_oauth_modular] -ui.start('#firebaseui-auth-container', { - signInOptions: [ - // List of OAuth providers supported. - firebase.auth.GoogleAuthProvider.PROVIDER_ID, - firebase.auth.FacebookAuthProvider.PROVIDER_ID, - firebase.auth.TwitterAuthProvider.PROVIDER_ID, - firebase.auth.GithubAuthProvider.PROVIDER_ID - ], - // Other config options... -}); -// [END auth_fui_start_oauth_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_oauth_options.js b/snippets/auth-next/firebaseui/auth_fui_start_oauth_options.js deleted file mode 100644 index af787c1f..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_start_oauth_options.js +++ /dev/null @@ -1,37 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_start_oauth_options_modular] -ui.start('#firebaseui-auth-container', { - signInOptions: [ - { - provider: firebase.auth.GoogleAuthProvider.PROVIDER_ID, - scopes: [ - 'https://www.googleapis.com/auth/contacts.readonly' - ], - customParameters: { - // Forces account selection even when one account - // is available. - prompt: 'select_account' - } - }, - { - provider: firebase.auth.FacebookAuthProvider.PROVIDER_ID, - scopes: [ - 'public_profile', - 'email', - 'user_likes', - 'user_friends' - ], - customParameters: { - // Forces password re-entry. - auth_type: 'reauthenticate' - } - }, - firebase.auth.TwitterAuthProvider.PROVIDER_ID, // Twitter does not support scopes. - firebase.auth.EmailAuthProvider.PROVIDER_ID // Other providers don't need to be given as object. - ] -}); -// [END auth_fui_start_oauth_options_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_phone.js b/snippets/auth-next/firebaseui/auth_fui_start_phone.js deleted file mode 100644 index bd6d1b1d..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_start_phone.js +++ /dev/null @@ -1,13 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_start_phone_modular] -ui.start('#firebaseui-auth-container', { - signInOptions: [ - firebase.auth.PhoneAuthProvider.PROVIDER_ID - ], - // Other config options... -}); -// [END auth_fui_start_phone_modular] \ No newline at end of file diff --git a/snippets/auth-next/firebaseui/auth_fui_start_phone_options.js b/snippets/auth-next/firebaseui/auth_fui_start_phone_options.js deleted file mode 100644 index 8ae0de1d..00000000 --- a/snippets/auth-next/firebaseui/auth_fui_start_phone_options.js +++ /dev/null @@ -1,36 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth-next/firebaseui.js -// -// To make edits to the snippets in this file, please edit the source - -// [START auth_fui_start_phone_options_modular] -ui.start('#firebaseui-auth-container', { - signInOptions: [ - { - provider: firebase.auth.PhoneAuthProvider.PROVIDER_ID, - recaptchaParameters: { - type: 'image', // 'audio' - size: 'normal', // 'invisible' or 'compact' - badge: 'bottomleft' //' bottomright' or 'inline' applies to invisible. - }, - defaultCountry: 'GB', // Set default country to the United Kingdom (+44). - // For prefilling the national number, set defaultNationNumber. - // This will only be observed if only phone Auth provider is used since - // for multiple providers, the NASCAR screen will always render first - // with a 'sign in with phone number' button. - defaultNationalNumber: '1234567890', - // You can also pass the full phone number string instead of the - // 'defaultCountry' and 'defaultNationalNumber'. However, in this case, - // the first country ID that matches the country code will be used to - // populate the country selector. So for countries that share the same - // country code, the selected country may not be the expected one. - // In that case, pass the 'defaultCountry' instead to ensure the exact - // country is selected. The 'defaultCountry' and 'defaultNationaNumber' - // will always have higher priority than 'loginHint' which will be ignored - // in their favor. In this case, the default country will be 'GB' even - // though 'loginHint' specified the country code as '+1'. - loginHint: '+11234567890' - } - ] -}); -// [END auth_fui_start_phone_options_modular] \ No newline at end of file diff --git a/snippets/auth-next/github/auth_github_provider_create.js b/snippets/auth-next/github/auth_github_provider_create.js new file mode 100644 index 00000000..eb5250d9 --- /dev/null +++ b/snippets/auth-next/github/auth_github_provider_create.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/github.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_github_provider_create_modular] +import { GithubAuthProvider } from "firebase/auth"; + +const provider = new GithubAuthProvider(); +// [END auth_github_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth-next/github/auth_github_provider_params.js b/snippets/auth-next/github/auth_github_provider_params.js new file mode 100644 index 00000000..159dcd8c --- /dev/null +++ b/snippets/auth-next/github/auth_github_provider_params.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/github.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_github_provider_params_modular] +provider.setCustomParameters({ + 'allow_signup': 'false' +}); +// [END auth_github_provider_params_modular] \ No newline at end of file diff --git a/snippets/auth-next/github/auth_github_provider_scopes.js b/snippets/auth-next/github/auth_github_provider_scopes.js new file mode 100644 index 00000000..09f26298 --- /dev/null +++ b/snippets/auth-next/github/auth_github_provider_scopes.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/github.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_github_provider_scopes_modular] +provider.addScope('repo'); +// [END auth_github_provider_scopes_modular] \ No newline at end of file diff --git a/snippets/auth-next/github/auth_github_signin_popup.js b/snippets/auth-next/github/auth_github_signin_popup.js new file mode 100644 index 00000000..b5ac46a2 --- /dev/null +++ b/snippets/auth-next/github/auth_github_signin_popup.js @@ -0,0 +1,29 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/github.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_github_signin_popup_modular] +import { getAuth, signInWithPopup, GithubAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithPopup(auth, provider) + .then((result) => { + // This gives you a GitHub Access Token. You can use it to access the GitHub API. + const credential = GithubAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + + // The signed-in user info. + const user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = GithubAuthProvider.credentialFromError(error); + // ... + }); +// [END auth_github_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/github/auth_github_signin_redirect_result.js b/snippets/auth-next/github/auth_github_signin_redirect_result.js new file mode 100644 index 00000000..423440fa --- /dev/null +++ b/snippets/auth-next/github/auth_github_signin_redirect_result.js @@ -0,0 +1,31 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/github.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_github_signin_redirect_result_modular] +import { getAuth, getRedirectResult, GithubAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +getRedirectResult(auth) + .then((result) => { + const credential = GithubAuthProvider.credentialFromResult(result); + if (credential) { + // This gives you a GitHub Access Token. You can use it to access the GitHub API. + const token = credential.accessToken; + // ... + } + + // The signed-in user info. + const user = result.user; + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = GithubAuthProvider.credentialFromError(error); + // ... + }); +// [END auth_github_signin_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/google-signin/auth_google_provider_create.js b/snippets/auth-next/google-signin/auth_google_provider_create.js new file mode 100644 index 00000000..6d696d21 --- /dev/null +++ b/snippets/auth-next/google-signin/auth_google_provider_create.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/google-signin.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_google_provider_create_modular] +import { GoogleAuthProvider } from "firebase/auth"; + +const provider = new GoogleAuthProvider(); +// [END auth_google_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth-next/google-signin/auth_google_provider_params.js b/snippets/auth-next/google-signin/auth_google_provider_params.js new file mode 100644 index 00000000..4799da72 --- /dev/null +++ b/snippets/auth-next/google-signin/auth_google_provider_params.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/google-signin.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_google_provider_params_modular] +provider.setCustomParameters({ + 'login_hint': 'user@example.com' +}); +// [END auth_google_provider_params_modular] \ No newline at end of file diff --git a/snippets/auth-next/google-signin/auth_google_provider_scopes.js b/snippets/auth-next/google-signin/auth_google_provider_scopes.js new file mode 100644 index 00000000..f370a854 --- /dev/null +++ b/snippets/auth-next/google-signin/auth_google_provider_scopes.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/google-signin.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_google_provider_scopes_modular] +provider.addScope('https://www.googleapis.com/auth/contacts.readonly'); +// [END auth_google_provider_scopes_modular] \ No newline at end of file diff --git a/snippets/auth-next/google-signin/auth_google_signin_popup.js b/snippets/auth-next/google-signin/auth_google_signin_popup.js new file mode 100644 index 00000000..b5763bf8 --- /dev/null +++ b/snippets/auth-next/google-signin/auth_google_signin_popup.js @@ -0,0 +1,28 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/google-signin.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_google_signin_popup_modular] +import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithPopup(auth, provider) + .then((result) => { + // This gives you a Google Access Token. You can use it to access the Google API. + const credential = GoogleAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + // The signed-in user info. + const user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = GoogleAuthProvider.credentialFromError(error); + // ... + }); +// [END auth_google_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js b/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js new file mode 100644 index 00000000..410eae3f --- /dev/null +++ b/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js @@ -0,0 +1,28 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/google-signin.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_google_signin_redirect_result_modular] +import { getAuth, getRedirectResult, GoogleAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +getRedirectResult(auth) + .then((result) => { + // This gives you a Google Access Token. You can use it to access Google APIs. + const credential = GoogleAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + + // The signed-in user info. + const user = result.user; + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = GoogleAuthProvider.credentialFromError(error); + // ... + }); +// [END auth_google_signin_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/phone-auth/auth_set_language_code.js b/snippets/auth-next/index/auth_set_language_code.js similarity index 93% rename from snippets/auth-next/phone-auth/auth_set_language_code.js rename to snippets/auth-next/index/auth_set_language_code.js index 5f904381..de11d4ce 100644 --- a/snippets/auth-next/phone-auth/auth_set_language_code.js +++ b/snippets/auth-next/index/auth_set_language_code.js @@ -1,5 +1,5 @@ // This snippet file was generated by processing the source file: -// ./auth-next/phone-auth.js +// ./auth-next/index.js // // To make edits to the snippets in this file, please edit the source diff --git a/snippets/auth-next/index/auth_signin_credential.js b/snippets/auth-next/index/auth_signin_credential.js new file mode 100644 index 00000000..6885e033 --- /dev/null +++ b/snippets/auth-next/index/auth_signin_credential.js @@ -0,0 +1,24 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_signin_credential_modular] +import { getAuth, signInWithCredential } from "firebase/auth"; + +// Sign in with the credential from the user. +const auth = getAuth(firebaseApp); +signInWithCredential(auth, credential) + .then((result) => { + // Signed in + // ... + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // ... + }); +// [END auth_signin_credential_modular] \ No newline at end of file diff --git a/snippets/auth-next/index/auth_signin_redirect.js b/snippets/auth-next/index/auth_signin_redirect.js new file mode 100644 index 00000000..9062ac87 --- /dev/null +++ b/snippets/auth-next/index/auth_signin_redirect.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_signin_redirect_modular] +import { getAuth, signInWithRedirect } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithRedirect(auth, provider); +// [END auth_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_provider_scopes.js b/snippets/auth-next/microsoft-oauth/auth_msft_provider_scopes.js new file mode 100644 index 00000000..6c4d2fed --- /dev/null +++ b/snippets/auth-next/microsoft-oauth/auth_msft_provider_scopes.js @@ -0,0 +1,9 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/microsoft-oauth.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_msft_provider_scopes_modular] +provider.addScope('mail.read'); +provider.addScope('calendars.read'); +// [END auth_msft_provider_scopes_modular] \ No newline at end of file diff --git a/snippets/auth-next/microsoft-oauth/auth_msf_redirect_result.js b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js similarity index 87% rename from snippets/auth-next/microsoft-oauth/auth_msf_redirect_result.js rename to snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js index 9b892ec2..2d624588 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msf_redirect_result.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START auth_msf_redirect_result_modular] +// [START auth_msft_signin_redirect_result_modular] import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; const auth = getAuth(firebaseApp); @@ -20,4 +20,4 @@ getRedirectResult(auth) .catch((error) => { // Handle error. }); -// [END auth_msf_redirect_result_modular] \ No newline at end of file +// [END auth_msft_signin_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/twitter/auth_twitter_provider_create.js b/snippets/auth-next/twitter/auth_twitter_provider_create.js new file mode 100644 index 00000000..496ae5f5 --- /dev/null +++ b/snippets/auth-next/twitter/auth_twitter_provider_create.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/twitter.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_twitter_provider_create_modular] +import { TwitterAuthProvider } from "firebase/auth"; + +const provider = new TwitterAuthProvider(); +// [END auth_twitter_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth-next/twitter/auth_twitter_provider_params.js b/snippets/auth-next/twitter/auth_twitter_provider_params.js new file mode 100644 index 00000000..cb7c7a39 --- /dev/null +++ b/snippets/auth-next/twitter/auth_twitter_provider_params.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/twitter.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_twitter_provider_params_modular] +provider.setCustomParameters({ + 'lang': 'es' +}); +// [END auth_twitter_provider_params_modular] \ No newline at end of file diff --git a/snippets/auth-next/twitter/auth_twitter_signin_popup.js b/snippets/auth-next/twitter/auth_twitter_signin_popup.js new file mode 100644 index 00000000..d500a504 --- /dev/null +++ b/snippets/auth-next/twitter/auth_twitter_signin_popup.js @@ -0,0 +1,31 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/twitter.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_twitter_signin_popup_modular] +import { getAuth, signInWithPopup, TwitterAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +signInWithPopup(auth, provider) + .then((result) => { + // This gives you a the Twitter OAuth 1.0 Access Token and Secret. + // You can use these server side with your app's credentials to access the Twitter API. + const credential = TwitterAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + const secret = credential.secret; + + // The signed-in user info. + const user = result.user; + // ... + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = TwitterAuthProvider.credentialFromError(error); + // ... + }); +// [END auth_twitter_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js b/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js new file mode 100644 index 00000000..5d781644 --- /dev/null +++ b/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js @@ -0,0 +1,31 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/twitter.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_twitter_signin_redirect_result_modular] +import { getAuth, getRedirectResult, TwitterAuthProvider } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +getRedirectResult(auth) + .then((result) => { + // This gives you a the Twitter OAuth 1.0 Access Token and Secret. + // You can use these server side with your app's credentials to access the Twitter API. + const credential = TwitterAuthProvider.credentialFromResult(result); + const token = credential.accessToken; + const secret = credential.secret; + // ... + + // The signed-in user info. + const user = result.user; + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = TwitterAuthProvider.credentialFromError(error); + // ... + }); +// [END auth_twitter_signin_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_create.js similarity index 75% rename from snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider.js rename to snippets/auth-next/yahoo-oauth/auth_yahoo_provider_create.js index 3b7c4b93..c30a64f0 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_create.js @@ -3,8 +3,8 @@ // // To make edits to the snippets in this file, please edit the source -// [START auth_yahoo_create_provider_modular] +// [START auth_yahoo_provider_create_modular] import { OAuthProvider } from "firebase/auth"; const provider = new OAuthProvider('yahoo.com'); -// [END auth_yahoo_create_provider_modular] \ No newline at end of file +// [END auth_yahoo_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_params.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_params.js similarity index 75% rename from snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_params.js rename to snippets/auth-next/yahoo-oauth/auth_yahoo_provider_params.js index 83e28c35..7bd28592 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_params.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_params.js @@ -3,11 +3,11 @@ // // To make edits to the snippets in this file, please edit the source -// [START auth_yahoo_create_provider_params_modular] +// [START auth_yahoo_provider_params_modular] provider.setCustomParameters({ // Prompt user to re-authenticate to Yahoo. prompt: 'login', // Localize to French. language: 'fr' }); -// [END auth_yahoo_create_provider_params_modular] \ No newline at end of file +// [END auth_yahoo_provider_params_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_scopes.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_scopes.js similarity index 78% rename from snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_scopes.js rename to snippets/auth-next/yahoo-oauth/auth_yahoo_provider_scopes.js index bb216718..24e059c8 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_create_provider_scopes.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_scopes.js @@ -3,10 +3,10 @@ // // To make edits to the snippets in this file, please edit the source -// [START auth_yahoo_create_provider_scopes_modular] +// [START auth_yahoo_provider_scopes_modular] // Request access to Yahoo Mail API. provider.addScope('mail-r'); // Request read/write access to user contacts. // This must be preconfigured in the app's API permissions. provider.addScope('sdct-w'); -// [END auth_yahoo_create_provider_scopes_modular] \ No newline at end of file +// [END auth_yahoo_provider_scopes_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js index 2bd94b16..cad34a24 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js @@ -4,15 +4,15 @@ // To make edits to the snippets in this file, please edit the source // [START auth_yahoo_signin_popup_modular] -import { getAuth, signInWithPopup,OAuthProvider } from "firebase/auth"; +import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth"; const auth = getAuth(firebaseApp); signInWithPopup(auth, provider) .then((result) => { - // User is signed in. - // IdP data available in result.additionalUserInfo.profile. + // IdP data available in result.additionalUserInfo.profile + // ... - // Get the OAuth access token and ID Token + // Yahoo OAuth access token and ID token can be retrieved by calling: const credential = OAuthProvider.credentialFromResult(result); const accessToken = credential.accessToken; const idToken = credential.idToken; diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_redirect_result.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js similarity index 68% rename from snippets/auth-next/yahoo-oauth/auth_yahoo_redirect_result.js rename to snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js index f7ed546b..11be5523 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_redirect_result.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js @@ -3,16 +3,16 @@ // // To make edits to the snippets in this file, please edit the source -// [START auth_yahoo_redirect_result_modular] +// [START auth_yahoo_signin_redirect_result_modular] import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; const auth = getAuth(firebaseApp); getRedirectResult(auth) .then((result) => { - // User is signed in. - // IdP data available in result.additionalUserInfo.profile. + // IdP data available in result.additionalUserInfo.profile + // ... - // Get the OAuth access token and ID Token + // Yahoo OAuth access token and ID token can be retrieved by calling: const credential = OAuthProvider.credentialFromResult(result); const accessToken = credential.accessToken; const idToken = credential.idToken; @@ -20,4 +20,4 @@ getRedirectResult(auth) .catch((error) => { // Handle error. }); -// [END auth_yahoo_redirect_result_modular] \ No newline at end of file +// [END auth_yahoo_signin_redirect_result_modular] \ No newline at end of file diff --git a/snippets/placeholder.js b/snippets/placeholder.js deleted file mode 100644 index c5da7069..00000000 --- a/snippets/placeholder.js +++ /dev/null @@ -1,3 +0,0 @@ -// [START coming_soon_modular] -// TODO: Snippet coming soon! -// [END coming_soon_modular] diff --git a/snippets/placeholder/coming_soon.js b/snippets/placeholder/coming_soon.js new file mode 100644 index 00000000..715d6a3d --- /dev/null +++ b/snippets/placeholder/coming_soon.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./placeholder.js +// +// To make edits to the snippets in this file, please edit the source + +// [START coming_soon_modular] +// TODO: Snippet coming soon! +// [END coming_soon_modular] \ No newline at end of file From 0bd7a6abbd7f18ad4faaf01084e9e05037a6cff8 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Thu, 7 Jan 2021 14:14:57 +0000 Subject: [PATCH 063/235] Cloud Firestore --> Firestore (#80) --- firestore-next/test.firestore.js | 2 +- firestore/test.firestore.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 445f35b3..0be9c3ef 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -68,7 +68,7 @@ describe("firestore", () => { const app = initializeApp({ apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', - projectId: '### CLOUD FIRESTORE PROJECT ID ###', + projectId: '### FIREBASE PROJECT ID ###', } ,"persisted_app"); const db = getFirestore(app); diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index d2c7602d..fe600769 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -56,7 +56,7 @@ describe("firestore", () => { firebase.initializeApp({ apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', - projectId: '### CLOUD FIRESTORE PROJECT ID ###', + projectId: '### FIREBASE PROJECT ID ###', } ,"persisted_app"); // [START initialize_persistence] From b7b8c7274f63db4c01c6e88e656d8dd5bd5aabf9 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 8 Jan 2021 02:37:32 -0800 Subject: [PATCH 064/235] Auto-update dependencies. (#81) --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/auth/package.json b/auth/package.json index 97182df1..6af79a47 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.1", + "firebase": "^8.2.2", "firebaseui": "^4.7.1" } } diff --git a/database/package.json b/database/package.json index 2c58101a..763ebb14 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.1" + "firebase": "^8.2.2" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 0780a79c..f2483182 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.1" + "firebase": "^8.2.2" } } diff --git a/firestore/package.json b/firestore/package.json index 3800a011..df5faf59 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.1", + "firebase": "^8.2.2", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index b9ba6340..aa09b8f3 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.1" + "firebase": "^8.2.2" } } diff --git a/installations/package.json b/installations/package.json index 0b8ea7ef..64ac9086 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.1" + "firebase": "^8.2.2" } } diff --git a/perf/package.json b/perf/package.json index d27b16ab..1c259bef 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.1" + "firebase": "^8.2.2" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index fb9b928b..db3c3182 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.1" + "firebase": "^8.2.2" } } From 2309082b9ca8ce11a9c5864781817b93dcbd8987 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 8 Jan 2021 05:59:00 -0800 Subject: [PATCH 065/235] Auto-update dependencies. (#82) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 7c5911bb..54ff25bd 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From 1452a031ee1b7904a361b23391af8533237eab82 Mon Sep 17 00:00:00 2001 From: KlutchDEV Date: Mon, 11 Jan 2021 05:19:57 -0500 Subject: [PATCH 066/235] Simple typo (#84) --- auth-next/email.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth-next/email.js b/auth-next/email.js index 368ad8a8..07a3cc3a 100644 --- a/auth-next/email.js +++ b/auth-next/email.js @@ -29,7 +29,7 @@ function signInWithEmailPassword() { // [END auth_signin_password] } -function signUpWithEmailPasswoerd() { +function signUpWithEmailPassword() { const email = "test@example.com"; const password = "hunter2"; From 6344eeb4d72df3bca3af1a7409110694aaa15573 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 15 Jan 2021 02:32:40 -0800 Subject: [PATCH 067/235] Auto-update dependencies. (#85) --- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/auth/package.json b/auth/package.json index 6af79a47..c814359e 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.2", + "firebase": "^8.2.3", "firebaseui": "^4.7.1" } } diff --git a/database/package.json b/database/package.json index 763ebb14..1063856e 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.2" + "firebase": "^8.2.3" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index f2483182..ab98eba2 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.2" + "firebase": "^8.2.3" } } diff --git a/firestore/package.json b/firestore/package.json index df5faf59..eada0581 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.2", + "firebase": "^8.2.3", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index aa09b8f3..6cf0d5cf 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.2" + "firebase": "^8.2.3" } } diff --git a/installations/package.json b/installations/package.json index 64ac9086..13361e6d 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.2" + "firebase": "^8.2.3" } } diff --git a/perf/package.json b/perf/package.json index 1c259bef..6689d178 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.2" + "firebase": "^8.2.3" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index db3c3182..94072b11 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.2" + "firebase": "^8.2.3" } } From 1f7e6e98a56964caa5854ddc1c659f245f139bd1 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 15 Jan 2021 12:30:03 +0000 Subject: [PATCH 068/235] Move quickstart-js snippets (#86) --- lerna.json | 4 ++- messaging/index.js | 70 +++++++++++++++++++++++++++++++++++++ messaging/package.json | 11 ++++++ messaging/service-worker.js | 53 ++++++++++++++++++++++++++++ storage/index.js | 33 +++++++++++++++++ storage/package.json | 11 ++++++ 6 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 messaging/index.js create mode 100644 messaging/package.json create mode 100644 messaging/service-worker.js create mode 100644 storage/index.js create mode 100644 storage/package.json diff --git a/lerna.json b/lerna.json index 6397cfbf..8080d78a 100644 --- a/lerna.json +++ b/lerna.json @@ -10,10 +10,12 @@ "functions", "functions-next", "installations", + "messaging", "perf", "perf-next", "remoteconfig", - "remoteconfig-next" + "remoteconfig-next", + "storage" ], "version": "1.0.0" } diff --git a/messaging/index.js b/messaging/index.js new file mode 100644 index 00000000..073d8c2a --- /dev/null +++ b/messaging/index.js @@ -0,0 +1,70 @@ +import firebase from "firebase/app"; +import "firebase/messaging"; + +function getMessagingObject() { + // [START messaging_get_messaging_object] + const messaging = firebase.messaging(); + // [END messaging_get_messaging_object] +} + +function receiveMessage() { + const messaging = firebase.messaging(); + // [START messaging_receive_message] + // Handle incoming messages. Called when: + // - a message is received while the app has focus + // - the user clicks on an app notification created by a service worker + // `messaging.onBackgroundMessage` handler. + messaging.onMessage((payload) => { + console.log('Message received. ', payload); + // ... + }); + // [END messaging_receive_message] +} + +function getToken() { + const messaging = firebase.messaging(); + // [START messaging_get_token] + // Get registration token. Initially this makes a network call, once retrieved + // subsequent calls to getToken will return from cache. + messaging.getToken({ vapidKey: '' }).then((currentToken) => { + if (currentToken) { + // Send the token to your server and update the UI if necessary + // ... + } else { + // Show permission request UI + console.log('No registration token available. Request permission to generate one.'); + // ... + } + }).catch((err) => { + console.log('An error occurred while retrieving token. ', err); + // ... + }); + // [END messaging_get_token] +} + +function requestPermission() { + // [START messaging_request_permission] + Notification.requestPermission().then((permission) => { + if (permission === 'granted') { + console.log('Notification permission granted.'); + // TODO(developer): Retrieve a registration token for use with FCM. + // ... + } else { + console.log('Unable to get permission to notify.'); + } + }); + // [END messaging_request_permission] +} + +function deleteToken() { + const messaging = firebase.messaging(); + + // [START messaging_delete_token] + messaging.deleteToken().then(() => { + console.log('Token deleted.'); + // ... + }).catch((err) => { + console.log('Unable to delete token. ', err); + }); + // [END messaging_delete_token] +} diff --git a/messaging/package.json b/messaging/package.json new file mode 100644 index 00000000..6ca0ae56 --- /dev/null +++ b/messaging/package.json @@ -0,0 +1,11 @@ +{ + "name": "messaging", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^8.2.3" + } +} diff --git a/messaging/service-worker.js b/messaging/service-worker.js new file mode 100644 index 00000000..20179153 --- /dev/null +++ b/messaging/service-worker.js @@ -0,0 +1,53 @@ +import firebase from "firebase/app"; +import "firebase/messaging"; + +// See: https://github.com/microsoft/TypeScript/issues/14877 +/** @type {ServiceWorkerGlobalScope} */ +let self; + +function initInSw() { + // [START messaging_init_in_sw] + // Give the service worker access to Firebase Messaging. + // Note that you can only use Firebase Messaging here. Other Firebase libraries + // are not available in the service worker. + importScripts('https://www.gstatic.com/firebasejs/8.2.3/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.3/firebase-messaging.js'); + + // Initialize the Firebase app in the service worker by passing in + // your app's Firebase config object. + // https://firebase.google.com/docs/web/setup#config-object + firebase.initializeApp({ + apiKey: 'api-key', + authDomain: 'project-id.firebaseapp.com', + databaseURL: 'https://project-id.firebaseio.com', + projectId: 'project-id', + storageBucket: 'project-id.appspot.com', + messagingSenderId: 'sender-id', + appId: 'app-id', + measurementId: 'G-measurement-id', + }); + + // Retrieve an instance of Firebase Messaging so that it can handle background + // messages. + const messaging = firebase.messaging(); + // [END messaging_init_in_sw] +} + +function onBackgroundMessage() { + const messaging = firebase.messaging(); + + // [START messaging_on_background_message] + messaging.onBackgroundMessage((payload) => { + console.log('[firebase-messaging-sw.js] Received background message ', payload); + // Customize notification here + const notificationTitle = 'Background Message Title'; + const notificationOptions = { + body: 'Background Message body.', + icon: '/firebase-logo.png' + }; + + self.registration.showNotification(notificationTitle, + notificationOptions); + }); + // [END messaging_on_background_message] +} diff --git a/storage/index.js b/storage/index.js new file mode 100644 index 00000000..02598d88 --- /dev/null +++ b/storage/index.js @@ -0,0 +1,33 @@ +import firebase from "firebase/app"; +import "firebase/storage"; + +/** + * @param {File} file + */ +function storageOnComplete(file) { + // The file param would be a File object from a file selection event in the browser. + // See: + // - https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications + // - https://developer.mozilla.org/en-US/docs/Web/API/File + + const metadata = { + 'contentType': file.type + }; + + // [START storage_on_complete] + const storageRef = firebase.storage().ref(); + storageRef.child('images/' + file.name).put(file, metadata) + .then((snapshot) => { + console.log('Uploaded', snapshot.totalBytes, 'bytes.'); + console.log('File metadata:', snapshot.metadata); + // Let's get a download URL for the file. + snapshot.ref.getDownloadURL().then((url) => { + console.log('File available at', url); + // ... + }); + }).catch((error) => { + console.error('Upload failed', error); + // ... + }); + // [END storage_on_complete] +} diff --git a/storage/package.json b/storage/package.json new file mode 100644 index 00000000..655f1d3c --- /dev/null +++ b/storage/package.json @@ -0,0 +1,11 @@ +{ + "name": "storage", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^8.2.3" + } +} From c0ca18d8abb53e338956fbbffe9731e14b9b7e4c Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 15 Jan 2021 05:20:06 -0800 Subject: [PATCH 069/235] Auto-update dependencies. (#87) --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 54ff25bd..a02a895c 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From 67bda8b68e1d202b0dd3eb464383a4eefb449170 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Wed, 20 Jan 2021 17:23:41 +0000 Subject: [PATCH 070/235] Add analytics snippets (#88) --- analytics/ecommerce.js | 248 +++++++++++++++++++++++++++++++++++++++++ analytics/index.js | 40 +++++++ analytics/package.json | 11 ++ lerna.json | 1 + 4 files changed, 300 insertions(+) create mode 100644 analytics/ecommerce.js create mode 100644 analytics/index.js create mode 100644 analytics/package.json diff --git a/analytics/ecommerce.js b/analytics/ecommerce.js new file mode 100644 index 00000000..6e5216bd --- /dev/null +++ b/analytics/ecommerce.js @@ -0,0 +1,248 @@ +import firebase from "firebase/app"; +import "firebase/analytics"; + +// [START analytics_ecommerce_items] +// A pair of jeggings +const item_jeggings = { + item_id: 'SKU_123', + item_name: 'jeggings', + item_category: 'pants', + item_variant: 'black', + item_brand: 'Google', + price: 9.99 +}; + +// A pair of boots +const item_boots = { + item_id: 'SKU_456', + item_name: 'boots', + item_category: 'shoes', + item_variant: 'brown', + item_brand: 'Google', + price: 24.99 +}; + +// A pair of socks +const item_socks = { + item_id: 'SKU_789', + item_name: 'ankle_socks', + item_category: 'socks', + item_variant: 'red', + item_brand: 'Google', + price: 5.99 +}; +// [END analytics_ecommerce_items] + +function ecommerceViewItemList() { + // [START analytics_ecommerce_view_item_list] + // Prepare ecommerce params + const params1 = { + item_list_id: 'L001', + item_list_name: 'Related products', + items: [item_jeggings, item_boots, item_socks] + }; + + // Log event + firebase.analytics().logEvent(firebase.analytics.EventName.VIEW_ITEM_LIST, params1); + // [END analytics_ecommerce_view_item_list] +} + +function ecommerceSelectItem() { + // [START analytics_ecommerce_select_item] + // Prepare ecommerce event params + const params2 = { + item_list_id: 'L001', + item_list_name: 'Related products', + items: [item_jeggings] + }; + + // Log event + firebase.analytics().logEvent(firebase.analytics.EventName.SELECT_ITEM, params2); + // [END analytics_ecommerce_select_item] +} + +function ecommerceViewItemDetails() { + // [START analytics_ecommerce_view_item_details] + // Prepare ecommerce event params + const params3 = { + currency: 'USD', + value: 9.99, + items: [item_jeggings] + }; + + // Log event + firebase.analytics().logEvent(firebase.analytics.EventName.VIEW_ITEM, params3); + // [END analytics_ecommerce_view_item_details] +} + +function ecommerceAddCart() { + // [START analytics_ecommerce_add_cart] + // Specify order quantity + const item_jeggings_quantity = { + ...item_jeggings, + quantity: 2 + }; + + // Prepare ecommerce bundle + const params4 = { + currency: 'USD', + value: 19.98, + items: [item_jeggings_quantity] + }; + + // Log event when a product is added to a wishlist + firebase.analytics().logEvent(firebase.analytics.EventName.ADD_TO_WISHLIST, params4); + + // Log event when a product is added to the cart + firebase.analytics().logEvent(firebase.analytics.EventName.ADD_TO_CART, params4); + // [END analytics_ecommerce_add_cart] +} + +function ecommerceViewCart() { + // [START analytics_ecommerce_view_cart] + // Specify order quantity + const item_jeggings_quantity = { + ...item_jeggings, + quantity: 2 + }; + + const item_boots_quantity = { + ...item_boots, + quantity: 1 + }; + + // Prepare ecommerce params + const params5 = { + currency: 'USD', + value: 44.97, + items: [item_jeggings_quantity, item_boots_quantity] + }; + + // Log event when the cart is viewed + firebase.analytics().logEvent(firebase.analytics.EventName.VIEW_CART, params5); + // [END analytics_ecommerce_view_cart] +} + +function ecommerceRemoveCart() { + // [START analytics_ecommerce_remove_cart] + // Prepare ecommerce params + const params6 = { + currency: 'USD', + value: 24.99, + items: [item_jeggings] + }; + + // Log event + firebase.analytics().logEvent(firebase.analytics.EventName.REMOVE_FROM_CART, params6); + // [END analytics_ecommerce_remove_cart] +} + +function ecommerceCheckout() { + // [START analytics_ecommerce_checkout] + // Prepare ecommerce params + const params7 = { + currency: 'USD', + value: 14.98, // Total Revenue + coupon: 'SUMMER_FUN', + items: [item_jeggings] + }; + + // Log event + firebase.analytics().logEvent(firebase.analytics.EventName.BEGIN_CHECKOUT, params7); + // [END analytics_ecommerce_checkout] +} + +function ecommerceShippingInfo() { + // [START analytics_ecommerce_shipping_info] + // Prepare ecommerce params + const params8 = { + currency: 'USD', + value: 14.98, // Total Revenue + coupon: 'SUMMER_FUN', + shipping_tier: 'Ground', + items: [item_jeggings] + }; + + // Log event + firebase.analytics().logEvent(firebase.analytics.EventName.ADD_SHIPPING_INFO, params8); + // [END analytics_ecommerce_shipping_info] +} + +function ecommercePaymentInfo() { + // [START analytics_ecommerce_payment_info] + // Prepare ecommerce params + const params9 = { + currency: 'USD', + value: 14.98, // Total Revenue + coupon: 'SUMMER_FUN', + payment_type: 'Visa', + items: [item_jeggings] + }; + + // Log event + firebase.analytics().logEvent(firebase.analytics.EventName.ADD_PAYMENT_INFO, params9); + // [END analytics_ecommerce_payment_info] +} + +function ecommercePurchase() { + // [START analytics_ecommerce_purchase] + // Prepare ecommerce bundle + const params10 = { + transaction_id: 'T12345', + affiliation: 'Google Store', + currency: 'USD', + value: 14.98, // Total Revenue + tax: 2.85, + shipping: 5.34, + coupon: 'SUMMER_FUN', + items: [item_jeggings] + }; + + // Log event + firebase.analytics().logEvent(firebase.analytics.EventName.PURCHASE, params10); + // [END analytics_ecommerce_purchase] +} + +function ecommerceRefund() { + // [START analytics_ecommerce_refund] + // Prepare ecommerce params + const params11 = { + transaction_id: 'T12345', // Required + affiliation: 'Google Store', + currency: 'USD', + value: 9.99, + items: [] + }; + + // (Optional) For partial refunds, define the item_id and quantity of refunded items + const refundedProduct = { + item_id: 'SKU_123', // Required + quantity: 1 // Required + }; + + params11.items.push(refundedProduct); + + // Log event + firebase.analytics().logEvent(firebase.analytics.EventName.REFUND, params11); + // [END analytics_ecommerce_refund] +} + +function ecommercePromotions() { + // [START analytics_ecommerce_promotions] + // Prepare ecommerce params + const params12 = { + promotion_id: 'ABC123', + promotion_name: 'Summer Sale', + creative_name: 'summer2020_promo.jpg', + creative_slot: 'featured_app_1', + location_id: 'HERO_BANNER', + items: [item_jeggings] + }; + + // Log event when a promotion is displayed + firebase.analytics().logEvent(firebase.analytics.EventName.VIEW_PROMOTION, params12); + + // Log event when a promotion is selected + firebase.analytics().logEvent(firebase.analytics.EventName.SELECT_PROMOTION, params12); + // [END analytics_ecommerce_promotions] +} diff --git a/analytics/index.js b/analytics/index.js new file mode 100644 index 00000000..f8a0e856 --- /dev/null +++ b/analytics/index.js @@ -0,0 +1,40 @@ +import firebase from "firebase/app"; +import "firebase/analytics"; + +function initialize() { + // [START analytics_initialize] + const analytics = firebase.analytics(); + // [END analytics_initialize] +} + +function logEvent() { + // [START analytics_log_event] + firebase.analytics().logEvent('notification_received'); + // [END analytics_log_event] +} + +function logEventParams() { + const analytics = firebase.analytics(); + + // [START analytics_log_event_params] + analytics.logEvent('select_content', { + content_type: 'image', + content_id: 'P12453', + items: [{ name: 'Kittens' }] + }); + // [END analytics_log_event_params] +} + +function logEventCustomParams() { + const analytics = firebase.analytics(); + + // [START analytics_log_event_custom_params] + analytics.logEvent('goal_completion', { name: 'lever_puzzle'}); + // [END analytics_log_event_custom_params] +} + +function setUserProperties() { + // [START analytics_set_user_properties] + firebase.analytics().setUserProperties({favorite_food: 'apples'}); + // [END analytics_set_user_properties] +} diff --git a/analytics/package.json b/analytics/package.json new file mode 100644 index 00000000..41bd45d7 --- /dev/null +++ b/analytics/package.json @@ -0,0 +1,11 @@ +{ + "name": "analytics", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^8.2.3" + } +} diff --git a/lerna.json b/lerna.json index 8080d78a..ca43200d 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,7 @@ { "lerna": "2.8.0", "packages": [ + "analytics", "auth", "auth-next", "database", From a808a4b54d06ba3a2f69a5d8fe75e4df7671b50d Mon Sep 17 00:00:00 2001 From: Frank van Puffelen Date: Thu, 21 Jan 2021 02:55:47 -0800 Subject: [PATCH 071/235] Update email.js (#89) Co-authored-by: Sam --- auth-next/custom.js | 3 ++- auth-next/email.js | 6 ++++-- auth/custom.js | 3 ++- auth/email.js | 8 +++++--- snippets/auth-next/custom/auth_sign_in_custom.js | 3 ++- snippets/auth-next/email/auth_signin_password.js | 3 ++- snippets/auth-next/email/auth_signup_password.js | 3 ++- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/auth-next/custom.js b/auth-next/custom.js index 6ecdbe18..8f4ac547 100644 --- a/auth-next/custom.js +++ b/auth-next/custom.js @@ -17,8 +17,9 @@ function signInCustom() { const auth = getAuth(firebaseApp); signInWithCustomToken(auth, token) - .then((user) => { + .then((userCredential) => { // Signed in + const user = userCredential.user; // ... }) .catch((error) => { diff --git a/auth-next/email.js b/auth-next/email.js index 07a3cc3a..7285185a 100644 --- a/auth-next/email.js +++ b/auth-next/email.js @@ -18,8 +18,9 @@ function signInWithEmailPassword() { const auth = getAuth(firebaseApp); signInWithEmailAndPassword(auth, email, password) - .then((user) => { + .then((userCredential) => { // Signed in + const user = userCredential.user; // ... }) .catch((error) => { @@ -38,8 +39,9 @@ function signUpWithEmailPassword() { const auth = getAuth(firebaseApp); createUserWithEmailAndPassword(auth, email, password) - .then((user) => { + .then((userCredential) => { // Signed in + const user = userCredential.user; // ... }) .catch((error) => { diff --git a/auth/custom.js b/auth/custom.js index dc02990e..97713714 100644 --- a/auth/custom.js +++ b/auth/custom.js @@ -8,8 +8,9 @@ function signInCustom() { var token = "token123"; // [START auth_sign_in_custom] firebase.auth().signInWithCustomToken(token) - .then((user) => { + .then((userCredential) => { // Signed in + var user = userCredential.user; // ... }) .catch((error) => { diff --git a/auth/email.js b/auth/email.js index ba919819..cdb4bde3 100644 --- a/auth/email.js +++ b/auth/email.js @@ -9,8 +9,9 @@ function signInWithEmailPassword() { var password = "hunter2"; // [START auth_signin_password] firebase.auth().signInWithEmailAndPassword(email, password) - .then((user) => { - // Signed in + .then((userCredential) => { + // Signed in + var user = userCredential.user; // ... }) .catch((error) => { @@ -25,8 +26,9 @@ function signUpWithEmailPasswoerd() { var password = "hunter2"; // [START auth_signup_password] firebase.auth().createUserWithEmailAndPassword(email, password) - .then((user) => { + .then((userCredential) => { // Signed in + var user = userCredential.user; // ... }) .catch((error) => { diff --git a/snippets/auth-next/custom/auth_sign_in_custom.js b/snippets/auth-next/custom/auth_sign_in_custom.js index c22ed725..018c8b07 100644 --- a/snippets/auth-next/custom/auth_sign_in_custom.js +++ b/snippets/auth-next/custom/auth_sign_in_custom.js @@ -8,8 +8,9 @@ import { getAuth, signInWithCustomToken } from "firebase/auth"; const auth = getAuth(firebaseApp); signInWithCustomToken(auth, token) - .then((user) => { + .then((userCredential) => { // Signed in + const user = userCredential.user; // ... }) .catch((error) => { diff --git a/snippets/auth-next/email/auth_signin_password.js b/snippets/auth-next/email/auth_signin_password.js index d04a492e..43817787 100644 --- a/snippets/auth-next/email/auth_signin_password.js +++ b/snippets/auth-next/email/auth_signin_password.js @@ -8,8 +8,9 @@ import { getAuth, signInWithEmailAndPassword } from "firebase/auth"; const auth = getAuth(firebaseApp); signInWithEmailAndPassword(auth, email, password) - .then((user) => { + .then((userCredential) => { // Signed in + const user = userCredential.user; // ... }) .catch((error) => { diff --git a/snippets/auth-next/email/auth_signup_password.js b/snippets/auth-next/email/auth_signup_password.js index de1e38bb..3a20884c 100644 --- a/snippets/auth-next/email/auth_signup_password.js +++ b/snippets/auth-next/email/auth_signup_password.js @@ -8,8 +8,9 @@ import { getAuth, createUserWithEmailAndPassword } from "firebase/auth"; const auth = getAuth(firebaseApp); createUserWithEmailAndPassword(auth, email, password) - .then((user) => { + .then((userCredential) => { // Signed in + const user = userCredential.user; // ... }) .catch((error) => { From d5f652de67fbaaf5ce1ef3116b725800866931fc Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 21 Jan 2021 13:57:06 +0000 Subject: [PATCH 072/235] Add missing GitHub snippet --- auth-next/github.js | 8 ++++++++ auth/github.js | 6 ++++++ .../github/auth_github_provider_credential.js | 10 ++++++++++ 3 files changed, 24 insertions(+) create mode 100644 snippets/auth-next/github/auth_github_provider_credential.js diff --git a/auth-next/github.js b/auth-next/github.js index d59b0f42..0289a53b 100644 --- a/auth-next/github.js +++ b/auth-next/github.js @@ -27,6 +27,14 @@ function githubProvider() { // [END auth_github_provider_params] } +function githubProviderCredential(token) { + // [START auth_github_provider_credential] + const { GithubAuthProvider } = require("firebase/auth"); + + const credential = GithubAuthProvider.credential(token); + // [END auth_github_provider_credential] +} + function githubSignInPopup(provider) { // [START auth_github_signin_popup] const { getAuth, signInWithPopup, GithubAuthProvider } = require("firebase/auth"); diff --git a/auth/github.js b/auth/github.js index bf2db5bf..6ae1e531 100644 --- a/auth/github.js +++ b/auth/github.js @@ -20,6 +20,12 @@ function githubProvider() { // [END auth_github_provider_params] } +function githubProviderCredential(token) { + // [START auth_github_provider_credential] + var credential = firebase.auth.GithubAuthProvider.credential(token); + // [END auth_github_provider_credential] +} + function githubSignInPopup(provider) { // [START auth_github_signin_popup] firebase diff --git a/snippets/auth-next/github/auth_github_provider_credential.js b/snippets/auth-next/github/auth_github_provider_credential.js new file mode 100644 index 00000000..ee159180 --- /dev/null +++ b/snippets/auth-next/github/auth_github_provider_credential.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/github.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_github_provider_credential_modular] +import { GithubAuthProvider } from "firebase/auth"; + +const credential = GithubAuthProvider.credential(token); +// [END auth_github_provider_credential_modular] \ No newline at end of file From 03f16b910dc68e4f3c1dd1dff4f4bbcf5c56239a Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Thu, 21 Jan 2021 14:59:05 +0000 Subject: [PATCH 073/235] Add Perf and Storage snippets (#90) --- perf-next/index.js | 19 ++ perf/index.js | 16 ++ snippets/perf-next/index/perf_initialize.js | 21 ++ storage/create-reference.js | 95 +++++++++ storage/delete-files.js | 18 ++ storage/download-files.js | 80 ++++++++ storage/file-metadata.js | 75 +++++++ storage/index.js | 38 ++++ storage/list-files.js | 53 +++++ storage/upload-files.js | 212 ++++++++++++++++++++ 10 files changed, 627 insertions(+) create mode 100644 snippets/perf-next/index/perf_initialize.js create mode 100644 storage/create-reference.js create mode 100644 storage/delete-files.js create mode 100644 storage/download-files.js create mode 100644 storage/file-metadata.js create mode 100644 storage/list-files.js create mode 100644 storage/upload-files.js diff --git a/perf-next/index.js b/perf-next/index.js index 96545d31..58b70ae7 100644 --- a/perf-next/index.js +++ b/perf-next/index.js @@ -10,6 +10,25 @@ const firebaseApp = initializeApp({ }); const perf = getInstance(firebaseApp); +function intialize() { + // [START perf_initialize] + const { initializeApp } = require("firebase/app"); + const { getPerformance } = require("firebase/performance"); + + // TODO: Replace the following with your app's Firebase project configuration + // See: https://firebase.google.com/docs/web/setup#config-object + const firebaseConfig = { + // ... + }; + + // Initialize Firebase + const app = initializeApp(firebaseConfig); + + // Initialize Performance Monitoring and get a reference to the service + const perf = getPerformance(app); + // [END perf_initialize] +} + export function getInstance(firebaseApp) { // [START perf_get_instance] const { getPerformance } = require("firebase/performance"); diff --git a/perf/index.js b/perf/index.js index 9ef0dd9c..6d512e32 100644 --- a/perf/index.js +++ b/perf/index.js @@ -3,6 +3,22 @@ import "firebase/performance"; const perf = firebase.performance(); +function intialize() { + // [START perf_initialize] + // TODO: Replace the following with your app's Firebase project configuration + // See: https://firebase.google.com/docs/web/setup#config-object + var firebaseConfig = { + // ... + }; + + // Initialize Firebase + firebase.initializeApp(firebaseConfig); + + // Initialize Performance Monitoring and get a reference to the service + var perf = firebase.performance(); + // [END perf_initialize] +} + function addCustomTrace() { // [START perf_add_custom_trace] const trace = perf.trace("CUSTOM_TRACE_NAME"); diff --git a/snippets/perf-next/index/perf_initialize.js b/snippets/perf-next/index/perf_initialize.js new file mode 100644 index 00000000..c4802566 --- /dev/null +++ b/snippets/perf-next/index/perf_initialize.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./perf-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START perf_initialize_modular] +import { initializeApp } from "firebase/app"; +import { getPerformance } from "firebase/performance"; + +// TODO: Replace the following with your app's Firebase project configuration +// See: https://firebase.google.com/docs/web/setup#config-object +const firebaseConfig = { + // ... +}; + +// Initialize Firebase +const app = initializeApp(firebaseConfig); + +// Initialize Performance Monitoring and get a reference to the service +const perf = getPerformance(app); +// [END perf_initialize_modular] \ No newline at end of file diff --git a/storage/create-reference.js b/storage/create-reference.js new file mode 100644 index 00000000..09794832 --- /dev/null +++ b/storage/create-reference.js @@ -0,0 +1,95 @@ +import firebase from "firebase/app"; +import "firebase/storage"; + +function createRef() { + // [START storage_create_ref] + // Get a reference to the storage service, which is used to create references in your storage bucket + var storage = firebase.storage(); + + // Create a storage reference from our storage service + var storageRef = storage.ref(); + // [END storage_create_ref] +} + +function createRefChild() { + const storageRef = firebase.storage().ref(); + + // [START storage_create_ref_child] + // Create a child reference + var imagesRef = storageRef.child('images'); + // imagesRef now points to 'images' + + // Child references can also take paths delimited by '/' + var spaceRef = storageRef.child('images/space.jpg'); + // spaceRef now points to "images/space.jpg" + // imagesRef still points to "images" + // [END storage_create_ref_child] +} + +function navigateRef() { + const spaceRef = firebase.storage().ref().child('images/space.jpg'); + + // [START storage_navigate_ref] + // Parent allows us to move to the parent of a reference + var imagesRef = spaceRef.parent; + // imagesRef now points to 'images' + + // Root allows us to move all the way back to the top of our bucket + var rootRef = spaceRef.root; + // rootRef now points to the root + // [END storage_navigate_ref] +} + +function navigateRefChain() { + const spaceRef = firebase.storage().ref().child('images/space.jpg'); + + // [START storage_navigate_ref_chain] + // References can be chained together multiple times + var earthRef = spaceRef.parent.child('earth.jpg'); + // earthRef points to 'images/earth.jpg' + + // nullRef is null, since the parent of root is null + var nullRef = spaceRef.root.parent; + // [END storage_navigate_ref_chain] +} + +function refProperties() { + const spaceRef = firebase.storage().ref().child('images/space.jpg'); + + // [START storage_ref_properties] + // Reference's path is: 'images/space.jpg' + // This is analogous to a file path on disk + spaceRef.fullPath; + + // Reference's name is the last segment of the full path: 'space.jpg' + // This is analogous to the file name + spaceRef.name; + + // Reference's bucket is the name of the storage bucket where files are stored + spaceRef.bucket; + // [END storage_ref_properties] +} + +function refFullExample() { + // [START storage_ref_full_example] + // Points to the root reference + var storageRef = firebase.storage().ref(); + + // Points to 'images' + var imagesRef = storageRef.child('images'); + + // Points to 'images/space.jpg' + // Note that you can use variables to create child values + var fileName = 'space.jpg'; + var spaceRef = imagesRef.child(fileName); + + // File path is 'images/space.jpg' + var path = spaceRef.fullPath; + + // File name is 'space.jpg' + var name = spaceRef.name; + + // Points to 'images' + var imagesRef = spaceRef.parent; + // [END storage_ref_full_example] +} diff --git a/storage/delete-files.js b/storage/delete-files.js new file mode 100644 index 00000000..73b84904 --- /dev/null +++ b/storage/delete-files.js @@ -0,0 +1,18 @@ +import firebase from "firebase/app"; +import "firebase/storage"; + +function deleteFile() { + const storageRef = firebase.storage().ref(); + + // [START storage_delete_file] + // Create a reference to the file to delete + var desertRef = storageRef.child('images/desert.jpg'); + + // Delete the file + desertRef.delete().then(() => { + // File deleted successfully + }).catch((error) => { + // Uh-oh, an error occurred! + }); + // [END storage_delete_file] +} diff --git a/storage/download-files.js b/storage/download-files.js new file mode 100644 index 00000000..cb2af375 --- /dev/null +++ b/storage/download-files.js @@ -0,0 +1,80 @@ +import firebase from "firebase/app"; +import "firebase/storage"; + +function downloadCreateRef() { + // [START storage_download_create_ref] + // Create a reference with an initial file path and name + var storage = firebase.storage(); + var pathReference = storage.ref('images/stars.jpg'); + + // Create a reference from a Google Cloud Storage URI + var gsReference = storage.refFromURL('gs://bucket/images/stars.jpg'); + + // Create a reference from an HTTPS URL + // Note that in the URL, characters are URL escaped! + var httpsReference = storage.refFromURL('https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg'); + // [END storage_download_create_ref] +} + +function downloadViaUrl() { + const storageRef = firebase.storage().ref(); + + // [START storage_download_via_url] + storageRef.child('images/stars.jpg').getDownloadURL() + .then((url) => { + // `url` is the download URL for 'images/stars.jpg' + + // This can be downloaded directly: + var xhr = new XMLHttpRequest(); + xhr.responseType = 'blob'; + xhr.onload = (event) => { + var blob = xhr.response; + }; + xhr.open('GET', url); + xhr.send(); + + // Or inserted into an element + var img = document.getElementById('myimg'); + img.setAttribute('src', url); + }) + .catch((error) => { + // Handle any errors + }); + // [END storage_download_via_url] +} + +function downloadFullExample() { + const storageRef = firebase.storage().ref(); + + // [START storage_download_full_example] + // Create a reference to the file we want to download + var starsRef = storageRef.child('images/stars.jpg'); + + // Get the download URL + starsRef.getDownloadURL() + .then((url) => { + // Insert url into an tag to "download" + }) + .catch((error) => { + // A full list of error codes is available at + // https://firebase.google.com/docs/storage/web/handle-errors + switch (error.code) { + case 'storage/object-not-found': + // File doesn't exist + break; + case 'storage/unauthorized': + // User doesn't have permission to access the object + break; + case 'storage/canceled': + // User canceled the upload + break; + + // ... + + case 'storage/unknown': + // Unknown error occurred, inspect the server response + break; + } + }); + // [END storage_download_full_example] +} diff --git a/storage/file-metadata.js b/storage/file-metadata.js new file mode 100644 index 00000000..cef42364 --- /dev/null +++ b/storage/file-metadata.js @@ -0,0 +1,75 @@ +import firebase from "firebase/app"; +import "firebase/storage"; + +function getMetadata() { + const storageRef = firebase.storage().ref(); + + // [START storage_get_metadata] + // Create a reference to the file whose metadata we want to retrieve + var forestRef = storageRef.child('images/forest.jpg'); + + // Get metadata properties + forestRef.getMetadata() + .then((metadata) => { + // Metadata now contains the metadata for 'images/forest.jpg' + }) + .catch((error) => { + // Uh-oh, an error occurred! + }); + // [END storage_get_metadata] +} + +function updateMetadata() { + const storageRef = firebase.storage().ref(); + + // [START storage_update_metadata] + // Create a reference to the file whose metadata we want to change + var forestRef = storageRef.child('images/forest.jpg'); + + // Create file metadata to update + var newMetadata = { + cacheControl: 'public,max-age=300', + contentType: 'image/jpeg' + }; + + // Update metadata properties + forestRef.updateMetadata(newMetadata) + .then((metadata) => { + // Updated metadata for 'images/forest.jpg' is returned in the Promise + }).catch((error) => { + // Uh-oh, an error occurred! + }); + // [END storage_update_metadata] +} + +function deleteMetadata() { + const storageRef = firebase.storage().ref(); + const forestRef = storageRef.child('images/forest.jpg'); + + // [START storage_delete_metadata] + + // Create file metadata with property to delete + var deleteMetadata = { + contentType: null + }; + + // Delete the metadata property + forestRef.updateMetadata(deleteMetadata) + .then((metadata) => { + // metadata.contentType should be null + }).catch((error) => { + // Uh-oh, an error occurred! + }); + // [END storage_delete_metadata] +} + +function customMetadata() { + // [START storage_custom_metadata] + var metadata = { + customMetadata: { + 'location': 'Yosemite, CA, USA', + 'activity': 'Hiking' + } + }; + // [END storage_custom_metadata] +} diff --git a/storage/index.js b/storage/index.js index 02598d88..7a7db0df 100644 --- a/storage/index.js +++ b/storage/index.js @@ -1,6 +1,44 @@ import firebase from "firebase/app"; import "firebase/storage"; +function initialize() { + // [START storage_initialize] + // Set the configuration for your app + // TODO: Replace with your app's config object + var firebaseConfig = { + apiKey: '', + authDomain: '', + databaseURL: '', + storageBucket: '' + }; + firebase.initializeApp(firebaseConfig); + + // Get a reference to the storage service, which is used to create references in your storage bucket + var storage = firebase.storage(); + // [END storage_initialize] +} + +function multipleBuckets() { + // [START storage_multiple_buckets] + // Get a non-default Storage bucket + var storage = firebase.app().storage("gs://my-custom-bucket"); + // [END storage_multiple_buckets] +} + +function storageCustomApp() { + const customApp = firebase.initializeApp({ + // ... custom stuff + }); + + // [START storage_custom_app] + // Get the default bucket from a custom firebase.app.App + var storage = customApp.storage(); + + // Get a non-default bucket from a custom firebase.app.App + var storage = customApp.storage("gs://my-custom-bucket"); + // [END storage_custom_app] +} + /** * @param {File} file */ diff --git a/storage/list-files.js b/storage/list-files.js new file mode 100644 index 00000000..ef248da7 --- /dev/null +++ b/storage/list-files.js @@ -0,0 +1,53 @@ +import firebase from "firebase/app"; +import "firebase/storage"; + +function listAll() { + const storageRef = firebase.storage().ref(); + + // [START storage_list_all] + // Create a reference under which you want to list + var listRef = storageRef.child('files/uid'); + + // Find all the prefixes and items. + listRef.listAll() + .then((res) => { + res.prefixes.forEach((folderRef) => { + // All the prefixes under listRef. + // You may call listAll() recursively on them. + }); + res.items.forEach((itemRef) => { + // All the items under listRef. + }); + }).catch((error) => { + // Uh-oh, an error occurred! + }); + // [END storage_list_all] +} + +function listPaginate() { + const storageRef = firebase.storage().ref(); + + // [START storage_list_paginate] + async function pageTokenExample(){ + // Create a reference under which you want to list + var listRef = storageRef.child('files/uid'); + + // Fetch the first page of 100. + var firstPage = await listRef.list({ maxResults: 100}); + + // Use the result. + // processItems(firstPage.items) + // processPrefixes(firstPage.prefixes) + + // Fetch the second page if there are more elements. + if (firstPage.nextPageToken) { + var secondPage = await listRef.list({ + maxResults: 100, + pageToken: firstPage.nextPageToken, + }); + // processItems(secondPage.items) + // processPrefixes(secondPage.prefixes) + } + } + // [END storage_list_paginate] +} diff --git a/storage/upload-files.js b/storage/upload-files.js new file mode 100644 index 00000000..988fc3eb --- /dev/null +++ b/storage/upload-files.js @@ -0,0 +1,212 @@ +import firebase from "firebase/app"; +import "firebase/storage"; + +function uploadRef() { + // [START storage_upload_ref] + // Create a root reference + var storageRef = firebase.storage().ref(); + + // Create a reference to 'mountains.jpg' + var mountainsRef = storageRef.child('mountains.jpg'); + + // Create a reference to 'images/mountains.jpg' + var mountainImagesRef = storageRef.child('images/mountains.jpg'); + + // While the file names are the same, the references point to different files + mountainsRef.name === mountainImagesRef.name; // true + mountainsRef.fullPath === mountainImagesRef.fullPath; // false + // [END storage_upload_ref] +} + +/** + * @param {File} file + */ +function uploadBlob(file) { + const ref = firebase.storage().ref().child('some-child'); + + // [START storage_upload_blob] + // 'file' comes from the Blob or File API + ref.put(file).then((snapshot) => { + console.log('Uploaded a blob or file!'); + }); + // [END storage_upload_blob] +} + +function uploadBytes() { + const ref = firebase.storage().ref().child('some-child'); + + // [START storage_upload_bytes] + var bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21]); + ref.put(bytes).then((snapshot) => { + console.log('Uploaded an array!'); + }); + // [END storage_upload_bytes] +} + +function uploadString() { + const ref = firebase.storage().ref().child('some-child'); + + // [START storage_upload_string] + // Raw string is the default if no format is provided + var message = 'This is my message.'; + ref.putString(message).then((snapshot) => { + console.log('Uploaded a raw string!'); + }); + + // Base64 formatted string + var message = '5b6p5Y+344GX44G+44GX44Gf77yB44GK44KB44Gn44Go44GG77yB'; + ref.putString(message, 'base64').then((snapshot) => { + console.log('Uploaded a base64 string!'); + }); + + // Base64url formatted string + var message = '5b6p5Y-344GX44G-44GX44Gf77yB44GK44KB44Gn44Go44GG77yB'; + ref.putString(message, 'base64url').then((snapshot) => { + console.log('Uploaded a base64url string!'); + }); + + // Data URL string + var message = 'data:text/plain;base64,5b6p5Y+344GX44G+44GX44Gf77yB44GK44KB44Gn44Go44GG77yB'; + ref.putString(message, 'data_url').then((snapshot) => { + console.log('Uploaded a data_url string!'); + }); + // [END storage_upload_string] +} + +/** + * @param {File} file + */ +function uploadMetadata(file) { + const storageRef = firebase.storage().ref(); + + // [START storage_upload_metadata] + // Create file metadata including the content type + var metadata = { + contentType: 'image/jpeg', + }; + + // Upload the file and metadata + var uploadTask = storageRef.child('images/mountains.jpg').put(file, metadata); + // [END storage_upload_metadata] +} + +/** + * @param {File} file + */ +function manageUploads(file) { + const storageRef = firebase.storage().ref(); + + // [START storage_manage_uploads] + // Upload the file and metadata + var uploadTask = storageRef.child('images/mountains.jpg').put(file); + + // Pause the upload + uploadTask.pause(); + + // Resume the upload + uploadTask.resume(); + + // Cancel the upload + uploadTask.cancel(); + // [END storage_manage_uploads] +} + +/** + * @param {File} file + */ +function monitorUpload(file) { + const storageRef = firebase.storage().ref(); + + // [START storage_monitor_upload] + var uploadTask = storageRef.child('images/rivers.jpg').put(file); + + // Register three observers: + // 1. 'state_changed' observer, called any time the state changes + // 2. Error observer, called on failure + // 3. Completion observer, called on successful completion + uploadTask.on('state_changed', + (snapshot) => { + // Observe state change events such as progress, pause, and resume + // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded + var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; + console.log('Upload is ' + progress + '% done'); + switch (snapshot.state) { + case firebase.storage.TaskState.PAUSED: // or 'paused' + console.log('Upload is paused'); + break; + case firebase.storage.TaskState.RUNNING: // or 'running' + console.log('Upload is running'); + break; + } + }, + (error) => { + // Handle unsuccessful uploads + }, + () => { + // Handle successful uploads on complete + // For instance, get the download URL: https://firebasestorage.googleapis.com/... + uploadTask.snapshot.ref.getDownloadURL().then((downloadURL) => { + console.log('File available at', downloadURL); + }); + } + ); + // [END storage_monitor_upload] +} + +/** + * @param {File} file + */ +function uploadHandleError(file) { + const storageRef = firebase.storage().ref(); + + // [START storage_upload_handle_error] + // Create the file metadata + var metadata = { + contentType: 'image/jpeg' + }; + + // Upload file and metadata to the object 'images/mountains.jpg' + var uploadTask = storageRef.child('images/' + file.name).put(file, metadata); + + // Listen for state changes, errors, and completion of the upload. + uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed' + (snapshot) => { + // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded + var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; + console.log('Upload is ' + progress + '% done'); + switch (snapshot.state) { + case firebase.storage.TaskState.PAUSED: // or 'paused' + console.log('Upload is paused'); + break; + case firebase.storage.TaskState.RUNNING: // or 'running' + console.log('Upload is running'); + break; + } + }, + (error) => { + // A full list of error codes is available at + // https://firebase.google.com/docs/storage/web/handle-errors + switch (error.code) { + case 'storage/unauthorized': + // User doesn't have permission to access the object + break; + case 'storage/canceled': + // User canceled the upload + break; + + // ... + + case 'storage/unknown': + // Unknown error occurred, inspect error.serverResponse + break; + } + }, + () => { + // Upload completed successfully, now we can get the download URL + uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) { + console.log('File available at', downloadURL); + }); + } + ); + // [END storage_upload_handle_error] +} From 03c143d872a10b9d9ed4d55cf0f9f98316d4748e Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 22 Jan 2021 02:53:18 -0800 Subject: [PATCH 074/235] Auto-update dependencies. (#91) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 41bd45d7..e292956e 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.3" + "firebase": "^8.2.4" } } diff --git a/auth/package.json b/auth/package.json index c814359e..a6ea9b7c 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.3", + "firebase": "^8.2.4", "firebaseui": "^4.7.1" } } diff --git a/database/package.json b/database/package.json index 1063856e..ea1468d3 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.3" + "firebase": "^8.2.4" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index ab98eba2..b057f3d6 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.3" + "firebase": "^8.2.4" } } diff --git a/firestore/package.json b/firestore/package.json index eada0581..32b040f6 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.3", + "firebase": "^8.2.4", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 6cf0d5cf..c66ef81b 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.3" + "firebase": "^8.2.4" } } diff --git a/installations/package.json b/installations/package.json index 13361e6d..f5bb3d37 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.3" + "firebase": "^8.2.4" } } diff --git a/messaging/package.json b/messaging/package.json index 6ca0ae56..cc6f7c81 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.3" + "firebase": "^8.2.4" } } diff --git a/perf/package.json b/perf/package.json index 6689d178..f9176094 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.3" + "firebase": "^8.2.4" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 94072b11..1bfa9cc5 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.3" + "firebase": "^8.2.4" } } diff --git a/storage/package.json b/storage/package.json index 655f1d3c..7aad7b77 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.3" + "firebase": "^8.2.4" } } From e3396e052642bf9172171346f1292a1685446457 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 22 Jan 2021 11:11:18 +0000 Subject: [PATCH 075/235] Add messaging-next --- lerna.json | 1 + messaging-next/index.js | 85 +++++++++++++++++++ messaging-next/package.json | 11 +++ messaging-next/service-worker.js | 45 ++++++++++ .../index/messaging_delete_token.js | 16 ++++ .../index/messaging_get_messaging_object.js | 10 +++ .../index/messaging_get_token.js | 25 ++++++ .../index/messaging_receive_message.js | 18 ++++ .../index/messaging_request_permission.js | 16 ++++ .../service-worker/messaging_init_in_sw.js | 27 ++++++ .../messaging_on_background_message.js | 8 ++ 11 files changed, 262 insertions(+) create mode 100644 messaging-next/index.js create mode 100644 messaging-next/package.json create mode 100644 messaging-next/service-worker.js create mode 100644 snippets/messaging-next/index/messaging_delete_token.js create mode 100644 snippets/messaging-next/index/messaging_get_messaging_object.js create mode 100644 snippets/messaging-next/index/messaging_get_token.js create mode 100644 snippets/messaging-next/index/messaging_receive_message.js create mode 100644 snippets/messaging-next/index/messaging_request_permission.js create mode 100644 snippets/messaging-next/service-worker/messaging_init_in_sw.js create mode 100644 snippets/messaging-next/service-worker/messaging_on_background_message.js diff --git a/lerna.json b/lerna.json index ca43200d..4e51b74a 100644 --- a/lerna.json +++ b/lerna.json @@ -12,6 +12,7 @@ "functions-next", "installations", "messaging", + "messaging-next", "perf", "perf-next", "remoteconfig", diff --git a/messaging-next/index.js b/messaging-next/index.js new file mode 100644 index 00000000..dd800938 --- /dev/null +++ b/messaging-next/index.js @@ -0,0 +1,85 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function getMessagingObject() { + // [START messaging_get_messaging_object] + const { getMessaging } = require("firebase/messaging"); + + const messaging = getMessaging(firebaseApp); + // [END messaging_get_messaging_object] +} + +function receiveMessage() { + // [START messaging_receive_message] + // Handle incoming messages. Called when: + // - a message is received while the app has focus + // - the user clicks on an app notification created by a service worker + // `messaging.onBackgroundMessage` handler. + const { getMessaging, onMessage } = require("firebase/messaging"); + + const messaging = getMessaging(firebaseApp); + onMessage(messaging, (payload) => { + console.log('Message received. ', payload); + // ... + }); + // [END messaging_receive_message] +} + +function getToken() { + // [START messaging_get_token] + const { getMessaging, getToken } = require("firebase/messaging"); + + // Get registration token. Initially this makes a network call, once retrieved + // subsequent calls to getToken will return from cache. + const messaging = getMessaging(firebaseApp); + getToken(messaging, { vapidKey: '' }).then((currentToken) => { + if (currentToken) { + // Send the token to your server and update the UI if necessary + // ... + } else { + // Show permission request UI + console.log('No registration token available. Request permission to generate one.'); + // ... + } + }).catch((err) => { + console.log('An error occurred while retrieving token. ', err); + // ... + }); + // [END messaging_get_token] +} + +function requestPermission() { + // [START messaging_request_permission] + Notification.requestPermission().then((permission) => { + if (permission === 'granted') { + console.log('Notification permission granted.'); + // TODO(developer): Retrieve a registration token for use with FCM. + // ... + } else { + console.log('Unable to get permission to notify.'); + } + }); + // [END messaging_request_permission] +} + +function deleteToken() { + // [START messaging_delete_token] + const { getMessaging, deleteToken } = require("firebase/messaging"); + + const messaging = getMessaging(firebaseApp); + deleteToken(messaging).then(() => { + console.log('Token deleted.'); + // ... + }).catch((err) => { + console.log('Unable to delete token. ', err); + }); + // [END messaging_delete_token] +} diff --git a/messaging-next/package.json b/messaging-next/package.json new file mode 100644 index 00000000..c787b7ed --- /dev/null +++ b/messaging-next/package.json @@ -0,0 +1,11 @@ +{ + "name": "messaging-next", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "exp" + } +} diff --git a/messaging-next/service-worker.js b/messaging-next/service-worker.js new file mode 100644 index 00000000..633fb9e5 --- /dev/null +++ b/messaging-next/service-worker.js @@ -0,0 +1,45 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +// See: https://github.com/microsoft/TypeScript/issues/14877 +/** @type {ServiceWorkerGlobalScope} */ +let self; + +function initInSw() { + // [START messaging_init_in_sw] + const { initializeApp } = require("firebase/app"); + const { getMessaging } = require("firebase/messaging"); + + // Initialize the Firebase app in the service worker by passing in + // your app's Firebase config object. + // https://firebase.google.com/docs/web/setup#config-object + const firebaseApp = initializeApp({ + apiKey: 'api-key', + authDomain: 'project-id.firebaseapp.com', + databaseURL: 'https://project-id.firebaseio.com', + projectId: 'project-id', + storageBucket: 'project-id.appspot.com', + messagingSenderId: 'sender-id', + appId: 'app-id', + measurementId: 'G-measurement-id', + }) + + // Retrieve an instance of Firebase Messaging so that it can handle background + // messages. + const messaging = getMessaging(firebaseApp); + // [END messaging_init_in_sw] +} + +function onBackgroundMessage() { + // [START messaging_on_background_message] + // TODO(snippet): This snippet is not yet translated to the @exp SDK + // [END messaging_on_background_message] +} diff --git a/snippets/messaging-next/index/messaging_delete_token.js b/snippets/messaging-next/index/messaging_delete_token.js new file mode 100644 index 00000000..c6e1bf9e --- /dev/null +++ b/snippets/messaging-next/index/messaging_delete_token.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./messaging-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START messaging_delete_token_modular] +import { getMessaging, deleteToken } from "firebase/messaging"; + +const messaging = getMessaging(firebaseApp); +deleteToken(messaging).then(() => { + console.log('Token deleted.'); + // ... +}).catch((err) => { + console.log('Unable to delete token. ', err); +}); +// [END messaging_delete_token_modular] \ No newline at end of file diff --git a/snippets/messaging-next/index/messaging_get_messaging_object.js b/snippets/messaging-next/index/messaging_get_messaging_object.js new file mode 100644 index 00000000..5e75a7a5 --- /dev/null +++ b/snippets/messaging-next/index/messaging_get_messaging_object.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./messaging-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START messaging_get_messaging_object_modular] +import { getMessaging } from "firebase/messaging"; + +const messaging = getMessaging(firebaseApp); +// [END messaging_get_messaging_object_modular] \ No newline at end of file diff --git a/snippets/messaging-next/index/messaging_get_token.js b/snippets/messaging-next/index/messaging_get_token.js new file mode 100644 index 00000000..01773b6d --- /dev/null +++ b/snippets/messaging-next/index/messaging_get_token.js @@ -0,0 +1,25 @@ +// This snippet file was generated by processing the source file: +// ./messaging-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START messaging_get_token_modular] +import { getMessaging, getToken } from "firebase/messaging"; + +// Get registration token. Initially this makes a network call, once retrieved +// subsequent calls to getToken will return from cache. +const messaging = getMessaging(firebaseApp); +getToken(messaging, { vapidKey: '' }).then((currentToken) => { + if (currentToken) { + // Send the token to your server and update the UI if necessary + // ... + } else { + // Show permission request UI + console.log('No registration token available. Request permission to generate one.'); + // ... + } +}).catch((err) => { + console.log('An error occurred while retrieving token. ', err); + // ... +}); +// [END messaging_get_token_modular] \ No newline at end of file diff --git a/snippets/messaging-next/index/messaging_receive_message.js b/snippets/messaging-next/index/messaging_receive_message.js new file mode 100644 index 00000000..c95d1be4 --- /dev/null +++ b/snippets/messaging-next/index/messaging_receive_message.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./messaging-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START messaging_receive_message_modular] +// Handle incoming messages. Called when: +// - a message is received while the app has focus +// - the user clicks on an app notification created by a service worker +// `messaging.onBackgroundMessage` handler. +import { getMessaging, onMessage } from "firebase/messaging"; + +const messaging = getMessaging(firebaseApp); +onMessage(messaging, (payload) => { + console.log('Message received. ', payload); + // ... +}); +// [END messaging_receive_message_modular] \ No newline at end of file diff --git a/snippets/messaging-next/index/messaging_request_permission.js b/snippets/messaging-next/index/messaging_request_permission.js new file mode 100644 index 00000000..77e2d311 --- /dev/null +++ b/snippets/messaging-next/index/messaging_request_permission.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./messaging-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START messaging_request_permission_modular] +Notification.requestPermission().then((permission) => { + if (permission === 'granted') { + console.log('Notification permission granted.'); + // TODO(developer): Retrieve a registration token for use with FCM. + // ... + } else { + console.log('Unable to get permission to notify.'); + } +}); +// [END messaging_request_permission_modular] \ No newline at end of file diff --git a/snippets/messaging-next/service-worker/messaging_init_in_sw.js b/snippets/messaging-next/service-worker/messaging_init_in_sw.js new file mode 100644 index 00000000..c096acfa --- /dev/null +++ b/snippets/messaging-next/service-worker/messaging_init_in_sw.js @@ -0,0 +1,27 @@ +// This snippet file was generated by processing the source file: +// ./messaging-next/service-worker.js +// +// To make edits to the snippets in this file, please edit the source + +// [START messaging_init_in_sw_modular] +import { initializeApp } from "firebase/app"; +import { getMessaging } from "firebase/messaging"; + +// Initialize the Firebase app in the service worker by passing in +// your app's Firebase config object. +// https://firebase.google.com/docs/web/setup#config-object +const firebaseApp = initializeApp({ + apiKey: 'api-key', + authDomain: 'project-id.firebaseapp.com', + databaseURL: 'https://project-id.firebaseio.com', + projectId: 'project-id', + storageBucket: 'project-id.appspot.com', + messagingSenderId: 'sender-id', + appId: 'app-id', + measurementId: 'G-measurement-id', +}) + +// Retrieve an instance of Firebase Messaging so that it can handle background +// messages. +const messaging = getMessaging(firebaseApp); +// [END messaging_init_in_sw_modular] \ No newline at end of file diff --git a/snippets/messaging-next/service-worker/messaging_on_background_message.js b/snippets/messaging-next/service-worker/messaging_on_background_message.js new file mode 100644 index 00000000..2c55eab1 --- /dev/null +++ b/snippets/messaging-next/service-worker/messaging_on_background_message.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./messaging-next/service-worker.js +// +// To make edits to the snippets in this file, please edit the source + +// [START messaging_on_background_message_modular] +// TODO(snippet): This snippet is not yet translated to the @exp SDK +// [END messaging_on_background_message_modular] \ No newline at end of file From 3465c37d0a21ff0e1e050228eb350be55e8cda84 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 22 Jan 2021 11:24:49 +0000 Subject: [PATCH 076/235] Lint --- messaging-next/service-worker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-next/service-worker.js b/messaging-next/service-worker.js index 633fb9e5..25ee21db 100644 --- a/messaging-next/service-worker.js +++ b/messaging-next/service-worker.js @@ -30,7 +30,7 @@ function initInSw() { messagingSenderId: 'sender-id', appId: 'app-id', measurementId: 'G-measurement-id', - }) + }); // Retrieve an instance of Firebase Messaging so that it can handle background // messages. From 79fd51982f6575c98c05aa83085ee7f15ef1ac5b Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 22 Jan 2021 11:26:25 +0000 Subject: [PATCH 077/235] Add analytics-next --- analytics-next/ecommerce.js | 293 ++++++++++++++++++ analytics-next/index.js | 58 ++++ analytics-next/package.json | 11 + lerna.json | 1 + .../ecommerce/analytics_ecommerce_add_cart.js | 28 ++ .../ecommerce/analytics_ecommerce_checkout.js | 20 ++ .../ecommerce/analytics_ecommerce_items.js | 36 +++ .../analytics_ecommerce_payment_info.js | 21 ++ .../analytics_ecommerce_promotions.js | 25 ++ .../ecommerce/analytics_ecommerce_purchase.js | 24 ++ .../ecommerce/analytics_ecommerce_refund.js | 29 ++ .../analytics_ecommerce_remove_cart.js | 19 ++ .../analytics_ecommerce_select_item.js | 19 ++ .../analytics_ecommerce_shipping_info.js | 21 ++ .../analytics_ecommerce_view_cart.js | 30 ++ .../analytics_ecommerce_view_item_details.js | 19 ++ .../analytics_ecommerce_view_item_list.js | 19 ++ .../index/analytics_initialize.js | 10 + .../index/analytics_log_event.js | 11 + .../analytics_log_event_custom_params.js | 11 + .../index/analytics_log_event_params.js | 15 + .../index/analytics_set_user_properties.js | 11 + .../service-worker/messaging_init_in_sw.js | 2 +- 23 files changed, 732 insertions(+), 1 deletion(-) create mode 100644 analytics-next/ecommerce.js create mode 100644 analytics-next/index.js create mode 100644 analytics-next/package.json create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_items.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js create mode 100644 snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js create mode 100644 snippets/analytics-next/index/analytics_initialize.js create mode 100644 snippets/analytics-next/index/analytics_log_event.js create mode 100644 snippets/analytics-next/index/analytics_log_event_custom_params.js create mode 100644 snippets/analytics-next/index/analytics_log_event_params.js create mode 100644 snippets/analytics-next/index/analytics_set_user_properties.js diff --git a/analytics-next/ecommerce.js b/analytics-next/ecommerce.js new file mode 100644 index 00000000..b14f0eb2 --- /dev/null +++ b/analytics-next/ecommerce.js @@ -0,0 +1,293 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + + +// [START analytics_ecommerce_items] +// A pair of jeggings +const item_jeggings = { + item_id: 'SKU_123', + item_name: 'jeggings', + item_category: 'pants', + item_variant: 'black', + item_brand: 'Google', + price: 9.99 +}; + +// A pair of boots +const item_boots = { + item_id: 'SKU_456', + item_name: 'boots', + item_category: 'shoes', + item_variant: 'brown', + item_brand: 'Google', + price: 24.99 +}; + +// A pair of socks +const item_socks = { + item_id: 'SKU_789', + item_name: 'ankle_socks', + item_category: 'socks', + item_variant: 'red', + item_brand: 'Google', + price: 5.99 +}; +// [END analytics_ecommerce_items] + +function ecommerceViewItemList() { + // [START analytics_ecommerce_view_item_list] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Prepare ecommerce params + const params1 = { + item_list_id: 'L001', + item_list_name: 'Related products', + items: [item_jeggings, item_boots, item_socks] + }; + + // Log event + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'view_item_list', params1); + // [END analytics_ecommerce_view_item_list] +} + +function ecommerceSelectItem() { + // [START analytics_ecommerce_select_item] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Prepare ecommerce event params + const params2 = { + item_list_id: 'L001', + item_list_name: 'Related products', + items: [item_jeggings] + }; + + // Log event + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'select_item', params2); + // [END analytics_ecommerce_select_item] +} + +function ecommerceViewItemDetails() { + // [START analytics_ecommerce_view_item_details] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Prepare ecommerce event params + const params3 = { + currency: 'USD', + value: 9.99, + items: [item_jeggings] + }; + + // Log event + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'view_item', params3); + // [END analytics_ecommerce_view_item_details] +} + +function ecommerceAddCart() { + // [START analytics_ecommerce_add_cart] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Specify order quantity + const item_jeggings_quantity = { + ...item_jeggings, + quantity: 2 + }; + + // Prepare ecommerce bundle + const params4 = { + currency: 'USD', + value: 19.98, + items: [item_jeggings_quantity] + }; + + // Log event when a product is added to a wishlist + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'add_to_wishlist', params4); + + // Log event when a product is added to the cart + logEvent(analytics, 'add_to_cart', params4); + // [END analytics_ecommerce_add_cart] +} + +function ecommerceViewCart() { + // [START analytics_ecommerce_view_cart] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Specify order quantity + const item_jeggings_quantity = { + ...item_jeggings, + quantity: 2 + }; + + const item_boots_quantity = { + ...item_boots, + quantity: 1 + }; + + // Prepare ecommerce params + const params5 = { + currency: 'USD', + value: 44.97, + items: [item_jeggings_quantity, item_boots_quantity] + }; + + // Log event when the cart is viewed + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'view_cart', params5); + // [END analytics_ecommerce_view_cart] +} + +function ecommerceRemoveCart() { + // [START analytics_ecommerce_remove_cart] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Prepare ecommerce params + const params6 = { + currency: 'USD', + value: 24.99, + items: [item_jeggings] + }; + + // Log event + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'remove_from_cart', params6); + // [END analytics_ecommerce_remove_cart] +} + +function ecommerceCheckout() { + // [START analytics_ecommerce_checkout] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Prepare ecommerce params + const params7 = { + currency: 'USD', + value: 14.98, // Total Revenue + coupon: 'SUMMER_FUN', + items: [item_jeggings] + }; + + // Log event + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'begin_checkout', params7); + // [END analytics_ecommerce_checkout] +} + +function ecommerceShippingInfo() { + // [START analytics_ecommerce_shipping_info] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Prepare ecommerce params + const params8 = { + currency: 'USD', + value: 14.98, // Total Revenue + coupon: 'SUMMER_FUN', + shipping_tier: 'Ground', + items: [item_jeggings] + }; + + // Log event + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'add_shipping_info', params8); + // [END analytics_ecommerce_shipping_info] +} + +function ecommercePaymentInfo() { + // [START analytics_ecommerce_payment_info] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Prepare ecommerce params + const params9 = { + currency: 'USD', + value: 14.98, // Total Revenue + coupon: 'SUMMER_FUN', + payment_type: 'Visa', + items: [item_jeggings] + }; + + // Log event + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'add_payment_info', params9); + // [END analytics_ecommerce_payment_info] +} + +function ecommercePurchase() { + // [START analytics_ecommerce_purchase] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Prepare ecommerce bundle + const params10 = { + transaction_id: 'T12345', + affiliation: 'Google Store', + currency: 'USD', + value: 14.98, // Total Revenue + tax: 2.85, + shipping: 5.34, + coupon: 'SUMMER_FUN', + items: [item_jeggings] + }; + + // Log event + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'purchase', params10); + // [END analytics_ecommerce_purchase] +} + +function ecommerceRefund() { + // [START analytics_ecommerce_refund] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Prepare ecommerce params + const params11 = { + transaction_id: 'T12345', // Required + affiliation: 'Google Store', + currency: 'USD', + value: 9.99, + items: [] + }; + + // (Optional) For partial refunds, define the item_id and quantity of refunded items + const refundedProduct = { + item_id: 'SKU_123', // Required + quantity: 1 // Required + }; + + params11.items.push(refundedProduct); + + // Log event + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'refund', params11); + // [END analytics_ecommerce_refund] +} + +function ecommercePromotions() { + // [START analytics_ecommerce_promotions] + const { getAnalytics, logEvent } = require("@firebase/analytics"); + + // Prepare ecommerce params + const params12 = { + promotion_id: 'ABC123', + promotion_name: 'Summer Sale', + creative_name: 'summer2020_promo.jpg', + creative_slot: 'featured_app_1', + location_id: 'HERO_BANNER', + items: [item_jeggings] + }; + + // Log event when a promotion is displayed + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'view_promotion', params12); + + // Log event when a promotion is selected + logEvent(analytics, 'select_promotion', params12); + // [END analytics_ecommerce_promotions] +} diff --git a/analytics-next/index.js b/analytics-next/index.js new file mode 100644 index 00000000..047f1289 --- /dev/null +++ b/analytics-next/index.js @@ -0,0 +1,58 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function initialize() { + // [START analytics_initialize] + const { getAnalytics } = require("firebase/analytics"); + + const analytics = getAnalytics(firebaseApp); + // [END analytics_initialize] +} + +function logEvent() { + // [START analytics_log_event] + const { getAnalytics, logEvent } = require("firebase/analytics"); + + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'notification_received'); + // [END analytics_log_event] +} + +function logEventParams() { + // [START analytics_log_event_params] + const { getAnalytics, logEvent } = require("firebase/analytics"); + + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'select_content', { + content_type: 'image', + content_id: 'P12453', + items: [{ name: 'Kittens' }] + }); + // [END analytics_log_event_params] +} + +function logEventCustomParams() { + // [START analytics_log_event_custom_params] + const { getAnalytics, logEvent } = require("firebase/analytics"); + + const analytics = getAnalytics(firebaseApp); + logEvent(analytics, 'goal_completion', { name: 'lever_puzzle'}); + // [END analytics_log_event_custom_params] +} + +function setUserProperties() { + // [START analytics_set_user_properties] + const { getAnalytics, setUserProperties } = require("firebase/analytics"); + + const analytics = getAnalytics(firebaseApp); + setUserProperties(analytics, { favorite_food: 'apples' }); + // [END analytics_set_user_properties] +} diff --git a/analytics-next/package.json b/analytics-next/package.json new file mode 100644 index 00000000..7b054b75 --- /dev/null +++ b/analytics-next/package.json @@ -0,0 +1,11 @@ +{ + "name": "analytics-next", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "exp" + } +} diff --git a/lerna.json b/lerna.json index 4e51b74a..509b1db7 100644 --- a/lerna.json +++ b/lerna.json @@ -2,6 +2,7 @@ "lerna": "2.8.0", "packages": [ "analytics", + "analytics-next", "auth", "auth-next", "database", diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js new file mode 100644 index 00000000..c93b833e --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js @@ -0,0 +1,28 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_add_cart_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Specify order quantity +const item_jeggings_quantity = { + ...item_jeggings, + quantity: 2 +}; + +// Prepare ecommerce bundle +const params4 = { + currency: 'USD', + value: 19.98, + items: [item_jeggings_quantity] +}; + +// Log event when a product is added to a wishlist +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'add_to_wishlist', params4); + +// Log event when a product is added to the cart +logEvent(analytics, 'add_to_cart', params4); +// [END analytics_ecommerce_add_cart_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js new file mode 100644 index 00000000..7fc10a6c --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_checkout_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Prepare ecommerce params +const params7 = { + currency: 'USD', + value: 14.98, // Total Revenue + coupon: 'SUMMER_FUN', + items: [item_jeggings] +}; + +// Log event +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'begin_checkout', params7); +// [END analytics_ecommerce_checkout_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_items.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_items.js new file mode 100644 index 00000000..e3ad7cbe --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_items.js @@ -0,0 +1,36 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_items_modular] +// A pair of jeggings +const item_jeggings = { + item_id: 'SKU_123', + item_name: 'jeggings', + item_category: 'pants', + item_variant: 'black', + item_brand: 'Google', + price: 9.99 +}; + +// A pair of boots +const item_boots = { + item_id: 'SKU_456', + item_name: 'boots', + item_category: 'shoes', + item_variant: 'brown', + item_brand: 'Google', + price: 24.99 +}; + +// A pair of socks +const item_socks = { + item_id: 'SKU_789', + item_name: 'ankle_socks', + item_category: 'socks', + item_variant: 'red', + item_brand: 'Google', + price: 5.99 +}; +// [END analytics_ecommerce_items_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js new file mode 100644 index 00000000..d4ade3f1 --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_payment_info_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Prepare ecommerce params +const params9 = { + currency: 'USD', + value: 14.98, // Total Revenue + coupon: 'SUMMER_FUN', + payment_type: 'Visa', + items: [item_jeggings] +}; + +// Log event +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'add_payment_info', params9); +// [END analytics_ecommerce_payment_info_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js new file mode 100644 index 00000000..1e0e0e37 --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js @@ -0,0 +1,25 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_promotions_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Prepare ecommerce params +const params12 = { + promotion_id: 'ABC123', + promotion_name: 'Summer Sale', + creative_name: 'summer2020_promo.jpg', + creative_slot: 'featured_app_1', + location_id: 'HERO_BANNER', + items: [item_jeggings] +}; + +// Log event when a promotion is displayed +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'view_promotion', params12); + +// Log event when a promotion is selected +logEvent(analytics, 'select_promotion', params12); +// [END analytics_ecommerce_promotions_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js new file mode 100644 index 00000000..28817cd3 --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js @@ -0,0 +1,24 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_purchase_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Prepare ecommerce bundle +const params10 = { + transaction_id: 'T12345', + affiliation: 'Google Store', + currency: 'USD', + value: 14.98, // Total Revenue + tax: 2.85, + shipping: 5.34, + coupon: 'SUMMER_FUN', + items: [item_jeggings] +}; + +// Log event +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'purchase', params10); +// [END analytics_ecommerce_purchase_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js new file mode 100644 index 00000000..48984886 --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js @@ -0,0 +1,29 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_refund_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Prepare ecommerce params +const params11 = { + transaction_id: 'T12345', // Required + affiliation: 'Google Store', + currency: 'USD', + value: 9.99, + items: [] +}; + +// (Optional) For partial refunds, define the item_id and quantity of refunded items +const refundedProduct = { + item_id: 'SKU_123', // Required + quantity: 1 // Required +}; + +params11.items.push(refundedProduct); + +// Log event +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'refund', params11); +// [END analytics_ecommerce_refund_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js new file mode 100644 index 00000000..861c73ea --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_remove_cart_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Prepare ecommerce params +const params6 = { + currency: 'USD', + value: 24.99, + items: [item_jeggings] +}; + +// Log event +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'remove_from_cart', params6); +// [END analytics_ecommerce_remove_cart_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js new file mode 100644 index 00000000..537220f7 --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_select_item_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Prepare ecommerce event params +const params2 = { + item_list_id: 'L001', + item_list_name: 'Related products', + items: [item_jeggings] +}; + +// Log event +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'select_item', params2); +// [END analytics_ecommerce_select_item_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js new file mode 100644 index 00000000..d4425db8 --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_shipping_info_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Prepare ecommerce params +const params8 = { + currency: 'USD', + value: 14.98, // Total Revenue + coupon: 'SUMMER_FUN', + shipping_tier: 'Ground', + items: [item_jeggings] +}; + +// Log event +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'add_shipping_info', params8); +// [END analytics_ecommerce_shipping_info_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js new file mode 100644 index 00000000..4bb85052 --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js @@ -0,0 +1,30 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_view_cart_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Specify order quantity +const item_jeggings_quantity = { + ...item_jeggings, + quantity: 2 +}; + +const item_boots_quantity = { + ...item_boots, + quantity: 1 +}; + +// Prepare ecommerce params +const params5 = { + currency: 'USD', + value: 44.97, + items: [item_jeggings_quantity, item_boots_quantity] +}; + +// Log event when the cart is viewed +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'view_cart', params5); +// [END analytics_ecommerce_view_cart_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js new file mode 100644 index 00000000..1fd40596 --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_view_item_details_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Prepare ecommerce event params +const params3 = { + currency: 'USD', + value: 9.99, + items: [item_jeggings] +}; + +// Log event +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'view_item', params3); +// [END analytics_ecommerce_view_item_details_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js new file mode 100644 index 00000000..acc8bf08 --- /dev/null +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/ecommerce.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_ecommerce_view_item_list_modular] +import { getAnalytics, logEvent } from "@firebase/analytics"; + +// Prepare ecommerce params +const params1 = { + item_list_id: 'L001', + item_list_name: 'Related products', + items: [item_jeggings, item_boots, item_socks] +}; + +// Log event +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'view_item_list', params1); +// [END analytics_ecommerce_view_item_list_modular] \ No newline at end of file diff --git a/snippets/analytics-next/index/analytics_initialize.js b/snippets/analytics-next/index/analytics_initialize.js new file mode 100644 index 00000000..8d491090 --- /dev/null +++ b/snippets/analytics-next/index/analytics_initialize.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_initialize_modular] +import { getAnalytics } from "firebase/analytics"; + +const analytics = getAnalytics(firebaseApp); +// [END analytics_initialize_modular] \ No newline at end of file diff --git a/snippets/analytics-next/index/analytics_log_event.js b/snippets/analytics-next/index/analytics_log_event.js new file mode 100644 index 00000000..d4122c71 --- /dev/null +++ b/snippets/analytics-next/index/analytics_log_event.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_log_event_modular] +import { getAnalytics, logEvent } from "firebase/analytics"; + +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'notification_received'); +// [END analytics_log_event_modular] \ No newline at end of file diff --git a/snippets/analytics-next/index/analytics_log_event_custom_params.js b/snippets/analytics-next/index/analytics_log_event_custom_params.js new file mode 100644 index 00000000..65de3fb4 --- /dev/null +++ b/snippets/analytics-next/index/analytics_log_event_custom_params.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_log_event_custom_params_modular] +import { getAnalytics, logEvent } from "firebase/analytics"; + +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'goal_completion', { name: 'lever_puzzle'}); +// [END analytics_log_event_custom_params_modular] \ No newline at end of file diff --git a/snippets/analytics-next/index/analytics_log_event_params.js b/snippets/analytics-next/index/analytics_log_event_params.js new file mode 100644 index 00000000..12956c31 --- /dev/null +++ b/snippets/analytics-next/index/analytics_log_event_params.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_log_event_params_modular] +import { getAnalytics, logEvent } from "firebase/analytics"; + +const analytics = getAnalytics(firebaseApp); +logEvent(analytics, 'select_content', { + content_type: 'image', + content_id: 'P12453', + items: [{ name: 'Kittens' }] +}); +// [END analytics_log_event_params_modular] \ No newline at end of file diff --git a/snippets/analytics-next/index/analytics_set_user_properties.js b/snippets/analytics-next/index/analytics_set_user_properties.js new file mode 100644 index 00000000..ca660ab8 --- /dev/null +++ b/snippets/analytics-next/index/analytics_set_user_properties.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START analytics_set_user_properties_modular] +import { getAnalytics, setUserProperties } from "firebase/analytics"; + +const analytics = getAnalytics(firebaseApp); +setUserProperties(analytics, { favorite_food: 'apples' }); +// [END analytics_set_user_properties_modular] \ No newline at end of file diff --git a/snippets/messaging-next/service-worker/messaging_init_in_sw.js b/snippets/messaging-next/service-worker/messaging_init_in_sw.js index c096acfa..703e687d 100644 --- a/snippets/messaging-next/service-worker/messaging_init_in_sw.js +++ b/snippets/messaging-next/service-worker/messaging_init_in_sw.js @@ -19,7 +19,7 @@ const firebaseApp = initializeApp({ messagingSenderId: 'sender-id', appId: 'app-id', measurementId: 'G-measurement-id', -}) +}); // Retrieve an instance of Firebase Messaging so that it can handle background // messages. From b27016fa3e86cfffd7fef7b3ee6fb34f5dbf9759 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 22 Jan 2021 06:16:46 -0800 Subject: [PATCH 078/235] Auto-update dependencies. (#93) * Auto-update dependencies. * Auto-update dependencies. --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index a02a895c..3941640e 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 20179153..d239e630 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.2.3/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.2.3/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.4/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.4/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 282e7117a0e719b4e8a68fa010b5b6887ec233d8 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 25 Jan 2021 11:27:26 +0000 Subject: [PATCH 079/235] Add storage-next snippets --- lerna.json | 3 +- storage-next/create-reference.js | 120 +++++++++++++++ storage-next/delete-files.js | 28 ++++ storage-next/download-files.js | 92 ++++++++++++ storage-next/file-metadata.js | 86 +++++++++++ storage-next/index.js | 77 ++++++++++ storage-next/list-files.js | 64 ++++++++ storage-next/package.json | 11 ++ storage-next/upload-files.js | 245 +++++++++++++++++++++++++++++++ 9 files changed, 725 insertions(+), 1 deletion(-) create mode 100644 storage-next/create-reference.js create mode 100644 storage-next/delete-files.js create mode 100644 storage-next/download-files.js create mode 100644 storage-next/file-metadata.js create mode 100644 storage-next/index.js create mode 100644 storage-next/list-files.js create mode 100644 storage-next/package.json create mode 100644 storage-next/upload-files.js diff --git a/lerna.json b/lerna.json index 509b1db7..68842173 100644 --- a/lerna.json +++ b/lerna.json @@ -18,7 +18,8 @@ "perf-next", "remoteconfig", "remoteconfig-next", - "storage" + "storage", + "storage-next" ], "version": "1.0.0" } diff --git a/storage-next/create-reference.js b/storage-next/create-reference.js new file mode 100644 index 00000000..eae1ff4f --- /dev/null +++ b/storage-next/create-reference.js @@ -0,0 +1,120 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function createRef() { + // [START storage_create_ref] + const { getStorage, ref } = require("firebase/storage"); + + // Get a reference to the storage service, which is used to create references in your storage bucket + const storage = getStorage(firebaseApp); + + // Create a storage reference from our storage service + const storageRef = ref(storage); + // [END storage_create_ref] +} + +function createRefChild() { + // [START storage_create_ref_child] + const { getStorage, ref } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + + // Create a child reference + const imagesRef = ref(storage, 'images'); + // imagesRef now points to 'images' + + // Child references can also take paths delimited by '/' + const spaceRef = ref(storage, 'images/space.jpg'); + // spaceRef now points to "images/space.jpg" + // imagesRef still points to "images" + // [END storage_create_ref_child] +} + +function navigateRef() { + // [START storage_navigate_ref] + const { getStorage, ref } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + const spaceRef = ref(storage, 'images/space.jpg'); + + // Parent allows us to move to the parent of a reference + const imagesRef = spaceRef.parent; + // imagesRef now points to 'images' + + // Root allows us to move all the way back to the top of our bucket + const rootRef = spaceRef.root; + // rootRef now points to the root + // [END storage_navigate_ref] +} + +function navigateRefChain() { + // [START storage_navigate_ref_chain] + const { getStorage, ref } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + const spaceRef = ref(storage, 'images/space.jpg'); + + // References can be chained together multiple times + const earthRef = ref(spaceRef.parent, 'earth.jpg'); + // earthRef points to 'images/earth.jpg' + + // nullRef is null, since the parent of root is null + const nullRef = spaceRef.root.parent; + // [END storage_navigate_ref_chain] +} + +function refProperties() { + // [START storage_ref_properties] + const { getStorage, ref } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + const spaceRef = ref(storage, 'images/space.jpg'); + + // Reference's path is: 'images/space.jpg' + // This is analogous to a file path on disk + spaceRef.fullPath; + + // Reference's name is the last segment of the full path: 'space.jpg' + // This is analogous to the file name + spaceRef.name; + + // Reference's bucket is the name of the storage bucket where files are stored + spaceRef.bucket; + // [END storage_ref_properties] +} + +function refFullExample() { + // [START storage_ref_full_example] + const { getStorage, ref } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + + // Points to the root reference + const storageRef = ref(storage); + + // Points to 'images' + const imagesRef = ref(storageRef, 'images'); + + // Points to 'images/space.jpg' + // Note that you can use variables to create child values + const fileName = 'space.jpg'; + const spaceRef = ref(imagesRef, fileName); + + // File path is 'images/space.jpg' + const path = spaceRef.fullPath; + + // File name is 'space.jpg' + const name = spaceRef.name; + + // Points to 'images' + const imagesRefAgain = spaceRef.parent; + // [END storage_ref_full_example] +} diff --git a/storage-next/delete-files.js b/storage-next/delete-files.js new file mode 100644 index 00000000..d5e640b5 --- /dev/null +++ b/storage-next/delete-files.js @@ -0,0 +1,28 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function deleteFile() { + // [START storage_delete_file] + const { getStorage, ref, deleteObject } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + + // Create a reference to the file to delete + const desertRef = ref(storage, 'images/desert.jpg'); + + // Delete the file + deleteObject(desertRef).then(() => { + // File deleted successfully + }).catch((error) => { + // Uh-oh, an error occurred! + }); + // [END storage_delete_file] +} diff --git a/storage-next/download-files.js b/storage-next/download-files.js new file mode 100644 index 00000000..5cfec855 --- /dev/null +++ b/storage-next/download-files.js @@ -0,0 +1,92 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function downloadCreateRef() { + // [START storage_download_create_ref] + const { getStorage, ref } = require("firebase/storage"); + + // Create a reference with an initial file path and name + const storage = getStorage(firebaseApp); + const pathReference = ref(storage, 'images/stars.jpg'); + + // Create a reference from a Google Cloud Storage URI + const gsReference = ref(storage, 'gs://bucket/images/stars.jpg'); + + // Create a reference from an HTTPS URL + // Note that in the URL, characters are URL escaped! + const httpsReference = ref(storage, 'https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg'); + // [END storage_download_create_ref] +} + +function downloadViaUrl() { + // [START storage_download_via_url] + const { getStorage, ref, getDownloadURL } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + getDownloadURL(ref(storage, 'images/stars.jpg')) + .then((url) => { + // `url` is the download URL for 'images/stars.jpg' + + // This can be downloaded directly: + const xhr = new XMLHttpRequest(); + xhr.responseType = 'blob'; + xhr.onload = (event) => { + const blob = xhr.response; + }; + xhr.open('GET', url); + xhr.send(); + + // Or inserted into an element + const img = document.getElementById('myimg'); + img.setAttribute('src', url); + }) + .catch((error) => { + // Handle any errors + }); + // [END storage_download_via_url] +} + +function downloadFullExample() { + // [START storage_download_full_example] + const { getStorage, ref, getDownloadURL } = require("firebase/storage"); + + // Create a reference to the file we want to download + const storage = getStorage(firebaseApp); + const starsRef = ref(storage, 'images/stars.jpg'); + + // Get the download URL + getDownloadURL(starsRef) + .then((url) => { + // Insert url into an tag to "download" + }) + .catch((error) => { + // A full list of error codes is available at + // https://firebase.google.com/docs/storage/web/handle-errors + switch (error.code) { + case 'storage/object-not-found': + // File doesn't exist + break; + case 'storage/unauthorized': + // User doesn't have permission to access the object + break; + case 'storage/canceled': + // User canceled the upload + break; + + // ... + + case 'storage/unknown': + // Unknown error occurred, inspect the server response + break; + } + }); + // [END storage_download_full_example] +} diff --git a/storage-next/file-metadata.js b/storage-next/file-metadata.js new file mode 100644 index 00000000..13624cc6 --- /dev/null +++ b/storage-next/file-metadata.js @@ -0,0 +1,86 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function getMetadata() { + // [START storage_get_metadata] + const { getStorage, ref, getMetadata } = require("firebase/storage"); + + // Create a reference to the file whose metadata we want to retrieve + const storage = getStorage(firebaseApp); + const forestRef = ref(storage, 'images/forest.jpg'); + + // Get metadata properties + getMetadata(forestRef) + .then((metadata) => { + // Metadata now contains the metadata for 'images/forest.jpg' + }) + .catch((error) => { + // Uh-oh, an error occurred! + }); + // [END storage_get_metadata] +} + +function updateMetadata() { + // [START storage_update_metadata] + const { getStorage, ref, updateMetadata } = require("firebase/storage"); + + // Create a reference to the file whose metadata we want to change + const storage = getStorage(firebaseApp); + const forestRef = ref(storage, 'images/forest.jpg'); + + // Create file metadata to update + const newMetadata = { + cacheControl: 'public,max-age=300', + contentType: 'image/jpeg' + }; + + // Update metadata properties + updateMetadata(forestRef, newMetadata) + .then((metadata) => { + // Updated metadata for 'images/forest.jpg' is returned in the Promise + }).catch((error) => { + // Uh-oh, an error occurred! + }); + // [END storage_update_metadata] +} + +function deleteMetadata() { + // [START storage_delete_metadata] + const { getStorage, ref, updateMetadata } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + const forestRef = ref(storage, 'images/forest.jpg'); + + // Create file metadata with property to delete + const deleteMetadata = { + contentType: null + }; + + // Delete the metadata property + updateMetadata(forestRef, deleteMetadata) + .then((metadata) => { + // metadata.contentType should be null + }).catch((error) => { + // Uh-oh, an error occurred! + }); + // [END storage_delete_metadata] +} + +function customMetadata() { + // [START storage_custom_metadata] + const metadata = { + customMetadata: { + 'location': 'Yosemite, CA, USA', + 'activity': 'Hiking' + } + }; + // [END storage_custom_metadata] +} diff --git a/storage-next/index.js b/storage-next/index.js new file mode 100644 index 00000000..c5d713cc --- /dev/null +++ b/storage-next/index.js @@ -0,0 +1,77 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function initialize() { + // [START storage_initialize] + const { initializeApp } = require("firebase/app"); + const { getStorage, uploadBytesResumable } = require("firebase/storage"); + + // Set the configuration for your app + // TODO: Replace with your app's config object + const firebaseConfig = { + apiKey: '', + authDomain: '', + databaseURL: '', + storageBucket: '' + }; + const firebaseApp = initializeApp(firebaseConfig); + + // Get a reference to the storage service, which is used to create references in your storage bucket + const storage = getStorage(firebaseApp); + // [END storage_initialize] +} + +function multipleBuckets() { + // [START storage_multiple_buckets] + // TODO: Snippet not yet written... + // [END storage_multiple_buckets] +} + +function storageCustomApp() { + // [START storage_custom_app] + // TODO: Snippet not yet written... + // [END storage_custom_app] +} + +/** + * @param {File} file + */ +function storageOnComplete(file) { + // The file param would be a File object from a file selection event in the browser. + // See: + // - https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications + // - https://developer.mozilla.org/en-US/docs/Web/API/File + + /** @type {any} */ + const metadata = { + 'contentType': file.type + }; + + // [START storage_on_complete] + const { getStorage, ref, uploadBytesResumable, getDownloadURL } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + const imageRef = ref(storage, 'images/' + file.name); + uploadBytesResumable(imageRef, file, metadata) + .then((snapshot) => { + console.log('Uploaded', snapshot.totalBytes, 'bytes.'); + console.log('File metadata:', snapshot.metadata); + // Let's get a download URL for the file. + getDownloadURL(snapshot.ref).then((url) => { + console.log('File available at', url); + // ... + }); + }).catch((error) => { + console.error('Upload failed', error); + // ... + }); + // [END storage_on_complete] +} diff --git a/storage-next/list-files.js b/storage-next/list-files.js new file mode 100644 index 00000000..4d3f05cc --- /dev/null +++ b/storage-next/list-files.js @@ -0,0 +1,64 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function listAll() { + // [START storage_list_all] + const { getStorage, ref, listAll } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + + // Create a reference under which you want to list + const listRef = ref(storage, 'files/uid'); + + // Find all the prefixes and items. + listAll(listRef) + .then((res) => { + res.prefixes.forEach((folderRef) => { + // All the prefixes under listRef. + // You may call listAll() recursively on them. + }); + res.items.forEach((itemRef) => { + // All the items under listRef. + }); + }).catch((error) => { + // Uh-oh, an error occurred! + }); + // [END storage_list_all] +} + +function listPaginate() { + // [START storage_list_paginate] + const { getStorage, ref, list } = require("firebase/storage"); + + async function pageTokenExample(){ + // Create a reference under which you want to list + const storage = getStorage(firebaseApp); + const listRef = ref(storage, 'files/uid'); + + // Fetch the first page of 100. + const firstPage = await list(listRef, { maxResults: 100 }); + + // Use the result. + // processItems(firstPage.items) + // processPrefixes(firstPage.prefixes) + + // Fetch the second page if there are more elements. + if (firstPage.nextPageToken) { + const secondPage = await list(listRef, { + maxResults: 100, + pageToken: firstPage.nextPageToken, + }); + // processItems(secondPage.items) + // processPrefixes(secondPage.prefixes) + } + } + // [END storage_list_paginate] +} diff --git a/storage-next/package.json b/storage-next/package.json new file mode 100644 index 00000000..f21c67e0 --- /dev/null +++ b/storage-next/package.json @@ -0,0 +1,11 @@ +{ + "name": "storage-next", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "exp" + } +} diff --git a/storage-next/upload-files.js b/storage-next/upload-files.js new file mode 100644 index 00000000..1ff5d4a8 --- /dev/null +++ b/storage-next/upload-files.js @@ -0,0 +1,245 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function uploadRef() { + // [START storage_upload_ref] + const { getStorage, ref } = require("firebase/storage"); + + // Create a root reference + const storage = getStorage(firebaseApp); + + // Create a reference to 'mountains.jpg' + const mountainsRef = ref(storage, 'mountains.jpg'); + + // Create a reference to 'images/mountains.jpg' + const mountainImagesRef = ref(storage, 'images/mountains.jpg'); + + // While the file names are the same, the references point to different files + mountainsRef.name === mountainImagesRef.name; // true + mountainsRef.fullPath === mountainImagesRef.fullPath; // false + // [END storage_upload_ref] +} + +/** + * @param {File} file + */ +function uploadBlob(file) { + // [START storage_upload_blob] + const { getStorage, ref, uploadBytes } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + const storageRef = ref(storage, 'some-child'); + + // 'file' comes from the Blob or File API + uploadBytes(storageRef, file).then((snapshot) => { + console.log('Uploaded a blob or file!'); + }); + // [END storage_upload_blob] +} + +function uploadBytes() { + // [START storage_upload_bytes] + const { getStorage, ref, uploadBytes } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + const storageRef = ref(storage, 'some-child'); + + const bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21]); + uploadBytes(storageRef, bytes).then((snapshot) => { + console.log('Uploaded an array!'); + }); + // [END storage_upload_bytes] +} + +function uploadString() { + // [START storage_upload_string] + const { getStorage, ref, uploadString } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + const storageRef = ref(storage, 'some-child'); + + // Raw string is the default if no format is provided + const message = 'This is my message.'; + uploadString(storageRef, message).then((snapshot) => { + console.log('Uploaded a raw string!'); + }); + + // Base64 formatted string + const message2 = '5b6p5Y+344GX44G+44GX44Gf77yB44GK44KB44Gn44Go44GG77yB'; + uploadString(storageRef, message2, 'base64').then((snapshot) => { + console.log('Uploaded a base64 string!'); + }); + + // Base64url formatted string + const message3 = '5b6p5Y-344GX44G-44GX44Gf77yB44GK44KB44Gn44Go44GG77yB'; + uploadString(storageRef, message3, 'base64url').then((snapshot) => { + console.log('Uploaded a base64url string!'); + }); + + // Data URL string + const message4 = 'data:text/plain;base64,5b6p5Y+344GX44G+44GX44Gf77yB44GK44KB44Gn44Go44GG77yB'; + uploadString(storageRef, message4, 'data_url').then((snapshot) => { + console.log('Uploaded a data_url string!'); + }); + // [END storage_upload_string] +} + +/** + * @param {File} file + */ +function uploadMetadata(file) { + // [START storage_upload_metadata] + const { getStorage, ref, uploadBytes } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + const storageRef = ref(storage, 'images/mountains.jpg'); + + // Create file metadata including the content type + /** @type {any} */ + const metadata = { + contentType: 'image/jpeg', + }; + + // Upload the file and metadata + const uploadTask = uploadBytes(storageRef, file, metadata); + // [END storage_upload_metadata] +} + +/** + * @param {File} file + */ +function manageUploads(file) { + // [START storage_manage_uploads] + const { getStorage, ref, uploadBytesResumable } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + const storageRef = ref(storage, 'images/mountains.jpg'); + + // Upload the file and metadata + const uploadTask = uploadBytesResumable(storageRef, file); + + // Pause the upload + uploadTask.pause(); + + // Resume the upload + uploadTask.resume(); + + // Cancel the upload + uploadTask.cancel(); + // [END storage_manage_uploads] +} + +/** + * @param {File} file + */ +function monitorUpload(file) { + // [START storage_monitor_upload] + const { getStorage, ref, uploadBytesResumable, getDownloadURL } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + const storageRef = ref(storage, 'images/rivers.jpg'); + + const uploadTask = uploadBytesResumable(storageRef, file); + + // Register three observers: + // 1. 'state_changed' observer, called any time the state changes + // 2. Error observer, called on failure + // 3. Completion observer, called on successful completion + uploadTask.on('state_changed', + (snapshot) => { + // Observe state change events such as progress, pause, and resume + // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded + const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; + console.log('Upload is ' + progress + '% done'); + switch (snapshot.state) { + case 'paused': + console.log('Upload is paused'); + break; + case 'running': + console.log('Upload is running'); + break; + } + }, + (error) => { + // Handle unsuccessful uploads + }, + () => { + // Handle successful uploads on complete + // For instance, get the download URL: https://firebasestorage.googleapis.com/... + getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => { + console.log('File available at', downloadURL); + }); + } + ); + // [END storage_monitor_upload] +} + +/** + * @param {File} file + */ +function uploadHandleError(file) { + // [START storage_upload_handle_error] + const { getStorage, ref, uploadBytesResumable, getDownloadURL } = require("firebase/storage"); + + const storage = getStorage(firebaseApp); + + // Create the file metadata + /** @type {any} */ + const metadata = { + contentType: 'image/jpeg' + }; + + // Upload file and metadata to the object 'images/mountains.jpg' + const storageRef = ref(storage, 'images/' + file.name); + const uploadTask = uploadBytesResumable(storageRef, file, metadata); + + // Listen for state changes, errors, and completion of the upload. + uploadTask.on('state_changed', + (snapshot) => { + // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded + const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; + console.log('Upload is ' + progress + '% done'); + switch (snapshot.state) { + case 'paused': + console.log('Upload is paused'); + break; + case 'running': + console.log('Upload is running'); + break; + } + }, + (error) => { + // A full list of error codes is available at + // https://firebase.google.com/docs/storage/web/handle-errors + switch (error.code) { + case 'storage/unauthorized': + // User doesn't have permission to access the object + break; + case 'storage/canceled': + // User canceled the upload + break; + + // ... + + case 'storage/unknown': + // Unknown error occurred, inspect error.serverResponse + break; + } + }, + () => { + // Upload completed successfully, now we can get the download URL + getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => { + console.log('File available at', downloadURL); + }); + } + ); + // [END storage_upload_handle_error] +} From 798d73f4b7166b858deba097caabaabbf76d0220 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 25 Jan 2021 11:28:13 +0000 Subject: [PATCH 080/235] Generate storage snippets --- .../create-reference/storage_create_ref.js | 14 +++++ .../storage_create_ref_child.js | 19 ++++++ .../create-reference/storage_navigate_ref.js | 19 ++++++ .../storage_navigate_ref_chain.js | 18 ++++++ .../storage_ref_full_example.js | 30 +++++++++ .../storage_ref_properties.js | 22 +++++++ .../delete-files/storage_delete_file.js | 20 ++++++ .../storage_download_create_ref.js | 19 ++++++ .../storage_download_full_example.js | 39 ++++++++++++ .../storage_download_via_url.js | 30 +++++++++ .../file-metadata/storage_custom_metadata.js | 13 ++++ .../file-metadata/storage_delete_metadata.js | 24 ++++++++ .../file-metadata/storage_get_metadata.js | 21 +++++++ .../file-metadata/storage_update_metadata.js | 26 ++++++++ .../storage-next/index/storage_custom_app.js | 8 +++ .../storage-next/index/storage_initialize.js | 22 +++++++ .../index/storage_multiple_buckets.js | 8 +++ .../storage-next/index/storage_on_complete.js | 24 ++++++++ .../list-files/storage_list_all.js | 27 ++++++++ .../list-files/storage_list_paginate.js | 31 ++++++++++ .../upload-files/storage_manage_uploads.js | 23 +++++++ .../upload-files/storage_monitor_upload.js | 44 +++++++++++++ .../upload-files/storage_upload_blob.js | 16 +++++ .../upload-files/storage_upload_bytes.js | 16 +++++ .../storage_upload_handle_error.js | 61 +++++++++++++++++++ .../upload-files/storage_upload_metadata.js | 20 ++++++ .../upload-files/storage_upload_ref.js | 21 +++++++ .../upload-files/storage_upload_string.js | 35 +++++++++++ 28 files changed, 670 insertions(+) create mode 100644 snippets/storage-next/create-reference/storage_create_ref.js create mode 100644 snippets/storage-next/create-reference/storage_create_ref_child.js create mode 100644 snippets/storage-next/create-reference/storage_navigate_ref.js create mode 100644 snippets/storage-next/create-reference/storage_navigate_ref_chain.js create mode 100644 snippets/storage-next/create-reference/storage_ref_full_example.js create mode 100644 snippets/storage-next/create-reference/storage_ref_properties.js create mode 100644 snippets/storage-next/delete-files/storage_delete_file.js create mode 100644 snippets/storage-next/download-files/storage_download_create_ref.js create mode 100644 snippets/storage-next/download-files/storage_download_full_example.js create mode 100644 snippets/storage-next/download-files/storage_download_via_url.js create mode 100644 snippets/storage-next/file-metadata/storage_custom_metadata.js create mode 100644 snippets/storage-next/file-metadata/storage_delete_metadata.js create mode 100644 snippets/storage-next/file-metadata/storage_get_metadata.js create mode 100644 snippets/storage-next/file-metadata/storage_update_metadata.js create mode 100644 snippets/storage-next/index/storage_custom_app.js create mode 100644 snippets/storage-next/index/storage_initialize.js create mode 100644 snippets/storage-next/index/storage_multiple_buckets.js create mode 100644 snippets/storage-next/index/storage_on_complete.js create mode 100644 snippets/storage-next/list-files/storage_list_all.js create mode 100644 snippets/storage-next/list-files/storage_list_paginate.js create mode 100644 snippets/storage-next/upload-files/storage_manage_uploads.js create mode 100644 snippets/storage-next/upload-files/storage_monitor_upload.js create mode 100644 snippets/storage-next/upload-files/storage_upload_blob.js create mode 100644 snippets/storage-next/upload-files/storage_upload_bytes.js create mode 100644 snippets/storage-next/upload-files/storage_upload_handle_error.js create mode 100644 snippets/storage-next/upload-files/storage_upload_metadata.js create mode 100644 snippets/storage-next/upload-files/storage_upload_ref.js create mode 100644 snippets/storage-next/upload-files/storage_upload_string.js diff --git a/snippets/storage-next/create-reference/storage_create_ref.js b/snippets/storage-next/create-reference/storage_create_ref.js new file mode 100644 index 00000000..f69cc959 --- /dev/null +++ b/snippets/storage-next/create-reference/storage_create_ref.js @@ -0,0 +1,14 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/create-reference.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_create_ref_modular] +import { getStorage, ref } from "firebase/storage"; + +// Get a reference to the storage service, which is used to create references in your storage bucket +const storage = getStorage(firebaseApp); + +// Create a storage reference from our storage service +const storageRef = ref(storage); +// [END storage_create_ref_modular] \ No newline at end of file diff --git a/snippets/storage-next/create-reference/storage_create_ref_child.js b/snippets/storage-next/create-reference/storage_create_ref_child.js new file mode 100644 index 00000000..ded271e0 --- /dev/null +++ b/snippets/storage-next/create-reference/storage_create_ref_child.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/create-reference.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_create_ref_child_modular] +import { getStorage, ref } from "firebase/storage"; + +const storage = getStorage(firebaseApp); + +// Create a child reference +const imagesRef = ref(storage, 'images'); +// imagesRef now points to 'images' + +// Child references can also take paths delimited by '/' +const spaceRef = ref(storage, 'images/space.jpg'); +// spaceRef now points to "images/space.jpg" +// imagesRef still points to "images" +// [END storage_create_ref_child_modular] \ No newline at end of file diff --git a/snippets/storage-next/create-reference/storage_navigate_ref.js b/snippets/storage-next/create-reference/storage_navigate_ref.js new file mode 100644 index 00000000..3cdc6b6d --- /dev/null +++ b/snippets/storage-next/create-reference/storage_navigate_ref.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/create-reference.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_navigate_ref_modular] +import { getStorage, ref } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +const spaceRef = ref(storage, 'images/space.jpg'); + +// Parent allows us to move to the parent of a reference +const imagesRef = spaceRef.parent; +// imagesRef now points to 'images' + +// Root allows us to move all the way back to the top of our bucket +const rootRef = spaceRef.root; +// rootRef now points to the root +// [END storage_navigate_ref_modular] \ No newline at end of file diff --git a/snippets/storage-next/create-reference/storage_navigate_ref_chain.js b/snippets/storage-next/create-reference/storage_navigate_ref_chain.js new file mode 100644 index 00000000..93607b72 --- /dev/null +++ b/snippets/storage-next/create-reference/storage_navigate_ref_chain.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/create-reference.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_navigate_ref_chain_modular] +import { getStorage, ref } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +const spaceRef = ref(storage, 'images/space.jpg'); + +// References can be chained together multiple times +const earthRef = ref(spaceRef.parent, 'earth.jpg'); +// earthRef points to 'images/earth.jpg' + +// nullRef is null, since the parent of root is null +const nullRef = spaceRef.root.parent; +// [END storage_navigate_ref_chain_modular] \ No newline at end of file diff --git a/snippets/storage-next/create-reference/storage_ref_full_example.js b/snippets/storage-next/create-reference/storage_ref_full_example.js new file mode 100644 index 00000000..0869f09c --- /dev/null +++ b/snippets/storage-next/create-reference/storage_ref_full_example.js @@ -0,0 +1,30 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/create-reference.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_ref_full_example_modular] +import { getStorage, ref } from "firebase/storage"; + +const storage = getStorage(firebaseApp); + +// Points to the root reference +const storageRef = ref(storage); + +// Points to 'images' +const imagesRef = ref(storageRef, 'images'); + +// Points to 'images/space.jpg' +// Note that you can use variables to create child values +const fileName = 'space.jpg'; +const spaceRef = ref(imagesRef, fileName); + +// File path is 'images/space.jpg' +const path = spaceRef.fullPath; + +// File name is 'space.jpg' +const name = spaceRef.name; + +// Points to 'images' +const imagesRefAgain = spaceRef.parent; +// [END storage_ref_full_example_modular] \ No newline at end of file diff --git a/snippets/storage-next/create-reference/storage_ref_properties.js b/snippets/storage-next/create-reference/storage_ref_properties.js new file mode 100644 index 00000000..4707b931 --- /dev/null +++ b/snippets/storage-next/create-reference/storage_ref_properties.js @@ -0,0 +1,22 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/create-reference.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_ref_properties_modular] +import { getStorage, ref } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +const spaceRef = ref(storage, 'images/space.jpg'); + +// Reference's path is: 'images/space.jpg' +// This is analogous to a file path on disk +spaceRef.fullPath; + +// Reference's name is the last segment of the full path: 'space.jpg' +// This is analogous to the file name +spaceRef.name; + +// Reference's bucket is the name of the storage bucket where files are stored +spaceRef.bucket; +// [END storage_ref_properties_modular] \ No newline at end of file diff --git a/snippets/storage-next/delete-files/storage_delete_file.js b/snippets/storage-next/delete-files/storage_delete_file.js new file mode 100644 index 00000000..be582722 --- /dev/null +++ b/snippets/storage-next/delete-files/storage_delete_file.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/delete-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_delete_file_modular] +import { getStorage, ref, deleteObject } from "firebase/storage"; + +const storage = getStorage(firebaseApp); + +// Create a reference to the file to delete +const desertRef = ref(storage, 'images/desert.jpg'); + +// Delete the file +deleteObject(desertRef).then(() => { + // File deleted successfully +}).catch((error) => { + // Uh-oh, an error occurred! +}); +// [END storage_delete_file_modular] \ No newline at end of file diff --git a/snippets/storage-next/download-files/storage_download_create_ref.js b/snippets/storage-next/download-files/storage_download_create_ref.js new file mode 100644 index 00000000..5a17307d --- /dev/null +++ b/snippets/storage-next/download-files/storage_download_create_ref.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/download-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_download_create_ref_modular] +import { getStorage, ref } from "firebase/storage"; + +// Create a reference with an initial file path and name +const storage = getStorage(firebaseApp); +const pathReference = ref(storage, 'images/stars.jpg'); + +// Create a reference from a Google Cloud Storage URI +const gsReference = ref(storage, 'gs://bucket/images/stars.jpg'); + +// Create a reference from an HTTPS URL +// Note that in the URL, characters are URL escaped! +const httpsReference = ref(storage, 'https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg'); +// [END storage_download_create_ref_modular] \ No newline at end of file diff --git a/snippets/storage-next/download-files/storage_download_full_example.js b/snippets/storage-next/download-files/storage_download_full_example.js new file mode 100644 index 00000000..126ce2ea --- /dev/null +++ b/snippets/storage-next/download-files/storage_download_full_example.js @@ -0,0 +1,39 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/download-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_download_full_example_modular] +import { getStorage, ref, getDownloadURL } from "firebase/storage"; + +// Create a reference to the file we want to download +const storage = getStorage(firebaseApp); +const starsRef = ref(storage, 'images/stars.jpg'); + +// Get the download URL +getDownloadURL(starsRef) + .then((url) => { + // Insert url into an tag to "download" + }) + .catch((error) => { + // A full list of error codes is available at + // https://firebase.google.com/docs/storage/web/handle-errors + switch (error.code) { + case 'storage/object-not-found': + // File doesn't exist + break; + case 'storage/unauthorized': + // User doesn't have permission to access the object + break; + case 'storage/canceled': + // User canceled the upload + break; + + // ... + + case 'storage/unknown': + // Unknown error occurred, inspect the server response + break; + } + }); +// [END storage_download_full_example_modular] \ No newline at end of file diff --git a/snippets/storage-next/download-files/storage_download_via_url.js b/snippets/storage-next/download-files/storage_download_via_url.js new file mode 100644 index 00000000..50be6f65 --- /dev/null +++ b/snippets/storage-next/download-files/storage_download_via_url.js @@ -0,0 +1,30 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/download-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_download_via_url_modular] +import { getStorage, ref, getDownloadURL } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +getDownloadURL(ref(storage, 'images/stars.jpg')) + .then((url) => { + // `url` is the download URL for 'images/stars.jpg' + + // This can be downloaded directly: + const xhr = new XMLHttpRequest(); + xhr.responseType = 'blob'; + xhr.onload = (event) => { + const blob = xhr.response; + }; + xhr.open('GET', url); + xhr.send(); + + // Or inserted into an element + const img = document.getElementById('myimg'); + img.setAttribute('src', url); + }) + .catch((error) => { + // Handle any errors + }); +// [END storage_download_via_url_modular] \ No newline at end of file diff --git a/snippets/storage-next/file-metadata/storage_custom_metadata.js b/snippets/storage-next/file-metadata/storage_custom_metadata.js new file mode 100644 index 00000000..7674c7d4 --- /dev/null +++ b/snippets/storage-next/file-metadata/storage_custom_metadata.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/file-metadata.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_custom_metadata_modular] +const metadata = { + customMetadata: { + 'location': 'Yosemite, CA, USA', + 'activity': 'Hiking' + } +}; +// [END storage_custom_metadata_modular] \ No newline at end of file diff --git a/snippets/storage-next/file-metadata/storage_delete_metadata.js b/snippets/storage-next/file-metadata/storage_delete_metadata.js new file mode 100644 index 00000000..927e4be8 --- /dev/null +++ b/snippets/storage-next/file-metadata/storage_delete_metadata.js @@ -0,0 +1,24 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/file-metadata.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_delete_metadata_modular] +import { getStorage, ref, updateMetadata } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +const forestRef = ref(storage, 'images/forest.jpg'); + +// Create file metadata with property to delete +const deleteMetadata = { + contentType: null +}; + +// Delete the metadata property +updateMetadata(forestRef, deleteMetadata) + .then((metadata) => { + // metadata.contentType should be null + }).catch((error) => { + // Uh-oh, an error occurred! + }); +// [END storage_delete_metadata_modular] \ No newline at end of file diff --git a/snippets/storage-next/file-metadata/storage_get_metadata.js b/snippets/storage-next/file-metadata/storage_get_metadata.js new file mode 100644 index 00000000..8bc462f1 --- /dev/null +++ b/snippets/storage-next/file-metadata/storage_get_metadata.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/file-metadata.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_get_metadata_modular] +import { getStorage, ref, getMetadata } from "firebase/storage"; + +// Create a reference to the file whose metadata we want to retrieve +const storage = getStorage(firebaseApp); +const forestRef = ref(storage, 'images/forest.jpg'); + +// Get metadata properties +getMetadata(forestRef) + .then((metadata) => { + // Metadata now contains the metadata for 'images/forest.jpg' + }) + .catch((error) => { + // Uh-oh, an error occurred! + }); +// [END storage_get_metadata_modular] \ No newline at end of file diff --git a/snippets/storage-next/file-metadata/storage_update_metadata.js b/snippets/storage-next/file-metadata/storage_update_metadata.js new file mode 100644 index 00000000..97cacc4b --- /dev/null +++ b/snippets/storage-next/file-metadata/storage_update_metadata.js @@ -0,0 +1,26 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/file-metadata.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_update_metadata_modular] +import { getStorage, ref, updateMetadata } from "firebase/storage"; + +// Create a reference to the file whose metadata we want to change +const storage = getStorage(firebaseApp); +const forestRef = ref(storage, 'images/forest.jpg'); + +// Create file metadata to update +const newMetadata = { + cacheControl: 'public,max-age=300', + contentType: 'image/jpeg' +}; + +// Update metadata properties +updateMetadata(forestRef, newMetadata) + .then((metadata) => { + // Updated metadata for 'images/forest.jpg' is returned in the Promise + }).catch((error) => { + // Uh-oh, an error occurred! + }); +// [END storage_update_metadata_modular] \ No newline at end of file diff --git a/snippets/storage-next/index/storage_custom_app.js b/snippets/storage-next/index/storage_custom_app.js new file mode 100644 index 00000000..71827148 --- /dev/null +++ b/snippets/storage-next/index/storage_custom_app.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_custom_app_modular] +// TODO: Snippet not yet written... +// [END storage_custom_app_modular] \ No newline at end of file diff --git a/snippets/storage-next/index/storage_initialize.js b/snippets/storage-next/index/storage_initialize.js new file mode 100644 index 00000000..ec69f915 --- /dev/null +++ b/snippets/storage-next/index/storage_initialize.js @@ -0,0 +1,22 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_initialize_modular] +import { initializeApp } from "firebase/app"; +import { getStorage, uploadBytesResumable } from "firebase/storage"; + +// Set the configuration for your app +// TODO: Replace with your app's config object +const firebaseConfig = { + apiKey: '', + authDomain: '', + databaseURL: '', + storageBucket: '' +}; +const firebaseApp = initializeApp(firebaseConfig); + +// Get a reference to the storage service, which is used to create references in your storage bucket +const storage = getStorage(firebaseApp); +// [END storage_initialize_modular] \ No newline at end of file diff --git a/snippets/storage-next/index/storage_multiple_buckets.js b/snippets/storage-next/index/storage_multiple_buckets.js new file mode 100644 index 00000000..86908130 --- /dev/null +++ b/snippets/storage-next/index/storage_multiple_buckets.js @@ -0,0 +1,8 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_multiple_buckets_modular] +// TODO: Snippet not yet written... +// [END storage_multiple_buckets_modular] \ No newline at end of file diff --git a/snippets/storage-next/index/storage_on_complete.js b/snippets/storage-next/index/storage_on_complete.js new file mode 100644 index 00000000..c0c615ff --- /dev/null +++ b/snippets/storage-next/index/storage_on_complete.js @@ -0,0 +1,24 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_on_complete_modular] +import { getStorage, ref, uploadBytesResumable, getDownloadURL } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +const imageRef = ref(storage, 'images/' + file.name); +uploadBytesResumable(imageRef, file, metadata) + .then((snapshot) => { + console.log('Uploaded', snapshot.totalBytes, 'bytes.'); + console.log('File metadata:', snapshot.metadata); + // Let's get a download URL for the file. + getDownloadURL(snapshot.ref).then((url) => { + console.log('File available at', url); + // ... + }); + }).catch((error) => { + console.error('Upload failed', error); + // ... + }); +// [END storage_on_complete_modular] \ No newline at end of file diff --git a/snippets/storage-next/list-files/storage_list_all.js b/snippets/storage-next/list-files/storage_list_all.js new file mode 100644 index 00000000..9f794ca4 --- /dev/null +++ b/snippets/storage-next/list-files/storage_list_all.js @@ -0,0 +1,27 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/list-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_list_all_modular] +import { getStorage, ref, listAll } from "firebase/storage"; + +const storage = getStorage(firebaseApp); + +// Create a reference under which you want to list +const listRef = ref(storage, 'files/uid'); + +// Find all the prefixes and items. +listAll(listRef) + .then((res) => { + res.prefixes.forEach((folderRef) => { + // All the prefixes under listRef. + // You may call listAll() recursively on them. + }); + res.items.forEach((itemRef) => { + // All the items under listRef. + }); + }).catch((error) => { + // Uh-oh, an error occurred! + }); +// [END storage_list_all_modular] \ No newline at end of file diff --git a/snippets/storage-next/list-files/storage_list_paginate.js b/snippets/storage-next/list-files/storage_list_paginate.js new file mode 100644 index 00000000..4415ccdc --- /dev/null +++ b/snippets/storage-next/list-files/storage_list_paginate.js @@ -0,0 +1,31 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/list-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_list_paginate_modular] +import { getStorage, ref, list } from "firebase/storage"; + +async function pageTokenExample(){ + // Create a reference under which you want to list + const storage = getStorage(firebaseApp); + const listRef = ref(storage, 'files/uid'); + + // Fetch the first page of 100. + const firstPage = await list(listRef, { maxResults: 100 }); + + // Use the result. + // processItems(firstPage.items) + // processPrefixes(firstPage.prefixes) + + // Fetch the second page if there are more elements. + if (firstPage.nextPageToken) { + const secondPage = await list(listRef, { + maxResults: 100, + pageToken: firstPage.nextPageToken, + }); + // processItems(secondPage.items) + // processPrefixes(secondPage.prefixes) + } +} +// [END storage_list_paginate_modular] \ No newline at end of file diff --git a/snippets/storage-next/upload-files/storage_manage_uploads.js b/snippets/storage-next/upload-files/storage_manage_uploads.js new file mode 100644 index 00000000..476503bb --- /dev/null +++ b/snippets/storage-next/upload-files/storage_manage_uploads.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/upload-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_manage_uploads_modular] +import { getStorage, ref, uploadBytesResumable } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +const storageRef = ref(storage, 'images/mountains.jpg'); + +// Upload the file and metadata +const uploadTask = uploadBytesResumable(storageRef, file); + +// Pause the upload +uploadTask.pause(); + +// Resume the upload +uploadTask.resume(); + +// Cancel the upload +uploadTask.cancel(); +// [END storage_manage_uploads_modular] \ No newline at end of file diff --git a/snippets/storage-next/upload-files/storage_monitor_upload.js b/snippets/storage-next/upload-files/storage_monitor_upload.js new file mode 100644 index 00000000..f6d81935 --- /dev/null +++ b/snippets/storage-next/upload-files/storage_monitor_upload.js @@ -0,0 +1,44 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/upload-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_monitor_upload_modular] +import { getStorage, ref, uploadBytesResumable, getDownloadURL } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +const storageRef = ref(storage, 'images/rivers.jpg'); + +const uploadTask = uploadBytesResumable(storageRef, file); + +// Register three observers: +// 1. 'state_changed' observer, called any time the state changes +// 2. Error observer, called on failure +// 3. Completion observer, called on successful completion +uploadTask.on('state_changed', + (snapshot) => { + // Observe state change events such as progress, pause, and resume + // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded + const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; + console.log('Upload is ' + progress + '% done'); + switch (snapshot.state) { + case 'paused': + console.log('Upload is paused'); + break; + case 'running': + console.log('Upload is running'); + break; + } + }, + (error) => { + // Handle unsuccessful uploads + }, + () => { + // Handle successful uploads on complete + // For instance, get the download URL: https://firebasestorage.googleapis.com/... + getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => { + console.log('File available at', downloadURL); + }); + } +); +// [END storage_monitor_upload_modular] \ No newline at end of file diff --git a/snippets/storage-next/upload-files/storage_upload_blob.js b/snippets/storage-next/upload-files/storage_upload_blob.js new file mode 100644 index 00000000..11970dea --- /dev/null +++ b/snippets/storage-next/upload-files/storage_upload_blob.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/upload-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_upload_blob_modular] +import { getStorage, ref, uploadBytes } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +const storageRef = ref(storage, 'some-child'); + +// 'file' comes from the Blob or File API +uploadBytes(storageRef, file).then((snapshot) => { + console.log('Uploaded a blob or file!'); +}); +// [END storage_upload_blob_modular] \ No newline at end of file diff --git a/snippets/storage-next/upload-files/storage_upload_bytes.js b/snippets/storage-next/upload-files/storage_upload_bytes.js new file mode 100644 index 00000000..aa906060 --- /dev/null +++ b/snippets/storage-next/upload-files/storage_upload_bytes.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/upload-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_upload_bytes_modular] +import { getStorage, ref, uploadBytes } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +const storageRef = ref(storage, 'some-child'); + +const bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21]); +uploadBytes(storageRef, bytes).then((snapshot) => { + console.log('Uploaded an array!'); +}); +// [END storage_upload_bytes_modular] \ No newline at end of file diff --git a/snippets/storage-next/upload-files/storage_upload_handle_error.js b/snippets/storage-next/upload-files/storage_upload_handle_error.js new file mode 100644 index 00000000..3baa5758 --- /dev/null +++ b/snippets/storage-next/upload-files/storage_upload_handle_error.js @@ -0,0 +1,61 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/upload-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_upload_handle_error_modular] +import { getStorage, ref, uploadBytesResumable, getDownloadURL } from "firebase/storage"; + +const storage = getStorage(firebaseApp); + +// Create the file metadata +/** @type {any} */ +const metadata = { + contentType: 'image/jpeg' +}; + +// Upload file and metadata to the object 'images/mountains.jpg' +const storageRef = ref(storage, 'images/' + file.name); +const uploadTask = uploadBytesResumable(storageRef, file, metadata); + +// Listen for state changes, errors, and completion of the upload. +uploadTask.on('state_changed', + (snapshot) => { + // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded + const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; + console.log('Upload is ' + progress + '% done'); + switch (snapshot.state) { + case 'paused': + console.log('Upload is paused'); + break; + case 'running': + console.log('Upload is running'); + break; + } + }, + (error) => { + // A full list of error codes is available at + // https://firebase.google.com/docs/storage/web/handle-errors + switch (error.code) { + case 'storage/unauthorized': + // User doesn't have permission to access the object + break; + case 'storage/canceled': + // User canceled the upload + break; + + // ... + + case 'storage/unknown': + // Unknown error occurred, inspect error.serverResponse + break; + } + }, + () => { + // Upload completed successfully, now we can get the download URL + getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => { + console.log('File available at', downloadURL); + }); + } +); +// [END storage_upload_handle_error_modular] \ No newline at end of file diff --git a/snippets/storage-next/upload-files/storage_upload_metadata.js b/snippets/storage-next/upload-files/storage_upload_metadata.js new file mode 100644 index 00000000..6632cfb6 --- /dev/null +++ b/snippets/storage-next/upload-files/storage_upload_metadata.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/upload-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_upload_metadata_modular] +import { getStorage, ref, uploadBytes } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +const storageRef = ref(storage, 'images/mountains.jpg'); + +// Create file metadata including the content type +/** @type {any} */ +const metadata = { + contentType: 'image/jpeg', +}; + +// Upload the file and metadata +const uploadTask = uploadBytes(storageRef, file, metadata); +// [END storage_upload_metadata_modular] \ No newline at end of file diff --git a/snippets/storage-next/upload-files/storage_upload_ref.js b/snippets/storage-next/upload-files/storage_upload_ref.js new file mode 100644 index 00000000..820b2632 --- /dev/null +++ b/snippets/storage-next/upload-files/storage_upload_ref.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/upload-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_upload_ref_modular] +import { getStorage, ref } from "firebase/storage"; + +// Create a root reference +const storage = getStorage(firebaseApp); + +// Create a reference to 'mountains.jpg' +const mountainsRef = ref(storage, 'mountains.jpg'); + +// Create a reference to 'images/mountains.jpg' +const mountainImagesRef = ref(storage, 'images/mountains.jpg'); + +// While the file names are the same, the references point to different files +mountainsRef.name === mountainImagesRef.name; // true +mountainsRef.fullPath === mountainImagesRef.fullPath; // false +// [END storage_upload_ref_modular] \ No newline at end of file diff --git a/snippets/storage-next/upload-files/storage_upload_string.js b/snippets/storage-next/upload-files/storage_upload_string.js new file mode 100644 index 00000000..80b8aaa3 --- /dev/null +++ b/snippets/storage-next/upload-files/storage_upload_string.js @@ -0,0 +1,35 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/upload-files.js +// +// To make edits to the snippets in this file, please edit the source + +// [START storage_upload_string_modular] +import { getStorage, ref, uploadString } from "firebase/storage"; + +const storage = getStorage(firebaseApp); +const storageRef = ref(storage, 'some-child'); + +// Raw string is the default if no format is provided +const message = 'This is my message.'; +uploadString(storageRef, message).then((snapshot) => { + console.log('Uploaded a raw string!'); +}); + +// Base64 formatted string +const message2 = '5b6p5Y+344GX44G+44GX44Gf77yB44GK44KB44Gn44Go44GG77yB'; +uploadString(storageRef, message2, 'base64').then((snapshot) => { + console.log('Uploaded a base64 string!'); +}); + +// Base64url formatted string +const message3 = '5b6p5Y-344GX44G-44GX44Gf77yB44GK44KB44Gn44Go44GG77yB'; +uploadString(storageRef, message3, 'base64url').then((snapshot) => { + console.log('Uploaded a base64url string!'); +}); + +// Data URL string +const message4 = 'data:text/plain;base64,5b6p5Y+344GX44G+44GX44Gf77yB44GK44KB44Gn44Go44GG77yB'; +uploadString(storageRef, message4, 'data_url').then((snapshot) => { + console.log('Uploaded a data_url string!'); +}); +// [END storage_upload_string_modular] \ No newline at end of file From db0ad0d144f6c9336f99928e79819e7415c5b052 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 25 Jan 2021 11:45:49 +0000 Subject: [PATCH 081/235] Add Database snippets --- database-next/emulator-suite.js | 32 ++++ database-next/index.js | 18 ++ database-next/lists-of-data.js | 99 +++++++++++ database-next/package.json | 11 ++ database-next/read-and-write.js | 161 ++++++++++++++++++ database-next/sharding.js | 31 ++++ database/read-and-write.js | 2 +- lerna.json | 1 + .../emulator-suite/rtdb_emulator_connect.js | 14 ++ .../emulator-suite/rtdb_emulator_flush.js | 12 ++ .../database-next/index/rtdb_get_reference.js | 10 ++ .../rtdb_social_listen_children.js | 22 +++ .../lists-of-data/rtdb_social_listen_value.js | 19 +++ .../lists-of-data/rtdb_social_most_starred.js | 15 ++ .../lists-of-data/rtdb_social_most_viewed.js | 11 ++ .../lists-of-data/rtdb_social_push.js | 16 ++ .../lists-of-data/rtdb_social_recent.js | 11 ++ .../rtdb_social_completion_callback.js | 21 +++ .../rtdb_social_listen_star_count.js | 15 ++ .../rtdb_social_single_value_read.js | 18 ++ .../rtdb_social_star_transaction.js | 29 ++++ .../rtdb_social_write_fan_out.js | 30 ++++ .../read-and-write/rtdb_write_new_user.js | 17 ++ .../rtdb_write_new_user_completion.js | 21 +++ .../sharding/rtdb_multiple_instances.js | 23 +++ 25 files changed, 658 insertions(+), 1 deletion(-) create mode 100644 database-next/emulator-suite.js create mode 100644 database-next/index.js create mode 100644 database-next/lists-of-data.js create mode 100644 database-next/package.json create mode 100644 database-next/read-and-write.js create mode 100644 database-next/sharding.js create mode 100644 snippets/database-next/emulator-suite/rtdb_emulator_connect.js create mode 100644 snippets/database-next/emulator-suite/rtdb_emulator_flush.js create mode 100644 snippets/database-next/index/rtdb_get_reference.js create mode 100644 snippets/database-next/lists-of-data/rtdb_social_listen_children.js create mode 100644 snippets/database-next/lists-of-data/rtdb_social_listen_value.js create mode 100644 snippets/database-next/lists-of-data/rtdb_social_most_starred.js create mode 100644 snippets/database-next/lists-of-data/rtdb_social_most_viewed.js create mode 100644 snippets/database-next/lists-of-data/rtdb_social_push.js create mode 100644 snippets/database-next/lists-of-data/rtdb_social_recent.js create mode 100644 snippets/database-next/read-and-write/rtdb_social_completion_callback.js create mode 100644 snippets/database-next/read-and-write/rtdb_social_listen_star_count.js create mode 100644 snippets/database-next/read-and-write/rtdb_social_single_value_read.js create mode 100644 snippets/database-next/read-and-write/rtdb_social_star_transaction.js create mode 100644 snippets/database-next/read-and-write/rtdb_social_write_fan_out.js create mode 100644 snippets/database-next/read-and-write/rtdb_write_new_user.js create mode 100644 snippets/database-next/read-and-write/rtdb_write_new_user_completion.js create mode 100644 snippets/database-next/sharding/rtdb_multiple_instances.js diff --git a/database-next/emulator-suite.js b/database-next/emulator-suite.js new file mode 100644 index 00000000..cdcf4896 --- /dev/null +++ b/database-next/emulator-suite.js @@ -0,0 +1,32 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function onDocumentReady() { + // [START rtdb_emulator_connect] + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + if (location.hostname === "localhost") { + // Point to the RTDB emulator running on localhost. + db.useEmulator("localhost", 9000); + } + // [END rtdb_emulator_connect] +} + +function flushRealtimeDatabase() { + // [START rtdb_emulator_flush] + const { getDatabase } = require("firebase/database"); + + // With a database Reference, write null to clear the database. + const db = getDatabase(firebaseApp); + db.ref().set(null); + // [END rtdb_emulator_flush] +} diff --git a/database-next/index.js b/database-next/index.js new file mode 100644 index 00000000..53c8584d --- /dev/null +++ b/database-next/index.js @@ -0,0 +1,18 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function getReference() { + // [START rtdb_get_reference] + const { getDatabase } = require("firebase/database"); + + const database = getDatabase(firebaseApp); + // [END rtdb_get_reference] +} diff --git a/database-next/lists-of-data.js b/database-next/lists-of-data.js new file mode 100644 index 00000000..b19371e4 --- /dev/null +++ b/database-next/lists-of-data.js @@ -0,0 +1,99 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function socialPush() { + // [START rtdb_social_push] + const { getDatabase } = require("firebase/database"); + + // Create a new post reference with an auto-generated id + const db = getDatabase(firebaseApp); + const postListRef = db.ref('posts'); + const newPostRef = postListRef.push(); + newPostRef.set({ + // ... + }); + // [END rtdb_social_push] +} + +function socialListenChildren() { + const postElement = document.querySelector("#post"); + const postId = "1234"; + function addCommentElement(el, key, text, author) {} + function setCommentValues(el, key, text, author) {}; + function deleteComment(el, key) {}; + + // [START rtdb_social_listen_children] + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + const commentsRef = db.ref('post-comments/' + postId); + commentsRef.on('child_added', (data) => { + addCommentElement(postElement, data.key, data.val().text, data.val().author); + }); + + commentsRef.on('child_changed', (data) => { + setCommentValues(postElement, data.key, data.val().text, data.val().author); + }); + + commentsRef.on('child_removed', (data) => { + deleteComment(postElement, data.key); + }); + // [END rtdb_social_listen_children] +} + +function socialListenValue() { + + // [START rtdb_social_listen_value] + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + const ref = db.ref('/a/b/c'); + + ref.once('value', (snapshot) => { + snapshot.forEach((childSnapshot) => { + const childKey = childSnapshot.key; + const childData = childSnapshot.val(); + // ... + }); + }); + // [END rtdb_social_listen_value] +} + +function socialMostStarred() { + // [START rtdb_social_most_starred] + const { getDatabase } = require("firebase/database"); + const { getAuth } = require("firebase/auth"); + + const db = getDatabase(firebaseApp); + const auth = getAuth(firebaseApp); + + const myUserId = auth.currentUser.uid; + const topUserPostsRef = db.ref('user-posts/' + myUserId).orderByChild('starCount'); + // [END rtdb_social_most_starred] +} + +function socialMostViewed() { + // [START rtdb_social_most_viewed] + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + const mostViewedPosts = db.ref('posts').orderByChild('metrics/views'); + // [END rtdb_social_most_viewed] +} + +function socialRecent() { + // [START rtdb_social_recent] + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + const recentPostsRef = db.ref('posts').limitToLast(100); + // [END rtdb_social_recent] +} diff --git a/database-next/package.json b/database-next/package.json new file mode 100644 index 00000000..927237f7 --- /dev/null +++ b/database-next/package.json @@ -0,0 +1,11 @@ +{ + "name": "database-next", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "exp" + } +} diff --git a/database-next/read-and-write.js b/database-next/read-and-write.js new file mode 100644 index 00000000..6d890183 --- /dev/null +++ b/database-next/read-and-write.js @@ -0,0 +1,161 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function writeUserData_wrapped() { + // [START rtdb_write_new_user] + const { getDatabase } = require("firebase/database"); + + function writeUserData(userId, name, email, imageUrl) { + const db = getDatabase(firebaseApp); + db.ref('users/' + userId).set({ + username: name, + email: email, + profile_picture : imageUrl + }); + } + // [END rtdb_write_new_user] +} + + +function writeUserDataWithCompletion(userId, name, email, imageUrl) { + // [START rtdb_write_new_user_completion] + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + db.ref('users/' + userId).set({ + username: name, + email: email, + profile_picture : imageUrl + }, (error) => { + if (error) { + // The write failed... + } else { + // Data saved successfully! + } + }); + // [END rtdb_write_new_user_completion] +} + +function socialListenStarCount() { + const postElement = document.querySelector('#post'); + const postId = "1234"; + function updateStarCount(a, b) { + // ... + } + + // [START rtdb_social_listen_star_count] + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + const starCountRef = db.ref('posts/' + postId + '/starCount'); + starCountRef.on('value', (snapshot) => { + const data = snapshot.val(); + updateStarCount(postElement, data); + }); + // [END rtdb_social_listen_star_count] +} + +function socialSingleValueRead() { + // [START rtdb_social_single_value_read] + const { getDatabase } = require("firebase/database"); + const { getAuth } = require("firebase/auth"); + + const db = getDatabase(firebaseApp); + const auth = getAuth(firebaseApp); + + const userId = auth.currentUser.uid; + return db.ref('/users/' + userId).once('value').then((snapshot) => { + const username = (snapshot.val() && snapshot.val().username) || 'Anonymous'; + // ... + }); + // [END rtdb_social_single_value_read] +} + +function writeNewPost_wrapped() { + const { getDatabase } = require("firebase/database"); + + // [START rtdb_social_write_fan_out] + function writeNewPost(uid, username, picture, title, body) { + const db = getDatabase(firebaseApp); + + // A post entry. + const postData = { + author: username, + uid: uid, + body: body, + title: title, + starCount: 0, + authorPic: picture + }; + + // Get a key for a new Post. + const newPostKey = db.ref().child('posts').push().key; + + // Write the new post's data simultaneously in the posts list and the user's post list. + const updates = {}; + updates['/posts/' + newPostKey] = postData; + updates['/user-posts/' + uid + '/' + newPostKey] = postData; + + return db.ref().update(updates); + } + // [END rtdb_social_write_fan_out] +} + +function socialCompletionCallback() { + const userId = "123"; + const email = "test@example.com"; + const imageUrl = "https://example.com/image.png"; + + // [START rtdb_social_completion_callback] + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + db.ref('users/' + userId).set({ + username: name, + email: email, + profile_picture : imageUrl + }, (error) => { + if (error) { + // The write failed... + } else { + // Data saved successfully! + } + }); + // [END rtdb_social_completion_callback] +} + +function toggleStar_wrapped() { + // [START rtdb_social_star_transaction] + const { getDatabase } = require("firebase/database"); + + function toggleStar(uid) { + const db = getDatabase(firebaseApp); + const postRef = db.ref('/posts/foo-bar-123'); + + postRef.transaction((post) => { + if (post) { + if (post.stars && post.stars[uid]) { + post.starCount--; + post.stars[uid] = null; + } else { + post.starCount++; + if (!post.stars) { + post.stars = {}; + } + post.stars[uid] = true; + } + } + return post; + }); + } + // [END rtdb_social_star_transaction] +} + diff --git a/database-next/sharding.js b/database-next/sharding.js new file mode 100644 index 00000000..509503ef --- /dev/null +++ b/database-next/sharding.js @@ -0,0 +1,31 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function multipleInstances() { + // [START rtdb_multiple_instances] + const { initializeApp } = require("firebase/app"); + const { getDatabase } = require("firebase/database"); + + const app1 = initializeApp({ + databaseURL: "https://testapp-1234-1.firebaseio.com" + }); + + const app2 = initializeApp({ + databaseURL: "https://testapp-1234-2.firebaseio.com" + }, 'app2'); + + // Get the default database instance for an app1 + const database1 = getDatabase(app1); + + // Get a database instance for app2 + const database2 = getDatabase(app2); + // [END rtdb_multiple_instances] +} diff --git a/database/read-and-write.js b/database/read-and-write.js index 24b87b61..5fce6c97 100644 --- a/database/read-and-write.js +++ b/database/read-and-write.js @@ -27,7 +27,7 @@ function writeUserDataWithCompletion(userId, name, email, imageUrl) { // Data saved successfully! } }); - // [START rtdb_write_new_user_completion] + // [END rtdb_write_new_user_completion] } function socialListenStarCount() { diff --git a/lerna.json b/lerna.json index 68842173..1275a07e 100644 --- a/lerna.json +++ b/lerna.json @@ -6,6 +6,7 @@ "auth", "auth-next", "database", + "database-next", "firebaseapp", "firestore", "firestore-next", diff --git a/snippets/database-next/emulator-suite/rtdb_emulator_connect.js b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js new file mode 100644 index 00000000..c16f0210 --- /dev/null +++ b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js @@ -0,0 +1,14 @@ +// This snippet file was generated by processing the source file: +// ./database-next/emulator-suite.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_emulator_connect_modular] +import { getDatabase } from "firebase/database"; + +const db = getDatabase(firebaseApp); +if (location.hostname === "localhost") { + // Point to the RTDB emulator running on localhost. + db.useEmulator("localhost", 9000); +} +// [END rtdb_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/database-next/emulator-suite/rtdb_emulator_flush.js b/snippets/database-next/emulator-suite/rtdb_emulator_flush.js new file mode 100644 index 00000000..66f8b282 --- /dev/null +++ b/snippets/database-next/emulator-suite/rtdb_emulator_flush.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./database-next/emulator-suite.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_emulator_flush_modular] +import { getDatabase } from "firebase/database"; + +// With a database Reference, write null to clear the database. +const db = getDatabase(firebaseApp); +db.ref().set(null); +// [END rtdb_emulator_flush_modular] \ No newline at end of file diff --git a/snippets/database-next/index/rtdb_get_reference.js b/snippets/database-next/index/rtdb_get_reference.js new file mode 100644 index 00000000..2e2f31c7 --- /dev/null +++ b/snippets/database-next/index/rtdb_get_reference.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./database-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_get_reference_modular] +import { getDatabase } from "firebase/database"; + +const database = getDatabase(firebaseApp); +// [END rtdb_get_reference_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_listen_children.js b/snippets/database-next/lists-of-data/rtdb_social_listen_children.js new file mode 100644 index 00000000..5aefb875 --- /dev/null +++ b/snippets/database-next/lists-of-data/rtdb_social_listen_children.js @@ -0,0 +1,22 @@ +// This snippet file was generated by processing the source file: +// ./database-next/lists-of-data.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_listen_children_modular] +import { getDatabase } from "firebase/database"; + +const db = getDatabase(firebaseApp); +const commentsRef = db.ref('post-comments/' + postId); +commentsRef.on('child_added', (data) => { + addCommentElement(postElement, data.key, data.val().text, data.val().author); +}); + +commentsRef.on('child_changed', (data) => { + setCommentValues(postElement, data.key, data.val().text, data.val().author); +}); + +commentsRef.on('child_removed', (data) => { + deleteComment(postElement, data.key); +}); +// [END rtdb_social_listen_children_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_listen_value.js b/snippets/database-next/lists-of-data/rtdb_social_listen_value.js new file mode 100644 index 00000000..3958a0d9 --- /dev/null +++ b/snippets/database-next/lists-of-data/rtdb_social_listen_value.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./database-next/lists-of-data.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_listen_value_modular] +import { getDatabase } from "firebase/database"; + +const db = getDatabase(firebaseApp); +const ref = db.ref('/a/b/c'); + +ref.once('value', (snapshot) => { + snapshot.forEach((childSnapshot) => { + const childKey = childSnapshot.key; + const childData = childSnapshot.val(); + // ... + }); +}); +// [END rtdb_social_listen_value_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_most_starred.js b/snippets/database-next/lists-of-data/rtdb_social_most_starred.js new file mode 100644 index 00000000..8c20de7a --- /dev/null +++ b/snippets/database-next/lists-of-data/rtdb_social_most_starred.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./database-next/lists-of-data.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_most_starred_modular] +import { getDatabase } from "firebase/database"; +import { getAuth } from "firebase/auth"; + +const db = getDatabase(firebaseApp); +const auth = getAuth(firebaseApp); + +const myUserId = auth.currentUser.uid; +const topUserPostsRef = db.ref('user-posts/' + myUserId).orderByChild('starCount'); +// [END rtdb_social_most_starred_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js b/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js new file mode 100644 index 00000000..2f5c03f8 --- /dev/null +++ b/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./database-next/lists-of-data.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_most_viewed_modular] +import { getDatabase } from "firebase/database"; + +const db = getDatabase(firebaseApp); +const mostViewedPosts = db.ref('posts').orderByChild('metrics/views'); +// [END rtdb_social_most_viewed_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_push.js b/snippets/database-next/lists-of-data/rtdb_social_push.js new file mode 100644 index 00000000..e3c7f81c --- /dev/null +++ b/snippets/database-next/lists-of-data/rtdb_social_push.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./database-next/lists-of-data.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_push_modular] +import { getDatabase } from "firebase/database"; + +// Create a new post reference with an auto-generated id +const db = getDatabase(firebaseApp); +const postListRef = db.ref('posts'); +const newPostRef = postListRef.push(); +newPostRef.set({ + // ... +}); +// [END rtdb_social_push_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_recent.js b/snippets/database-next/lists-of-data/rtdb_social_recent.js new file mode 100644 index 00000000..58fa2e38 --- /dev/null +++ b/snippets/database-next/lists-of-data/rtdb_social_recent.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./database-next/lists-of-data.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_recent_modular] +import { getDatabase } from "firebase/database"; + +const db = getDatabase(firebaseApp); +const recentPostsRef = db.ref('posts').limitToLast(100); +// [END rtdb_social_recent_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_social_completion_callback.js b/snippets/database-next/read-and-write/rtdb_social_completion_callback.js new file mode 100644 index 00000000..5251b5c4 --- /dev/null +++ b/snippets/database-next/read-and-write/rtdb_social_completion_callback.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./database-next/read-and-write.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_completion_callback_modular] +import { getDatabase } from "firebase/database"; + +const db = getDatabase(firebaseApp); +db.ref('users/' + userId).set({ + username: name, + email: email, + profile_picture : imageUrl +}, (error) => { + if (error) { + // The write failed... + } else { + // Data saved successfully! + } +}); +// [END rtdb_social_completion_callback_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js b/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js new file mode 100644 index 00000000..186afb4f --- /dev/null +++ b/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./database-next/read-and-write.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_listen_star_count_modular] +import { getDatabase } from "firebase/database"; + +const db = getDatabase(firebaseApp); +const starCountRef = db.ref('posts/' + postId + '/starCount'); +starCountRef.on('value', (snapshot) => { + const data = snapshot.val(); + updateStarCount(postElement, data); +}); +// [END rtdb_social_listen_star_count_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_social_single_value_read.js b/snippets/database-next/read-and-write/rtdb_social_single_value_read.js new file mode 100644 index 00000000..b5bfc662 --- /dev/null +++ b/snippets/database-next/read-and-write/rtdb_social_single_value_read.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./database-next/read-and-write.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_single_value_read_modular] +import { getDatabase } from "firebase/database"; +import { getAuth } from "firebase/auth"; + +const db = getDatabase(firebaseApp); +const auth = getAuth(firebaseApp); + +const userId = auth.currentUser.uid; +return db.ref('/users/' + userId).once('value').then((snapshot) => { + const username = (snapshot.val() && snapshot.val().username) || 'Anonymous'; + // ... +}); +// [END rtdb_social_single_value_read_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_social_star_transaction.js b/snippets/database-next/read-and-write/rtdb_social_star_transaction.js new file mode 100644 index 00000000..9c905d2c --- /dev/null +++ b/snippets/database-next/read-and-write/rtdb_social_star_transaction.js @@ -0,0 +1,29 @@ +// This snippet file was generated by processing the source file: +// ./database-next/read-and-write.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_star_transaction_modular] +import { getDatabase } from "firebase/database"; + +function toggleStar(uid) { + const db = getDatabase(firebaseApp); + const postRef = db.ref('/posts/foo-bar-123'); + + postRef.transaction((post) => { + if (post) { + if (post.stars && post.stars[uid]) { + post.starCount--; + post.stars[uid] = null; + } else { + post.starCount++; + if (!post.stars) { + post.stars = {}; + } + post.stars[uid] = true; + } + } + return post; + }); +} +// [END rtdb_social_star_transaction_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js b/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js new file mode 100644 index 00000000..0c2973c4 --- /dev/null +++ b/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js @@ -0,0 +1,30 @@ +// This snippet file was generated by processing the source file: +// ./database-next/read-and-write.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_write_fan_out_modular] +function writeNewPost(uid, username, picture, title, body) { + const db = getDatabase(firebaseApp); + + // A post entry. + const postData = { + author: username, + uid: uid, + body: body, + title: title, + starCount: 0, + authorPic: picture + }; + + // Get a key for a new Post. + const newPostKey = db.ref().child('posts').push().key; + + // Write the new post's data simultaneously in the posts list and the user's post list. + const updates = {}; + updates['/posts/' + newPostKey] = postData; + updates['/user-posts/' + uid + '/' + newPostKey] = postData; + + return db.ref().update(updates); +} +// [END rtdb_social_write_fan_out_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_write_new_user.js b/snippets/database-next/read-and-write/rtdb_write_new_user.js new file mode 100644 index 00000000..c6a84358 --- /dev/null +++ b/snippets/database-next/read-and-write/rtdb_write_new_user.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./database-next/read-and-write.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_write_new_user_modular] +import { getDatabase } from "firebase/database"; + +function writeUserData(userId, name, email, imageUrl) { + const db = getDatabase(firebaseApp); + db.ref('users/' + userId).set({ + username: name, + email: email, + profile_picture : imageUrl + }); +} +// [END rtdb_write_new_user_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js b/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js new file mode 100644 index 00000000..cd10104d --- /dev/null +++ b/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./database-next/read-and-write.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_write_new_user_completion_modular] +import { getDatabase } from "firebase/database"; + +const db = getDatabase(firebaseApp); +db.ref('users/' + userId).set({ + username: name, + email: email, + profile_picture : imageUrl +}, (error) => { + if (error) { + // The write failed... + } else { + // Data saved successfully! + } +}); +// [END rtdb_write_new_user_completion_modular] \ No newline at end of file diff --git a/snippets/database-next/sharding/rtdb_multiple_instances.js b/snippets/database-next/sharding/rtdb_multiple_instances.js new file mode 100644 index 00000000..cd40b918 --- /dev/null +++ b/snippets/database-next/sharding/rtdb_multiple_instances.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./database-next/sharding.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_multiple_instances_modular] +import { initializeApp } from "firebase/app"; +import { getDatabase } from "firebase/database"; + +const app1 = initializeApp({ + databaseURL: "https://testapp-1234-1.firebaseio.com" +}); + +const app2 = initializeApp({ + databaseURL: "https://testapp-1234-2.firebaseio.com" +}, 'app2'); + +// Get the default database instance for an app1 +const database1 = getDatabase(app1); + +// Get a database instance for app2 +const database2 = getDatabase(app2); +// [END rtdb_multiple_instances_modular] \ No newline at end of file From d01cdd5bb99621cf790b30505f1a2a9fec744584 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 25 Jan 2021 11:59:07 +0000 Subject: [PATCH 082/235] Add FirebaseApp vNext Snippets (#94) --- firebaseapp-next/firebaseapp.js | 27 +++++++++++++++++++ firebaseapp-next/package.json | 11 ++++++++ lerna.json | 1 + .../firebaseapp/firebase_options.js | 20 ++++++++++++++ .../firebaseapp/firebase_secondary.js | 11 ++++++++ 5 files changed, 70 insertions(+) create mode 100644 firebaseapp-next/firebaseapp.js create mode 100644 firebaseapp-next/package.json create mode 100644 snippets/firebaseapp-next/firebaseapp/firebase_options.js create mode 100644 snippets/firebaseapp-next/firebaseapp/firebase_secondary.js diff --git a/firebaseapp-next/firebaseapp.js b/firebaseapp-next/firebaseapp.js new file mode 100644 index 00000000..8bd6838f --- /dev/null +++ b/firebaseapp-next/firebaseapp.js @@ -0,0 +1,27 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +function multpleFirebaseApps() { + // [START firebase_options] + const { initializeApp } = require("firebase/app"); + + // The following fields are REQUIRED: + // - Project ID + // - App ID + // - API Key + const secondaryAppConfig = { + projectId: "", + appId: "", + apiKey: "", + // databaseURL: "...", + // storageBucket: "...", + }; + // [END firebase_options] + + // [START firebase_secondary] + // Initialize another app with a different config + const secondaryApp = initializeApp(secondaryAppConfig, "secondary"); + // Access services, such as the Realtime Database + // getDatabase(secondaryApp) + // [END firebase_secondary] +} diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json new file mode 100644 index 00000000..a3f38088 --- /dev/null +++ b/firebaseapp-next/package.json @@ -0,0 +1,11 @@ +{ + "name": "firebaseapp-next", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "exp" + } +} diff --git a/lerna.json b/lerna.json index 1275a07e..a14444a4 100644 --- a/lerna.json +++ b/lerna.json @@ -8,6 +8,7 @@ "database", "database-next", "firebaseapp", + "firebaseapp-next", "firestore", "firestore-next", "functions", diff --git a/snippets/firebaseapp-next/firebaseapp/firebase_options.js b/snippets/firebaseapp-next/firebaseapp/firebase_options.js new file mode 100644 index 00000000..76a420e9 --- /dev/null +++ b/snippets/firebaseapp-next/firebaseapp/firebase_options.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./firebaseapp-next/firebaseapp.js +// +// To make edits to the snippets in this file, please edit the source + +// [START firebase_options_modular] +import { initializeApp } from "firebase/app"; + +// The following fields are REQUIRED: +// - Project ID +// - App ID +// - API Key +const secondaryAppConfig = { + projectId: "", + appId: "", + apiKey: "", + // databaseURL: "...", + // storageBucket: "...", +}; +// [END firebase_options_modular] \ No newline at end of file diff --git a/snippets/firebaseapp-next/firebaseapp/firebase_secondary.js b/snippets/firebaseapp-next/firebaseapp/firebase_secondary.js new file mode 100644 index 00000000..c78f2b3f --- /dev/null +++ b/snippets/firebaseapp-next/firebaseapp/firebase_secondary.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./firebaseapp-next/firebaseapp.js +// +// To make edits to the snippets in this file, please edit the source + +// [START firebase_secondary_modular] +// Initialize another app with a different config +const secondaryApp = initializeApp(secondaryAppConfig, "secondary"); +// Access services, such as the Realtime Database +// getDatabase(secondaryApp) +// [END firebase_secondary_modular] \ No newline at end of file From 82a7449c98400e814978b699703e36c9b67c2dd6 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 1 Feb 2021 02:40:25 -0800 Subject: [PATCH 083/235] Auto-update dependencies. (#95) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index e292956e..1f7c2809 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.4" + "firebase": "^8.2.5" } } diff --git a/auth/package.json b/auth/package.json index a6ea9b7c..12127fc3 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.4", + "firebase": "^8.2.5", "firebaseui": "^4.7.1" } } diff --git a/database/package.json b/database/package.json index ea1468d3..d1a5c823 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.4" + "firebase": "^8.2.5" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index b057f3d6..896fcaff 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.4" + "firebase": "^8.2.5" } } diff --git a/firestore/package.json b/firestore/package.json index 32b040f6..4e907d38 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.4", + "firebase": "^8.2.5", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index c66ef81b..ba64715b 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.4" + "firebase": "^8.2.5" } } diff --git a/installations/package.json b/installations/package.json index f5bb3d37..42db7bac 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.4" + "firebase": "^8.2.5" } } diff --git a/messaging/package.json b/messaging/package.json index cc6f7c81..11ba5bc7 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.4" + "firebase": "^8.2.5" } } diff --git a/perf/package.json b/perf/package.json index f9176094..7593b96e 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.4" + "firebase": "^8.2.5" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 1bfa9cc5..21becdc2 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.4" + "firebase": "^8.2.5" } } diff --git a/storage/package.json b/storage/package.json index 7aad7b77..23f2231a 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.4" + "firebase": "^8.2.5" } } From a0d95bd6cfff7427f8f604f1d06024fe42d84c95 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 1 Feb 2021 05:52:32 -0500 Subject: [PATCH 084/235] Explain repo purpose in README See #96 --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index f0f7a3bc..49015f4f 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,18 @@ This repository holds code snippets used in Web documentation on [firebase.google.com](https://firebase.google.com/docs/). +These snippets are part of our documentation and best read in the context of a documentation page rather than used directly. If you're looking to get started with the Firebase Web SDK the best place to start is [quicstart-web](https://github.com/firebase/quickstart-web). + +## Example + +Consider this page: +https://firebase.google.com/docs/database/web/lists-of-data + +Each snippet in the page is dynamically included from the source in this repository, in this case mostly from this file: +https://github.com/firebase/snippets-web/blob/master/database/lists-of-data.js + +Each snippet has a "region tag" which is defined by `// [START tag]` and `// [END tag]` comments. The code between the tags can be included in our documentation. Keeping the code on GitHub, rather than hard-coded into the HTML of our documentation, allows us to ensure the code is correct and up to date. + ## Contributing We love contributions! See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines. From 4a1c4e54db54ba790829c5ab695631a2ac2c2fd6 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 1 Feb 2021 05:16:21 -0800 Subject: [PATCH 085/235] Auto-update dependencies. --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 3941640e..743db2c2 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From e50024d3d8917cdef336d2a8e8a65f38dc2fe570 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 1 Feb 2021 05:16:26 -0800 Subject: [PATCH 086/235] Auto-update dependencies. --- messaging/service-worker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/messaging/service-worker.js b/messaging/service-worker.js index d239e630..62d8b30b 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.2.4/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.2.4/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.5/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.5/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From ee4f83e790df4868839a3aa22bab82df88bd4819 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Wed, 3 Feb 2021 12:28:50 +0000 Subject: [PATCH 087/235] Prefer arrow functions, const (#99) --- .eslintrc.json | 1 + auth/cordova.js | 2 +- auth/firebaseui.js | 4 +- auth/link-multiple-accounts.js | 28 ++-- database/read-and-write.js | 2 +- firestore-next/test.firestore.js | 20 +-- firestore/test.firestore.js | 132 +++++++++--------- .../test-firestore/city_custom_object.js | 6 +- .../test-firestore/delete_collection.js | 2 +- .../test-firestore/listen_for_users.js | 2 +- storage/upload-files.js | 2 +- 11 files changed, 101 insertions(+), 100 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 2a16144c..7e4337ee 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -13,6 +13,7 @@ "arrow-spacing": ["error"], "no-const-assign": ["error"], "prefer-const": ["error"], + "prefer-arrow-callback": ["error"], "spaced-comment": ["error", "always"], "semi": ["error", "always"] } diff --git a/auth/cordova.js b/auth/cordova.js index 1da36ef1..e7c3fc40 100644 --- a/auth/cordova.js +++ b/auth/cordova.js @@ -14,7 +14,7 @@ function createGoogleProvider() { function cordovaSignInRedirect(provider) { // [START auth_cordova_sign_in_redirect] - firebase.auth().signInWithRedirect(provider).then(function() { + firebase.auth().signInWithRedirect(provider).then(() => { return firebase.auth().getRedirectResult(); }).then((result) => { /** @type {firebase.auth.OAuthCredential} */ diff --git a/auth/firebaseui.js b/auth/firebaseui.js index 2a359d5a..dbbf9031 100644 --- a/auth/firebaseui.js +++ b/auth/firebaseui.js @@ -218,13 +218,13 @@ function fuiConfig() { // [START auth_fui_config] var uiConfig = { callbacks: { - signInSuccessWithAuthResult: function(authResult, redirectUrl) { + signInSuccessWithAuthResult: (authResult, redirectUrl) => { // User successfully signed in. // Return type determines whether we continue the redirect automatically // or whether we leave that to developer to handle. return true; }, - uiShown: function() { + uiShown: () => { // The widget is rendered. // Hide the loader. document.getElementById('loader').style.display = 'none'; diff --git a/auth/link-multiple-accounts.js b/auth/link-multiple-accounts.js index b6419431..30f5a2ec 100644 --- a/auth/link-multiple-accounts.js +++ b/auth/link-multiple-accounts.js @@ -41,10 +41,10 @@ function getProviders() { function simpleLink(credential) { // [START auth_simple_link] auth.currentUser.linkWithCredential(credential) - .then(function(usercred) { + .then((usercred) => { var user = usercred.user; console.log("Account linking success", user); - }).catch(function(error) { + }).catch((error) => { console.log("Account linking error", error); }); // [END auth_simple_link] @@ -53,10 +53,10 @@ function simpleLink(credential) { function anonymousLink(credential) { // [START auth_anonymous_link] auth.currentUser.linkWithCredential(credential) - .then(function(usercred) { + .then((usercred) => { var user = usercred.user; console.log("Anonymous account successfully upgraded", user); - }).catch(function(error) { + }).catch((error) => { console.log("Error upgrading anonymous account", error); }); // [END auth_anonymous_link] @@ -66,12 +66,12 @@ function linkWithPopup() { var provider = new firebase.auth.GoogleAuthProvider(); // [START auth_link_with_popup] - auth.currentUser.linkWithPopup(provider).then(function(result) { + auth.currentUser.linkWithPopup(provider).then((result) => { // Accounts successfully linked. var credential = result.credential; var user = result.user; // ... - }).catch(function(error) { + }).catch((error) => { // Handle Errors here. // ... }); @@ -88,14 +88,14 @@ function linkWithRedirect() { // [END auth_link_with_redirect] // [START auth_get_redirect_result] - auth.getRedirectResult().then(function(result) { + auth.getRedirectResult().then((result) => { if (result.credential) { // Accounts successfully linked. var credential = result.credential; var user = result.user; // ... } - }).catch(function(error) { + }).catch((error) => { // Handle Errors here. // ... }); @@ -118,7 +118,7 @@ function mergeAccounts(newCredential) { repo.delete(prevUser); // Sign in user with the account you want to link to - auth.signInWithCredential(newCredential).then(function(result) { + auth.signInWithCredential(newCredential).then((result) => { console.log("Sign In Success", result); var currentUser = result.user; var currentUserData = repo.get(currentUser); @@ -128,15 +128,15 @@ function mergeAccounts(newCredential) { var mergedData = repo.merge(prevUserData, currentUserData); return prevUser.linkWithCredential(result.credential) - .then(function(linkResult) { + .then((linkResult) => { // Sign in with the newly linked credential return auth.signInWithCredential(linkResult.credential); }) - .then(function(signInResult) { + .then((signInResult) => { // Save the merged data to the new user repo.set(signInResult.user, mergedData); }); - }).catch(function(error) { + }).catch((error) => { // If there are errors we want to undo the data merge/deletion console.log("Sign In Error", error); repo.set(prevUser, prevUserData); @@ -157,10 +157,10 @@ function unlink(providerId) { var user = auth.currentUser; // [START auth_unlink_provider] - user.unlink(providerId).then(function() { + user.unlink(providerId).then(() => { // Auth provider unlinked from account // ... - }).catch(function(error) { + }).catch((error) => { // An error happened // ... }); diff --git a/database/read-and-write.js b/database/read-and-write.js index 5fce6c97..59336c8f 100644 --- a/database/read-and-write.js +++ b/database/read-and-write.js @@ -20,7 +20,7 @@ function writeUserDataWithCompletion(userId, name, email, imageUrl) { username: name, email: email, profile_picture : imageUrl - }, function(error) { + }, (error) => { if (error) { // The write failed... } else { diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 0be9c3ef..15bc159e 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -16,15 +16,15 @@ class City { } // Firestore data converter -var cityConverter = { - toFirestore: function(city) { +const cityConverter = { + toFirestore: (city) => { return { name: city.name, state: city.state, country: city.country }; }, - fromFirestore: function(snapshot, options){ + fromFirestore: (snapshot, options) => { const data = snapshot.data(options); return new City(data.name, data.state, data.country); } @@ -190,7 +190,7 @@ describe("firestore", () => { const q = query(collection(db, "users"), where("born", "<", 1900)); const unsubscribe = onSnapshot(q, (snapshot) => { console.log("Current users born before 1900:"); - snapshot.forEach(function (userSnapshot) { + snapshot.forEach((userSnapshot) => { console.log(userSnapshot.data()); }); }); @@ -360,7 +360,7 @@ describe("firestore", () => { function deleteCollection(db, collectionRef, batchSize) { const q = query(collectionRef, orderBy('__name__'), limit(batchSize)); - return new Promise(function(resolve) { + return new Promise((resolve) => { deleteQueryBatch(db, q, batchSize, resolve); }); } @@ -616,7 +616,7 @@ describe("firestore", () => { }); // [END listen_document] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -632,7 +632,7 @@ describe("firestore", () => { }); // [END listen_document_local] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -650,7 +650,7 @@ describe("firestore", () => { }); // [END listen_with_metadata] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -695,7 +695,7 @@ describe("firestore", () => { console.log("Current cities in CA: ", cities.join(", ")); }); // [END listen_multiple] - setTimeout(function() { + setTimeout(() => { unsubscribe(); done(); }, 2500); @@ -720,7 +720,7 @@ describe("firestore", () => { }); }); // [END listen_diffs] - setTimeout(function() { + setTimeout(() => { unsubscribe(); done(); }, 2500); diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index fe600769..988a3c97 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -61,7 +61,7 @@ describe("firestore", () => { // [START initialize_persistence] firebase.firestore().enablePersistence() - .catch(function(err) { + .catch((err) => { if (err.code == 'failed-precondition') { // Multiple tabs open, persistence can only be enabled // in one tab at a a time. @@ -80,7 +80,7 @@ describe("firestore", () => { var disable = // [START disable_network] firebase.firestore().disableNetwork() - .then(function() { + .then(() => { // Do offline actions // [START_EXCLUDE] console.log("Network disabled!"); @@ -91,7 +91,7 @@ describe("firestore", () => { var enable = // [START enable_network] firebase.firestore().enableNetwork() - .then(function() { + .then(() => { // Do online actions // [START_EXCLUDE] console.log("Network enabled!"); @@ -105,8 +105,8 @@ describe("firestore", () => { it("should reply with .fromCache fields", () => { // [START use_from_cache] db.collection("cities").where("state", "==", "CA") - .onSnapshot({ includeMetadataChanges: true }, function(snapshot) { - snapshot.docChanges().forEach(function(change) { + .onSnapshot({ includeMetadataChanges: true }, (snapshot) => { + snapshot.docChanges().forEach((change) => { if (change.type === "added") { console.log("New city: ", change.doc.data()); } @@ -127,10 +127,10 @@ describe("firestore", () => { last: "Lovelace", born: 1815 }) - .then(function(docRef) { + .then((docRef) => { console.log("Document written with ID: ", docRef.id); }) - .catch(function(error) { + .catch((error) => { console.error("Error adding document: ", error); }); // [END add_ada_lovelace] @@ -159,10 +159,10 @@ describe("firestore", () => { last: "Turing", born: 1912 }) - .then(function(docRef) { + .then((docRef) => { console.log("Document written with ID: ", docRef.id); }) - .catch(function(error) { + .catch((error) => { console.error("Error adding document: ", error); }); // [END add_alan_turing] @@ -176,9 +176,9 @@ describe("firestore", () => { // [START listen_for_users] db.collection("users") .where("born", "<", 1900) - .onSnapshot(function(snapshot) { + .onSnapshot((snapshot) => { console.log("Current users born before 1900:"); - snapshot.forEach(function (userSnapshot) { + snapshot.forEach((userSnapshot) => { console.log(userSnapshot.data()); }); }); @@ -224,10 +224,10 @@ describe("firestore", () => { state: "CA", country: "USA" }) - .then(function() { + .then(() => { console.log("Document successfully written!"); }) - .catch(function(error) { + .catch((error) => { console.error("Error writing document: ", error); }); // [END set_document] @@ -250,7 +250,7 @@ describe("firestore", () => { // [START get_custom_object] db.collection("cities").doc("LA") .withConverter(cityConverter) - .get().then(function(doc) { + .get().then((doc) => { if (doc.exists){ // Convert to City object var city = doc.data(); @@ -258,7 +258,7 @@ describe("firestore", () => { console.log(city.toString()); } else { console.log("No such document!"); - }}).catch(function(error) { + }}).catch((error) => { console.log("Error getting document:", error); }); // [END get_custom_object] @@ -283,7 +283,7 @@ describe("firestore", () => { batch.delete(laRef); // Commit the batch - batch.commit().then(function () { + batch.commit().then(() => { // [START_EXCLUDE] done(); // [END_EXCLUDE] @@ -307,7 +307,7 @@ describe("firestore", () => { } } }; - db.collection("data").doc("one").set(docData).then(function() { + db.collection("data").doc("one").set(docData).then(() => { console.log("Document successfully written!"); }); // [END data_types] @@ -339,7 +339,7 @@ describe("firestore", () => { "age": 13, "favorites.color": "Red" }) - .then(function() { + .then(() => { console.log("Document successfully updated!"); }); // [END update_document_nested] @@ -354,7 +354,7 @@ describe("firestore", () => { function deleteCollection(db, collectionRef, batchSize) { var query = collectionRef.orderBy('__name__').limit(batchSize); - return new Promise(function(resolve, reject) { + return new Promise((resolve, reject) => { deleteQueryBatch(db, query, batchSize, resolve, reject); }); } @@ -369,14 +369,14 @@ describe("firestore", () => { // Delete documents in a batch var batch = db.batch(); - snapshot.docs.forEach(function(doc) { + snapshot.docs.forEach((doc) => { batch.delete(doc.ref); }); - return batch.commit().then(function() { + return batch.commit().then(() => { return snapshot.size; }); - }).then(function(numDeleted) { + }).then((numDeleted) => { if (numDeleted < batchSize) { resolve(); return; @@ -384,7 +384,7 @@ describe("firestore", () => { // Recurse on the next process tick, to avoid // exploding the stack. - setTimeout(function() { + setTimeout(() => { deleteQueryBatch(db, query, batchSize, resolve, reject); }, 0); }) @@ -440,10 +440,10 @@ describe("firestore", () => { name: "Tokyo", country: "Japan" }) - .then(function(docRef) { + .then((docRef) => { console.log("Document written with ID: ", docRef.id); }) - .catch(function(error) { + .catch((error) => { console.error("Error adding document: ", error); }); // [END add_document] @@ -470,10 +470,10 @@ describe("firestore", () => { return washingtonRef.update({ capital: true }) - .then(function() { + .then(() => { console.log("Document successfully updated!"); }) - .catch(function(error) { + .catch((error) => { // The document probably doesn't exist. console.error("Error updating document: ", error); }); @@ -510,9 +510,9 @@ describe("firestore", () => { it("should delete a document", () => { var output = // [START delete_document] - db.collection("cities").doc("DC").delete().then(function() { + db.collection("cities").doc("DC").delete().then(() => { console.log("Document successfully deleted!"); - }).catch(function(error) { + }).catch((error) => { console.error("Error removing document: ", error); }); // [END delete_document] @@ -528,9 +528,9 @@ describe("firestore", () => { // Uncomment to initialize the doc. // sfDocRef.set({ population: 0 }); - return db.runTransaction(function(transaction) { + return db.runTransaction((transaction) => { // This code may get re-run multiple times if there are conflicts. - return transaction.get(sfDocRef).then(function(sfDoc) { + return transaction.get(sfDocRef).then((sfDoc) => { if (!sfDoc.exists) { throw "Document does not exist!"; } @@ -541,9 +541,9 @@ describe("firestore", () => { var newPopulation = sfDoc.data().population + 1; transaction.update(sfDocRef, { population: newPopulation }); }); - }).then(function() { + }).then(() => { console.log("Transaction successfully committed!"); - }).catch(function(error) { + }).catch((error) => { console.log("Transaction failed: ", error); }); // [END transaction] @@ -555,8 +555,8 @@ describe("firestore", () => { // Create a reference to the SF doc. var sfDocRef = db.collection("cities").doc("SF"); - db.runTransaction(function(transaction) { - return transaction.get(sfDocRef).then(function(sfDoc) { + db.runTransaction((transaction) => { + return transaction.get(sfDocRef).then((sfDoc) => { if (!sfDoc.exists) { throw "Document does not exist!"; } @@ -569,9 +569,9 @@ describe("firestore", () => { return Promise.reject("Sorry! Population is too big."); } }); - }).then(function(newPopulation) { + }).then((newPopulation) => { console.log("Population increased to ", newPopulation); - }).catch(function(err) { + }).catch((err) => { // This will be an "population is too big" error. console.error(err); }); @@ -582,14 +582,14 @@ describe("firestore", () => { // [START get_document] var docRef = db.collection("cities").doc("SF"); - docRef.get().then(function(doc) { + docRef.get().then((doc) => { if (doc.exists) { console.log("Document data:", doc.data()); } else { // doc.data() will be undefined in this case console.log("No such document!"); } - }).catch(function(error) { + }).catch((error) => { console.log("Error getting document:", error); }); // [END get_document] @@ -607,11 +607,11 @@ describe("firestore", () => { }; // Get a document, forcing the SDK to fetch from the offline cache. - docRef.get(getOptions).then(function(doc) { + docRef.get(getOptions).then((doc) => { // Document was found in the cache. If no cached document exists, // an error will be returned to the 'catch' block below. console.log("Cached document data:", doc.data()); - }).catch(function(error) { + }).catch((error) => { console.log("Error getting cached document:", error); }); // [END get_document_options] @@ -621,12 +621,12 @@ describe("firestore", () => { var unsub = // [START listen_document] db.collection("cities").doc("SF") - .onSnapshot(function(doc) { + .onSnapshot((doc) => { console.log("Current data: ", doc.data()); }); // [END listen_document] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -636,13 +636,13 @@ describe("firestore", () => { var unsub = // [START listen_document_local] db.collection("cities").doc("SF") - .onSnapshot(function(doc) { + .onSnapshot((doc) => { var source = doc.metadata.hasPendingWrites ? "Local" : "Server"; console.log(source, " data: ", doc.data()); }); // [END listen_document_local] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -655,12 +655,12 @@ describe("firestore", () => { .onSnapshot({ // Listen for document metadata changes includeMetadataChanges: true - }, function(doc) { + }, (doc) => { // ... }); // [END listen_with_metadata] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -671,13 +671,13 @@ describe("firestore", () => { // [START get_multiple] db.collection("cities").where("capital", "==", true) .get() - .then(function(querySnapshot) { - querySnapshot.forEach(function(doc) { + .then((querySnapshot) => { + querySnapshot.forEach((doc) => { // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); }); }) - .catch(function(error) { + .catch((error) => { console.log("Error getting documents: ", error); }); // [END get_multiple] @@ -687,8 +687,8 @@ describe("firestore", () => { it("should get all documents from a collection", () => { var output = // [START get_multiple_all] - db.collection("cities").get().then(function(querySnapshot) { - querySnapshot.forEach(function(doc) { + db.collection("cities").get().then((querySnapshot) => { + querySnapshot.forEach((doc) => { // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); }); @@ -701,15 +701,15 @@ describe("firestore", () => { var unsubscribe = // [START listen_multiple] db.collection("cities").where("state", "==", "CA") - .onSnapshot(function(querySnapshot) { + .onSnapshot((querySnapshot) => { var cities = []; - querySnapshot.forEach(function(doc) { + querySnapshot.forEach((doc) => { cities.push(doc.data().name); }); console.log("Current cities in CA: ", cities.join(", ")); }); // [END listen_multiple] - setTimeout(function() { + setTimeout(() => { unsubscribe(); done(); }, 2500); @@ -719,8 +719,8 @@ describe("firestore", () => { var unsubscribe = // [START listen_diffs] db.collection("cities").where("state", "==", "CA") - .onSnapshot(function(snapshot) { - snapshot.docChanges().forEach(function(change) { + .onSnapshot((snapshot) => { + snapshot.docChanges().forEach((change) => { if (change.type === "added") { console.log("New city: ", change.doc.data()); } @@ -733,7 +733,7 @@ describe("firestore", () => { }); }); // [END listen_diffs] - setTimeout(function() { + setTimeout(() => { unsubscribe(); done(); }, 2500); @@ -742,7 +742,7 @@ describe("firestore", () => { it("should unsubscribe a listener", () => { // [START detach_listener] var unsubscribe = db.collection("cities") - .onSnapshot(function (){ + .onSnapshot(() => { // Respond to data // ... }); @@ -758,9 +758,9 @@ describe("firestore", () => { var unsubscribe = // [START handle_listen_errors] db.collection("cities") - .onSnapshot(function(snapshot) { + .onSnapshot((snapshot) => { // ... - }, function(error) { + }, (error) => { // ... }); // [END handle_listen_errors] @@ -803,7 +803,7 @@ describe("firestore", () => { docRef.update({ timestamp: firebase.firestore.FieldValue.serverTimestamp() }); - docRef.onSnapshot(function(snapshot) { + docRef.onSnapshot((snapshot) => { var data = snapshot.data(options); console.log( 'Timestamp: ' + data.timestamp + @@ -984,7 +984,7 @@ describe("firestore", () => { // [START start_doc] var citiesRef = db.collection("cities"); - return citiesRef.doc("SF").get().then(function(doc) { + return citiesRef.doc("SF").get().then((doc) => { // Get all cities with a population bigger than San Francisco var biggerThanSf = citiesRef .orderBy("population") @@ -1017,7 +1017,7 @@ describe("firestore", () => { .orderBy("population") .limit(25); - return first.get().then(function (documentSnapshots) { + return first.get().then((documentSnapshots) => { // Get the last visible document var lastVisible = documentSnapshots.docs[documentSnapshots.docs.length-1]; console.log("last", lastVisible); @@ -1087,8 +1087,8 @@ describe("firestore", () => { it("should query a collection group", () => { // [START fs_collection_group_query] var museums = db.collectionGroup('landmarks').where('type', '==', 'museum'); - museums.get().then(function (querySnapshot) { - querySnapshot.forEach(function (doc) { + museums.get().then((querySnapshot) => { + querySnapshot.forEach((doc) => { console.log(doc.id, ' => ', doc.data()); }); }); diff --git a/snippets/firestore-next/test-firestore/city_custom_object.js b/snippets/firestore-next/test-firestore/city_custom_object.js index 4335d06e..2b9f2c02 100644 --- a/snippets/firestore-next/test-firestore/city_custom_object.js +++ b/snippets/firestore-next/test-firestore/city_custom_object.js @@ -16,15 +16,15 @@ class City { } // Firestore data converter -var cityConverter = { - toFirestore: function(city) { +const cityConverter = { + toFirestore: (city) => { return { name: city.name, state: city.state, country: city.country }; }, - fromFirestore: function(snapshot, options){ + fromFirestore: (snapshot, options) => { const data = snapshot.data(options); return new City(data.name, data.state, data.country); } diff --git a/snippets/firestore-next/test-firestore/delete_collection.js b/snippets/firestore-next/test-firestore/delete_collection.js index d9d6c70a..758e653e 100644 --- a/snippets/firestore-next/test-firestore/delete_collection.js +++ b/snippets/firestore-next/test-firestore/delete_collection.js @@ -13,7 +13,7 @@ import { collection, query, orderBy, limit, getDocs, writeBatch } from "firebase function deleteCollection(db, collectionRef, batchSize) { const q = query(collectionRef, orderBy('__name__'), limit(batchSize)); - return new Promise(function(resolve) { + return new Promise((resolve) => { deleteQueryBatch(db, q, batchSize, resolve); }); } diff --git a/snippets/firestore-next/test-firestore/listen_for_users.js b/snippets/firestore-next/test-firestore/listen_for_users.js index 4a8de4a9..3c42287a 100644 --- a/snippets/firestore-next/test-firestore/listen_for_users.js +++ b/snippets/firestore-next/test-firestore/listen_for_users.js @@ -9,7 +9,7 @@ import { collection, where, query, onSnapshot } from "firebase/firestore"; const q = query(collection(db, "users"), where("born", "<", 1900)); const unsubscribe = onSnapshot(q, (snapshot) => { console.log("Current users born before 1900:"); - snapshot.forEach(function (userSnapshot) { + snapshot.forEach((userSnapshot) => { console.log(userSnapshot.data()); }); }); diff --git a/storage/upload-files.js b/storage/upload-files.js index 988fc3eb..2f889019 100644 --- a/storage/upload-files.js +++ b/storage/upload-files.js @@ -203,7 +203,7 @@ function uploadHandleError(file) { }, () => { // Upload completed successfully, now we can get the download URL - uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) { + uploadTask.snapshot.ref.getDownloadURL().then((downloadURL) => { console.log('File available at', downloadURL); }); } From 22d6b043bbeac62f09a8d2f525be692e479605bb Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 4 Feb 2021 11:00:05 -0800 Subject: [PATCH 088/235] Auto-update dependencies. (#100) Brought to you by your friendly [Repository Gardener](https://github.com/GoogleCloudPlatform/repository-gardener). --- auth/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/package.json b/auth/package.json index 12127fc3..9c757188 100644 --- a/auth/package.json +++ b/auth/package.json @@ -7,6 +7,6 @@ "license": "Apache 2.0", "dependencies": { "firebase": "^8.2.5", - "firebaseui": "^4.7.1" + "firebaseui": "^4.7.3" } } From 0dd7d82bff02c857d5d3d31725a8d81b406ce042 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Sun, 7 Feb 2021 05:16:12 -0800 Subject: [PATCH 089/235] Auto-update dependencies. --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 743db2c2..a55dcc9c 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From d4d41b3067dccd5bd9a08d48793d5cea4910f92f Mon Sep 17 00:00:00 2001 From: DPE bot Date: Sun, 7 Feb 2021 05:16:17 -0800 Subject: [PATCH 090/235] Auto-update dependencies. --- messaging/service-worker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 62d8b30b..37012e93 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.2.5/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.2.5/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.6/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.6/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 25f5a82c6dff073d23692225bf38f4c154831d69 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 8 Feb 2021 01:55:28 -0800 Subject: [PATCH 091/235] Auto-update dependencies. (#102) Co-authored-by: Sam Stern --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 1f7c2809..a0988552 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.5" + "firebase": "^8.2.6" } } diff --git a/auth/package.json b/auth/package.json index 9c757188..16be0875 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.5", + "firebase": "^8.2.6", "firebaseui": "^4.7.3" } } diff --git a/database/package.json b/database/package.json index d1a5c823..5ee62477 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.5" + "firebase": "^8.2.6" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 896fcaff..14c4b5a6 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.5" + "firebase": "^8.2.6" } } diff --git a/firestore/package.json b/firestore/package.json index 4e907d38..c83aec8d 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.5", + "firebase": "^8.2.6", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index ba64715b..b51992ce 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.5" + "firebase": "^8.2.6" } } diff --git a/installations/package.json b/installations/package.json index 42db7bac..52328369 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.5" + "firebase": "^8.2.6" } } diff --git a/messaging/package.json b/messaging/package.json index 11ba5bc7..f7cd38d0 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.5" + "firebase": "^8.2.6" } } diff --git a/perf/package.json b/perf/package.json index 7593b96e..62d1460d 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.5" + "firebase": "^8.2.6" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 21becdc2..a4fe3292 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.5" + "firebase": "^8.2.6" } } diff --git a/storage/package.json b/storage/package.json index 23f2231a..fbb15a0f 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.5" + "firebase": "^8.2.6" } } From 1952112596708e2039a571cd97c838a9cf301f34 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 8 Feb 2021 11:42:24 +0000 Subject: [PATCH 092/235] Add missing storage snippets (#104) --- .../storage-next/index/storage_custom_app.js | 8 ++++++- .../storage-next/index/storage_initialize.js | 2 +- .../index/storage_multiple_buckets.js | 5 ++++- storage-next/index.js | 21 ++++++++++++++++--- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/snippets/storage-next/index/storage_custom_app.js b/snippets/storage-next/index/storage_custom_app.js index 71827148..0c4f26fe 100644 --- a/snippets/storage-next/index/storage_custom_app.js +++ b/snippets/storage-next/index/storage_custom_app.js @@ -4,5 +4,11 @@ // To make edits to the snippets in this file, please edit the source // [START storage_custom_app_modular] -// TODO: Snippet not yet written... +import { getStorage } from "firebase/storage"; + +// Get the default bucket from a custom firebase.app.App +const storage1 = getStorage(customApp); + +// Get a non-default bucket from a custom firebase.app.App +const storage2 = getStorage(customApp, "gs://my-custom-bucket"); // [END storage_custom_app_modular] \ No newline at end of file diff --git a/snippets/storage-next/index/storage_initialize.js b/snippets/storage-next/index/storage_initialize.js index ec69f915..61ad21be 100644 --- a/snippets/storage-next/index/storage_initialize.js +++ b/snippets/storage-next/index/storage_initialize.js @@ -5,7 +5,7 @@ // [START storage_initialize_modular] import { initializeApp } from "firebase/app"; -import { getStorage, uploadBytesResumable } from "firebase/storage"; +import { getStorage } from "firebase/storage"; // Set the configuration for your app // TODO: Replace with your app's config object diff --git a/snippets/storage-next/index/storage_multiple_buckets.js b/snippets/storage-next/index/storage_multiple_buckets.js index 86908130..83c3770e 100644 --- a/snippets/storage-next/index/storage_multiple_buckets.js +++ b/snippets/storage-next/index/storage_multiple_buckets.js @@ -4,5 +4,8 @@ // To make edits to the snippets in this file, please edit the source // [START storage_multiple_buckets_modular] -// TODO: Snippet not yet written... +import { getStorage } from "firebase/storage"; + +// Get a non-default Storage bucket +const storage = getStorage(firebaseApp, "gs://my-custom-bucket"); // [END storage_multiple_buckets_modular] \ No newline at end of file diff --git a/storage-next/index.js b/storage-next/index.js index c5d713cc..1b18b957 100644 --- a/storage-next/index.js +++ b/storage-next/index.js @@ -12,7 +12,7 @@ const firebaseApp = initializeApp({ function initialize() { // [START storage_initialize] const { initializeApp } = require("firebase/app"); - const { getStorage, uploadBytesResumable } = require("firebase/storage"); + const { getStorage } = require("firebase/storage"); // Set the configuration for your app // TODO: Replace with your app's config object @@ -31,13 +31,28 @@ function initialize() { function multipleBuckets() { // [START storage_multiple_buckets] - // TODO: Snippet not yet written... + const { getStorage } = require("firebase/storage"); + + // Get a non-default Storage bucket + const storage = getStorage(firebaseApp, "gs://my-custom-bucket"); // [END storage_multiple_buckets] } function storageCustomApp() { + const { initializeApp } = require("firebase/app"); + + const customApp = initializeApp({ + // ... custom stuff + }); + // [START storage_custom_app] - // TODO: Snippet not yet written... + const { getStorage } = require("firebase/storage"); + + // Get the default bucket from a custom firebase.app.App + const storage1 = getStorage(customApp); + + // Get a non-default bucket from a custom firebase.app.App + const storage2 = getStorage(customApp, "gs://my-custom-bucket"); // [END storage_custom_app] } From a2dc0d922d6321fa8aca4456eb3d0319348b795e Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 12 Feb 2021 03:02:14 -0800 Subject: [PATCH 093/235] Auto-update dependencies. (#105) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index a0988552..b2635d82 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.6" + "firebase": "^8.2.7" } } diff --git a/auth/package.json b/auth/package.json index 16be0875..4aab7e8f 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.6", + "firebase": "^8.2.7", "firebaseui": "^4.7.3" } } diff --git a/database/package.json b/database/package.json index 5ee62477..f7be56cc 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.6" + "firebase": "^8.2.7" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 14c4b5a6..1da0806b 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.6" + "firebase": "^8.2.7" } } diff --git a/firestore/package.json b/firestore/package.json index c83aec8d..a908d40b 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.6", + "firebase": "^8.2.7", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index b51992ce..4933574a 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.6" + "firebase": "^8.2.7" } } diff --git a/installations/package.json b/installations/package.json index 52328369..c0728c77 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.6" + "firebase": "^8.2.7" } } diff --git a/messaging/package.json b/messaging/package.json index f7cd38d0..89c1df76 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.6" + "firebase": "^8.2.7" } } diff --git a/perf/package.json b/perf/package.json index 62d1460d..9f5c5e3b 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.6" + "firebase": "^8.2.7" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index a4fe3292..f4dc706f 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.6" + "firebase": "^8.2.7" } } diff --git a/storage/package.json b/storage/package.json index fbb15a0f..490d15a4 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.6" + "firebase": "^8.2.7" } } From 9bf44f18df2e8ca8f1052676e2e82c80504504d0 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Fri, 12 Feb 2021 05:16:06 -0800 Subject: [PATCH 094/235] Auto-update dependencies. --- firestore/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index a55dcc9c..2b88c6df 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + From 27cf6bf8f026323ae2081612f74c7d3cf2515ce0 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Fri, 12 Feb 2021 05:16:11 -0800 Subject: [PATCH 095/235] Auto-update dependencies. --- messaging/service-worker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 37012e93..682a6c70 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.2.6/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.2.6/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.7/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.7/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 1c8d1145cd8ce9665dacbfa2e7ab06ac8984f3e4 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 15 Feb 2021 11:39:05 +0000 Subject: [PATCH 096/235] Auth emulator snippets (#107) --- auth-next/emulator-suite.js | 20 +++++++++++++++++++ auth/emulator-suite.js | 9 +++++++++ .../emulator-suite/auth_emulator_connect.js | 11 ++++++++++ 3 files changed, 40 insertions(+) create mode 100644 auth-next/emulator-suite.js create mode 100644 auth/emulator-suite.js create mode 100644 snippets/auth-next/emulator-suite/auth_emulator_connect.js diff --git a/auth-next/emulator-suite.js b/auth-next/emulator-suite.js new file mode 100644 index 00000000..aca56cff --- /dev/null +++ b/auth-next/emulator-suite.js @@ -0,0 +1,20 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + projectId: '### PROJECT ID ###', + apiKey: '### FIREBASE API KEY ###', + authDomain: '### FIREBASE AUTH DOMAIN ###', +}); + +function emulatorConnect() { + // [START auth_emulator_connect] + const { getAuth, useAuthEmulator } = require("firebase/auth"); + + const auth = getAuth(firebaseApp); + useAuthEmulator(auth, "http://localhost:9099"); + // [END auth_emulator_connect] +} + diff --git a/auth/emulator-suite.js b/auth/emulator-suite.js new file mode 100644 index 00000000..044795a7 --- /dev/null +++ b/auth/emulator-suite.js @@ -0,0 +1,9 @@ +import firebase from "firebase/app"; +import "firebase/auth"; + +function emulatorConnect() { + // [START auth_emulator_connect] + var auth = firebase.auth(); + auth.useEmulator("http://localhost:9099"); + // [END auth_emulator_connect] +} diff --git a/snippets/auth-next/emulator-suite/auth_emulator_connect.js b/snippets/auth-next/emulator-suite/auth_emulator_connect.js new file mode 100644 index 00000000..e2b805ff --- /dev/null +++ b/snippets/auth-next/emulator-suite/auth_emulator_connect.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/emulator-suite.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_emulator_connect_modular] +import { getAuth, useAuthEmulator } from "firebase/auth"; + +const auth = getAuth(firebaseApp); +useAuthEmulator(auth, "http://localhost:9099"); +// [END auth_emulator_connect_modular] \ No newline at end of file From 3bf1495d864cd50e6cf38b7a674ce8ad3cf0e911 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 15 Feb 2021 11:43:55 +0000 Subject: [PATCH 097/235] Add RTDB offline snippets (#98) --- database-next/offline.js | 121 ++++++++++++++++++ database/offline.js | 95 ++++++++++++++ .../offline/rtdb_detect_connection_state.js | 18 +++ .../offline/rtdb_estimate_clock_skew.js | 15 +++ .../offline/rtdb_ondisconnect_callback.js | 12 ++ .../offline/rtdb_ondisconnect_cancel.js | 11 ++ .../offline/rtdb_ondisconnect_simple.js | 13 ++ .../offline/rtdb_sample_presence_app.js | 34 +++++ .../offline/rtdb_set_server_timestamp.js | 12 ++ 9 files changed, 331 insertions(+) create mode 100644 database-next/offline.js create mode 100644 database/offline.js create mode 100644 snippets/database-next/offline/rtdb_detect_connection_state.js create mode 100644 snippets/database-next/offline/rtdb_estimate_clock_skew.js create mode 100644 snippets/database-next/offline/rtdb_ondisconnect_callback.js create mode 100644 snippets/database-next/offline/rtdb_ondisconnect_cancel.js create mode 100644 snippets/database-next/offline/rtdb_ondisconnect_simple.js create mode 100644 snippets/database-next/offline/rtdb_sample_presence_app.js create mode 100644 snippets/database-next/offline/rtdb_set_server_timestamp.js diff --git a/database-next/offline.js b/database-next/offline.js new file mode 100644 index 00000000..461f3854 --- /dev/null +++ b/database-next/offline.js @@ -0,0 +1,121 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +import { initializeApp } from "firebase/app"; + +const firebaseApp = initializeApp({ + apiKey: '### FIREBASE API KEY ###', + appId: '### FIREBASE APP ID ###', + projectId: '### FIREBASE PROJECT ID ###' +}); + +function onDisconnectSimple() { + // [START rtdb_ondisconnect_simple] + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + const presenceRef = db.ref("disconnectmessage"); + // Write a string when this client loses connection + presenceRef.onDisconnect().set("I disconnected!"); + // [END rtdb_ondisconnect_simple] +} + +function onDisconnectCallback() { + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + const presenceRef = db.ref("disconnectmessage"); + + // [START rtdb_ondisconnect_callback] + presenceRef.onDisconnect().remove((err) => { + if (err) { + console.error("could not establish onDisconnect event", err); + } + }); + // [END rtdb_ondisconnect_callback] +} + +function onDisconnectCancel() { + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + const presenceRef = db.ref("disconnectmessage"); + + // [START rtdb_ondisconnect_cancel] + const onDisconnectRef = presenceRef.onDisconnect(); + onDisconnectRef.set("I disconnected"); + // some time later when we change our minds + onDisconnectRef.cancel(); + // [END rtdb_ondisconnect_cancel] +} + +function detectConnectionState() { + // [START rtdb_detect_connection_state] + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + const connectedRef = db.ref(".info/connected"); + connectedRef.on("value", (snap) => { + if (snap.val() === true) { + console.log("connected"); + } else { + console.log("not connected"); + } + }); + // [END rtdb_detect_connection_state] +} + +function setServerTimestamp() { + // [START rtdb_set_server_timestamp] + const { getDatabase, ServerValue } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + const userLastOnlineRef = db.ref("users/joe/lastOnline"); + userLastOnlineRef.onDisconnect().set(ServerValue.TIMESTAMP); + // [END rtdb_set_server_timestamp] +} + +function estimateClockSkew() { + // [START rtdb_estimate_clock_skew] + const { getDatabase } = require("firebase/database"); + + const db = getDatabase(firebaseApp); + const offsetRef = db.ref(".info/serverTimeOffset"); + offsetRef.on("value", (snap) => { + const offset = snap.val(); + const estimatedServerTimeMs = new Date().getTime() + offset; + }); + // [END rtdb_estimate_clock_skew] +} + +function samplePresenceApp() { + // [START rtdb_sample_presence_app] + const { getDatabase, ServerValue } = require("firebase/database"); + + // Since I can connect from multiple devices or browser tabs, we store each connection instance separately + // any time that connectionsRef's value is null (i.e. has no children) I am offline + const db = getDatabase(firebaseApp); + const myConnectionsRef = db.ref('users/joe/connections'); + + // stores the timestamp of my last disconnect (the last time I was seen online) + const lastOnlineRef = db.ref('users/joe/lastOnline'); + + const connectedRef = db.ref('.info/connected'); + connectedRef.on('value', (snap) => { + if (snap.val() === true) { + // We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect) + const con = myConnectionsRef.push(); + + // When I disconnect, remove this device + con.onDisconnect().remove(); + + // Add this device to my connections list + // this value could contain info about the device or a timestamp too + con.set(true); + + // When I disconnect, update the last time I was seen online + lastOnlineRef.onDisconnect().set(ServerValue.TIMESTAMP); + } + }); + // [END rtdb_sample_presence_app] +} diff --git a/database/offline.js b/database/offline.js new file mode 100644 index 00000000..66df4825 --- /dev/null +++ b/database/offline.js @@ -0,0 +1,95 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/database"; + +function onDisconnectSimple() { + // [START rtdb_ondisconnect_simple] + var presenceRef = firebase.database().ref("disconnectmessage"); + // Write a string when this client loses connection + presenceRef.onDisconnect().set("I disconnected!"); + // [END rtdb_ondisconnect_simple] +} + +function onDisconnectCallback() { + var presenceRef = firebase.database().ref("disconnectmessage"); + + // [START rtdb_ondisconnect_callback] + presenceRef.onDisconnect().remove((err) => { + if (err) { + console.error("could not establish onDisconnect event", err); + } + }); + // [END rtdb_ondisconnect_callback] +} + +function onDisconnectCancel() { + var presenceRef = firebase.database().ref("disconnectmessage"); + + // [START rtdb_ondisconnect_cancel] + var onDisconnectRef = presenceRef.onDisconnect(); + onDisconnectRef.set("I disconnected"); + // some time later when we change our minds + onDisconnectRef.cancel(); + // [END rtdb_ondisconnect_cancel] +} + +function detectConnectionState() { + // [START rtdb_detect_connection_state] + var connectedRef = firebase.database().ref(".info/connected"); + connectedRef.on("value", (snap) => { + if (snap.val() === true) { + console.log("connected"); + } else { + console.log("not connected"); + } + }); + // [END rtdb_detect_connection_state] +} + +function setServerTimestamp() { + // [START rtdb_set_server_timestamp] + var userLastOnlineRef = firebase.database().ref("users/joe/lastOnline"); + userLastOnlineRef.onDisconnect().set(firebase.database.ServerValue.TIMESTAMP); + // [END rtdb_set_server_timestamp] +} + +function estimateClockSkew() { + // [START rtdb_estimate_clock_skew] + var offsetRef = firebase.database().ref(".info/serverTimeOffset"); + offsetRef.on("value", (snap) => { + var offset = snap.val(); + var estimatedServerTimeMs = new Date().getTime() + offset; + }); + // [END rtdb_estimate_clock_skew] +} + +function samplePresenceApp() { + // [START rtdb_sample_presence_app] + // Since I can connect from multiple devices or browser tabs, we store each connection instance separately + // any time that connectionsRef's value is null (i.e. has no children) I am offline + var myConnectionsRef = firebase.database().ref('users/joe/connections'); + + // stores the timestamp of my last disconnect (the last time I was seen online) + var lastOnlineRef = firebase.database().ref('users/joe/lastOnline'); + + var connectedRef = firebase.database().ref('.info/connected'); + connectedRef.on('value', (snap) => { + if (snap.val() === true) { + // We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect) + var con = myConnectionsRef.push(); + + // When I disconnect, remove this device + con.onDisconnect().remove(); + + // Add this device to my connections list + // this value could contain info about the device or a timestamp too + con.set(true); + + // When I disconnect, update the last time I was seen online + lastOnlineRef.onDisconnect().set(firebase.database.ServerValue.TIMESTAMP); + } + }); + // [END rtdb_sample_presence_app] +} diff --git a/snippets/database-next/offline/rtdb_detect_connection_state.js b/snippets/database-next/offline/rtdb_detect_connection_state.js new file mode 100644 index 00000000..3756f5be --- /dev/null +++ b/snippets/database-next/offline/rtdb_detect_connection_state.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./database-next/offline.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_detect_connection_state_modular] +import { getDatabase } from "firebase/database"; + +const db = getDatabase(firebaseApp); +const connectedRef = db.ref(".info/connected"); +connectedRef.on("value", (snap) => { + if (snap.val() === true) { + console.log("connected"); + } else { + console.log("not connected"); + } +}); +// [END rtdb_detect_connection_state_modular] \ No newline at end of file diff --git a/snippets/database-next/offline/rtdb_estimate_clock_skew.js b/snippets/database-next/offline/rtdb_estimate_clock_skew.js new file mode 100644 index 00000000..cdb19491 --- /dev/null +++ b/snippets/database-next/offline/rtdb_estimate_clock_skew.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./database-next/offline.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_estimate_clock_skew_modular] +import { getDatabase } from "firebase/database"; + +const db = getDatabase(firebaseApp); +const offsetRef = db.ref(".info/serverTimeOffset"); +offsetRef.on("value", (snap) => { + const offset = snap.val(); + const estimatedServerTimeMs = new Date().getTime() + offset; +}); +// [END rtdb_estimate_clock_skew_modular] \ No newline at end of file diff --git a/snippets/database-next/offline/rtdb_ondisconnect_callback.js b/snippets/database-next/offline/rtdb_ondisconnect_callback.js new file mode 100644 index 00000000..6af1ee61 --- /dev/null +++ b/snippets/database-next/offline/rtdb_ondisconnect_callback.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./database-next/offline.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_ondisconnect_callback_modular] +presenceRef.onDisconnect().remove((err) => { + if (err) { + console.error("could not establish onDisconnect event", err); + } +}); +// [END rtdb_ondisconnect_callback_modular] \ No newline at end of file diff --git a/snippets/database-next/offline/rtdb_ondisconnect_cancel.js b/snippets/database-next/offline/rtdb_ondisconnect_cancel.js new file mode 100644 index 00000000..7af11312 --- /dev/null +++ b/snippets/database-next/offline/rtdb_ondisconnect_cancel.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./database-next/offline.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_ondisconnect_cancel_modular] +const onDisconnectRef = presenceRef.onDisconnect(); +onDisconnectRef.set("I disconnected"); +// some time later when we change our minds +onDisconnectRef.cancel(); +// [END rtdb_ondisconnect_cancel_modular] \ No newline at end of file diff --git a/snippets/database-next/offline/rtdb_ondisconnect_simple.js b/snippets/database-next/offline/rtdb_ondisconnect_simple.js new file mode 100644 index 00000000..eedfab7f --- /dev/null +++ b/snippets/database-next/offline/rtdb_ondisconnect_simple.js @@ -0,0 +1,13 @@ +// This snippet file was generated by processing the source file: +// ./database-next/offline.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_ondisconnect_simple_modular] +import { getDatabase } from "firebase/database"; + +const db = getDatabase(firebaseApp); +const presenceRef = db.ref("disconnectmessage"); +// Write a string when this client loses connection +presenceRef.onDisconnect().set("I disconnected!"); +// [END rtdb_ondisconnect_simple_modular] \ No newline at end of file diff --git a/snippets/database-next/offline/rtdb_sample_presence_app.js b/snippets/database-next/offline/rtdb_sample_presence_app.js new file mode 100644 index 00000000..bef04145 --- /dev/null +++ b/snippets/database-next/offline/rtdb_sample_presence_app.js @@ -0,0 +1,34 @@ +// This snippet file was generated by processing the source file: +// ./database-next/offline.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_sample_presence_app_modular] +import { getDatabase, ServerValue } from "firebase/database"; + +// Since I can connect from multiple devices or browser tabs, we store each connection instance separately +// any time that connectionsRef's value is null (i.e. has no children) I am offline +const db = getDatabase(firebaseApp); +const myConnectionsRef = db.ref('users/joe/connections'); + +// stores the timestamp of my last disconnect (the last time I was seen online) +const lastOnlineRef = db.ref('users/joe/lastOnline'); + +const connectedRef = db.ref('.info/connected'); +connectedRef.on('value', (snap) => { + if (snap.val() === true) { + // We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect) + const con = myConnectionsRef.push(); + + // When I disconnect, remove this device + con.onDisconnect().remove(); + + // Add this device to my connections list + // this value could contain info about the device or a timestamp too + con.set(true); + + // When I disconnect, update the last time I was seen online + lastOnlineRef.onDisconnect().set(ServerValue.TIMESTAMP); + } +}); +// [END rtdb_sample_presence_app_modular] \ No newline at end of file diff --git a/snippets/database-next/offline/rtdb_set_server_timestamp.js b/snippets/database-next/offline/rtdb_set_server_timestamp.js new file mode 100644 index 00000000..f9319e07 --- /dev/null +++ b/snippets/database-next/offline/rtdb_set_server_timestamp.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./database-next/offline.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_set_server_timestamp_modular] +import { getDatabase, ServerValue } from "firebase/database"; + +const db = getDatabase(firebaseApp); +const userLastOnlineRef = db.ref("users/joe/lastOnline"); +userLastOnlineRef.onDisconnect().set(ServerValue.TIMESTAMP); +// [END rtdb_set_server_timestamp_modular] \ No newline at end of file From e0a7847dd12aad5de015f90f874b92ff7a1f42f6 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Wed, 17 Feb 2021 09:50:39 -0500 Subject: [PATCH 098/235] Disable snippets from the README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 49015f4f..8b6f50ee 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ + # Firebase Web Snippets This repository holds code snippets used in Web documentation From 1e85bf60d95b775c2014e8e6f6760df13aa74172 Mon Sep 17 00:00:00 2001 From: Emmanuel Adeboje <46830860+emmanueldevs@users.noreply.github.com> Date: Wed, 17 Feb 2021 18:28:05 +0100 Subject: [PATCH 099/235] Changed typo error (#108) i just changed out the typo on line 24 --- auth/email.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/email.js b/auth/email.js index cdb4bde3..5520f71c 100644 --- a/auth/email.js +++ b/auth/email.js @@ -21,7 +21,7 @@ function signInWithEmailPassword() { // [END auth_signin_password] } -function signUpWithEmailPasswoerd() { +function signUpWithEmailPassword() { var email = "test@example.com"; var password = "hunter2"; // [START auth_signup_password] From e44ad145efd1aac5459bbb41abe8294aeaa9c904 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 19 Feb 2021 03:01:36 -0800 Subject: [PATCH 100/235] Auto-update dependencies. (#109) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index b2635d82..35916cc7 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.7" + "firebase": "^8.2.8" } } diff --git a/auth/package.json b/auth/package.json index 4aab7e8f..068dbbe0 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.7", + "firebase": "^8.2.8", "firebaseui": "^4.7.3" } } diff --git a/database/package.json b/database/package.json index f7be56cc..17ed84e2 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.7" + "firebase": "^8.2.8" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 1da0806b..8b7d0c89 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.7" + "firebase": "^8.2.8" } } diff --git a/firestore/package.json b/firestore/package.json index a908d40b..f9d92f4f 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.7", + "firebase": "^8.2.8", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 4933574a..192658a6 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.7" + "firebase": "^8.2.8" } } diff --git a/installations/package.json b/installations/package.json index c0728c77..1d757ce5 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.7" + "firebase": "^8.2.8" } } diff --git a/messaging/package.json b/messaging/package.json index 89c1df76..63917f26 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.7" + "firebase": "^8.2.8" } } diff --git a/perf/package.json b/perf/package.json index 9f5c5e3b..bb72a39f 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.7" + "firebase": "^8.2.8" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index f4dc706f..0a000149 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.7" + "firebase": "^8.2.8" } } diff --git a/storage/package.json b/storage/package.json index 490d15a4..bafa0042 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.7" + "firebase": "^8.2.8" } } From be635d5bf29ae2e6dbe655a2bcc0330332c4cbbb Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 19 Feb 2021 05:23:05 -0800 Subject: [PATCH 101/235] Auto-update dependencies. (#110) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 2b88c6df..5e9a73ea 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 682a6c70..3441b999 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.2.7/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.2.7/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.8/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.8/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 174088f73e9ebfa6d8fabe04cbdd1d54d257d9c6 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 22 Feb 2021 02:14:42 -0800 Subject: [PATCH 102/235] Auto-update dependencies. (#112) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 5e9a73ea..a90802c1 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 3441b999..b211b8df 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.2.8/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.2.8/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.9/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 0cb8dac0c5023535b510ebe61e10e727dd598332 Mon Sep 17 00:00:00 2001 From: David East Date: Thu, 25 Feb 2021 15:36:35 -0500 Subject: [PATCH 103/235] Update Firestore Emulator for vNext (#113) * Update Firestore Emulator for vNext * actually run snippets * Fix unknown types for functions --- firestore-next/emulator-suite.js | 13 +++---------- functions-next/callable.js | 8 ++++++-- functions-next/emulator-suite.js | 4 +++- .../emulator-suite/fs_emulator_connect.js | 13 +++---------- .../callable/functions_call_add_message.js | 4 +++- .../callable/functions_call_add_message_error.js | 4 +++- .../emulator-suite/functions_callable_call.js | 4 +++- 7 files changed, 24 insertions(+), 26 deletions(-) diff --git a/firestore-next/emulator-suite.js b/firestore-next/emulator-suite.js index cbcea744..fbbb9599 100644 --- a/firestore-next/emulator-suite.js +++ b/firestore-next/emulator-suite.js @@ -3,17 +3,10 @@ function onDocumentReady(firebaseApp) { // [START fs_emulator_connect] - const { initializeFirestore } = require("firebase/firestore"); - - let settings = {}; - if (location.hostname === "localhost") { - settings = { - host: "localhost:8080", - ssl: false - }; - } + const { getFirestore, useFirestoreEmulator } = require("firebase/firestore"); // firebaseApps previously initialized using initializeApp() - const db = initializeFirestore(firebaseApp, settings); + const db = getFirestore(firebaseApp); + useFirestoreEmulator(db, 'localhost', 8080); // [END fs_emulator_connect] } diff --git a/functions-next/callable.js b/functions-next/callable.js index 193a3c2e..8a8a56ab 100644 --- a/functions-next/callable.js +++ b/functions-next/callable.js @@ -12,7 +12,9 @@ export function callAddMessage(firebaseApp) { addMessage({ text: messageText }) .then((result) => { // Read result of the Cloud Function. - const sanitizedMessage = result.data.text; + /** @type {any} */ + const data = result.data; + const sanitizedMessage = data.text; }); // [END functions_call_add_message] } @@ -28,7 +30,9 @@ export function callAddMessageError(firebaseApp) { addMessage({ text: messageText }) .then((result) => { // Read result of the Cloud Function. - const sanitizedMessage = result.data.text; + /** @type {any} */ + const data = result.data; + const sanitizedMessage = data.text; }) .catch((error) => { // Getting the Error details. diff --git a/functions-next/emulator-suite.js b/functions-next/emulator-suite.js index 48b6c681..8f1fb043 100644 --- a/functions-next/emulator-suite.js +++ b/functions-next/emulator-suite.js @@ -28,7 +28,9 @@ export async function callFunction() { const addMessage = httpsCallable(functions, 'addMessage'); const result = await addMessage({ text: ''}); - const sanitizedMessage = result.data.text; + /** @type {any} */ + const data = result.data; + const sanitizedMessage = data.text; // ... // [END functions_callable_call] } diff --git a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js index 9824a297..f0984d8b 100644 --- a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js +++ b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js @@ -4,16 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START fs_emulator_connect_modular] -import { initializeFirestore } from "firebase/firestore"; - -let settings = {}; -if (location.hostname === "localhost") { - settings = { - host: "localhost:8080", - ssl: false - }; -} +import { getFirestore, useFirestoreEmulator } from "firebase/firestore"; // firebaseApps previously initialized using initializeApp() -const db = initializeFirestore(firebaseApp, settings); +const db = getFirestore(firebaseApp); +useFirestoreEmulator(db, 'localhost', 8080); // [END fs_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/functions-next/callable/functions_call_add_message.js b/snippets/functions-next/callable/functions_call_add_message.js index 7836b85c..a524ce66 100644 --- a/snippets/functions-next/callable/functions_call_add_message.js +++ b/snippets/functions-next/callable/functions_call_add_message.js @@ -11,6 +11,8 @@ const addMessage = httpsCallable(functions, 'addMessage'); addMessage({ text: messageText }) .then((result) => { // Read result of the Cloud Function. - const sanitizedMessage = result.data.text; + /** @type {any} */ + const data = result.data; + const sanitizedMessage = data.text; }); // [END functions_call_add_message_modular] \ No newline at end of file diff --git a/snippets/functions-next/callable/functions_call_add_message_error.js b/snippets/functions-next/callable/functions_call_add_message_error.js index 84d8a381..ee54b65f 100644 --- a/snippets/functions-next/callable/functions_call_add_message_error.js +++ b/snippets/functions-next/callable/functions_call_add_message_error.js @@ -11,7 +11,9 @@ const addMessage = httpsCallable(functions, 'addMessage'); addMessage({ text: messageText }) .then((result) => { // Read result of the Cloud Function. - const sanitizedMessage = result.data.text; + /** @type {any} */ + const data = result.data; + const sanitizedMessage = data.text; }) .catch((error) => { // Getting the Error details. diff --git a/snippets/functions-next/emulator-suite/functions_callable_call.js b/snippets/functions-next/emulator-suite/functions_callable_call.js index 8ac5f8ed..4174cbdf 100644 --- a/snippets/functions-next/emulator-suite/functions_callable_call.js +++ b/snippets/functions-next/emulator-suite/functions_callable_call.js @@ -11,6 +11,8 @@ const functions = getFunctions(getApp()); const addMessage = httpsCallable(functions, 'addMessage'); const result = await addMessage({ text: ''}); -const sanitizedMessage = result.data.text; +/** @type {any} */ +const data = result.data; +const sanitizedMessage = data.text; // ... // [END functions_callable_call_modular] \ No newline at end of file From cd15fbe80f62ee0658d1a5dd35d9754c6733bb87 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 26 Feb 2021 02:25:28 -0800 Subject: [PATCH 104/235] Auto-update dependencies. (#111) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 35916cc7..bb500b45 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.8" + "firebase": "^8.2.9" } } diff --git a/auth/package.json b/auth/package.json index 068dbbe0..7cc909c4 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.8", + "firebase": "^8.2.9", "firebaseui": "^4.7.3" } } diff --git a/database/package.json b/database/package.json index 17ed84e2..42f00040 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.8" + "firebase": "^8.2.9" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 8b7d0c89..3c8bfa2b 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.8" + "firebase": "^8.2.9" } } diff --git a/firestore/package.json b/firestore/package.json index f9d92f4f..c22f8658 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.8", + "firebase": "^8.2.9", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 192658a6..efe52b58 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.8" + "firebase": "^8.2.9" } } diff --git a/installations/package.json b/installations/package.json index 1d757ce5..0e03bf66 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.8" + "firebase": "^8.2.9" } } diff --git a/messaging/package.json b/messaging/package.json index 63917f26..8b31f774 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.8" + "firebase": "^8.2.9" } } diff --git a/perf/package.json b/perf/package.json index bb72a39f..b3d5f11b 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.8" + "firebase": "^8.2.9" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 0a000149..1998fd9f 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.8" + "firebase": "^8.2.9" } } diff --git a/storage/package.json b/storage/package.json index bafa0042..8d950613 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.8" + "firebase": "^8.2.9" } } From 9951802f2817346f113d93ca3bce40535ba804c2 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 5 Mar 2021 03:29:11 -0800 Subject: [PATCH 105/235] Auto-update dependencies. (#115) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index bb500b45..e60e84ae 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.9" + "firebase": "^8.2.10" } } diff --git a/auth/package.json b/auth/package.json index 7cc909c4..103fa2c7 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.9", + "firebase": "^8.2.10", "firebaseui": "^4.7.3" } } diff --git a/database/package.json b/database/package.json index 42f00040..8f7352ef 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.9" + "firebase": "^8.2.10" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 3c8bfa2b..29df45c3 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.9" + "firebase": "^8.2.10" } } diff --git a/firestore/package.json b/firestore/package.json index c22f8658..2e312d95 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.9", + "firebase": "^8.2.10", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index efe52b58..84d634fc 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.9" + "firebase": "^8.2.10" } } diff --git a/installations/package.json b/installations/package.json index 0e03bf66..ffdb6bec 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.9" + "firebase": "^8.2.10" } } diff --git a/messaging/package.json b/messaging/package.json index 8b31f774..7783756f 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.9" + "firebase": "^8.2.10" } } diff --git a/perf/package.json b/perf/package.json index b3d5f11b..b04cbe97 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.9" + "firebase": "^8.2.10" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 1998fd9f..9ed4a646 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.9" + "firebase": "^8.2.10" } } diff --git a/storage/package.json b/storage/package.json index 8d950613..9d206aba 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.9" + "firebase": "^8.2.10" } } From 6667c6eb7ea335ac1e37066c8e170a1ee783e8de Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 5 Mar 2021 05:23:02 -0800 Subject: [PATCH 106/235] Auto-update dependencies. (#116) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index a90802c1..552ee0aa 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index b211b8df..d71a58d4 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.2.9/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.10/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.2.10/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 9b2526407965d21173f810a559a3013f72117813 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Wed, 10 Mar 2021 02:19:39 -0800 Subject: [PATCH 107/235] Auto-update dependencies. (#117) --- auth/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/package.json b/auth/package.json index 103fa2c7..1b1648ad 100644 --- a/auth/package.json +++ b/auth/package.json @@ -7,6 +7,6 @@ "license": "Apache 2.0", "dependencies": { "firebase": "^8.2.10", - "firebaseui": "^4.7.3" + "firebaseui": "^4.8.0" } } From 2ab4c978ce9b0672d0833f46c6cd5a057efea23c Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 11 Mar 2021 02:46:22 -0800 Subject: [PATCH 108/235] Auto-update dependencies. (#118) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index e60e84ae..59f26bdc 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.10" + "firebase": "^8.3.0" } } diff --git a/auth/package.json b/auth/package.json index 1b1648ad..325eb14e 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.10", + "firebase": "^8.3.0", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index 8f7352ef..4ee9aef2 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.10" + "firebase": "^8.3.0" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 29df45c3..5717d947 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.10" + "firebase": "^8.3.0" } } diff --git a/firestore/package.json b/firestore/package.json index 2e312d95..11dd0ac4 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.10", + "firebase": "^8.3.0", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 84d634fc..4e5cf591 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.10" + "firebase": "^8.3.0" } } diff --git a/installations/package.json b/installations/package.json index ffdb6bec..68aa047e 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.2.10" + "firebase": "^8.3.0" } } diff --git a/messaging/package.json b/messaging/package.json index 7783756f..1a61fafe 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.10" + "firebase": "^8.3.0" } } diff --git a/perf/package.json b/perf/package.json index b04cbe97..45b1bdc2 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.10" + "firebase": "^8.3.0" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 9ed4a646..c13fe2c6 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.10" + "firebase": "^8.3.0" } } diff --git a/storage/package.json b/storage/package.json index 9d206aba..8bcd5013 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.2.10" + "firebase": "^8.3.0" } } From 3f94f3a87fe1e522eca95632c9725c8cdcc5810e Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 11 Mar 2021 05:19:03 -0800 Subject: [PATCH 109/235] Auto-update dependencies. (#119) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 552ee0aa..174f14bd 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index d71a58d4..d1869db6 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.2.10/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.2.10/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.3.0/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.3.0/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From a9ac6e6628816293e850eafa6c994a7b9d4d5831 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 12 Mar 2021 10:40:35 -0500 Subject: [PATCH 110/235] Add Firestore bundles snippets (#120) --- firestore-next/test.solution-bundles.js | 50 +++++++++++++++++++ firestore/test.solution-bundles.js | 48 ++++++++++++++++++ .../test-solution-bundles/fs_bundle_load.js | 24 +++++++++ 3 files changed, 122 insertions(+) create mode 100644 firestore-next/test.solution-bundles.js create mode 100644 firestore/test.solution-bundles.js create mode 100644 snippets/firestore-next/test-solution-bundles/fs_bundle_load.js diff --git a/firestore-next/test.solution-bundles.js b/firestore-next/test.solution-bundles.js new file mode 100644 index 00000000..400aeeb8 --- /dev/null +++ b/firestore-next/test.solution-bundles.js @@ -0,0 +1,50 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +const { FirebaseFirestore } = require('firebase/firestore'); + +/** + * @type FirebaseFirestore + */ +var db; + +// [START fs_bundle_load] +const { loadBundle, namedQuery, getDocsFromCache } = require("firebase/firestore"); + +async function fetchFromBundle() { + // Fetch the bundle from Firebase Hosting, if the CDN cache is hit the 'X-Cache' + // response header will be set to 'HIT' + const resp = await fetch('/createBundle'); + + // Load the bundle contents into the Firestore SDK + await loadBundle(db, resp.body); + + // Query the results from the cache + const query = await namedQuery(db, 'latest-stories-query'); + const storiesSnap = await getDocsFromCache(query); + + // Use the results + // ... +} +// [END fs_bundle_load] + +describe("firestore-solution-bundles", () => { + before(() => { + const { initializeApp } = require("firebase/app"); + const { getFirestore} = require("firebase/firestore"); + + const config = { + apiKey: "AIzaSyArvVh6VSdXicubcvIyuB-GZs8ua0m0DTI", + authDomain: "firestorequickstarts.firebaseapp.com", + projectId: "firestorequickstarts", + }; + const app = initializeApp(config, "solution-bundles"); + db = getFirestore(app); + }); + + describe("solution-bundles", () => { + it("should fetch a bundle", (done) => { + fetchFromBundle().finally(done); + }); + }); +}); diff --git a/firestore/test.solution-bundles.js b/firestore/test.solution-bundles.js new file mode 100644 index 00000000..4bece2c8 --- /dev/null +++ b/firestore/test.solution-bundles.js @@ -0,0 +1,48 @@ +// [START fs_bundle_load] +// If you are using module bundlers. +import firebase from "firebase/app"; +import "firebase/firestore"; +import "firebase/firestore/bundle"; // This line enables bundle loading as a side effect. + +// [START_EXCLUDE] +/** + * @type firebase.firestore.Firestore + */ +var db; +// [END_EXCLUDE] + +async function fetchFromBundle() { + // Fetch the bundle from Firebase Hosting, if the CDN cache is hit the 'X-Cache' + // response header will be set to 'HIT' + const resp = await fetch('/createBundle'); + + // Load the bundle contents into the Firestore SDK + await db.loadBundle(resp.body); + + // Query the results from the cache + // Note: omitting "source: cache" will query the Firestore backend. + const query = await db.namedQuery('latest-stories-query'); + const storiesSnap = await query.get({ source: 'cache' }); + + // Use the results + // ... +} +// [END fs_bundle_load] + +describe("firestore-solution-bundles", () => { + before(() => { + var config = { + apiKey: "AIzaSyArvVh6VSdXicubcvIyuB-GZs8ua0m0DTI", + authDomain: "firestorequickstarts.firebaseapp.com", + projectId: "firestorequickstarts", + }; + var app = firebase.initializeApp(config, "solution-bundles"); + db = firebase.firestore(app); + }); + + describe("solution-bundles", () => { + it("should fetch a bundle", (done) => { + fetchFromBundle().finally(done); + }); + }); +}); diff --git a/snippets/firestore-next/test-solution-bundles/fs_bundle_load.js b/snippets/firestore-next/test-solution-bundles/fs_bundle_load.js new file mode 100644 index 00000000..9aa8f430 --- /dev/null +++ b/snippets/firestore-next/test-solution-bundles/fs_bundle_load.js @@ -0,0 +1,24 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.solution-bundles.js +// +// To make edits to the snippets in this file, please edit the source + +// [START fs_bundle_load_modular] +import { loadBundle, namedQuery, getDocsFromCache } from "firebase/firestore"; + +async function fetchFromBundle() { + // Fetch the bundle from Firebase Hosting, if the CDN cache is hit the 'X-Cache' + // response header will be set to 'HIT' + const resp = await fetch('/createBundle'); + + // Load the bundle contents into the Firestore SDK + await loadBundle(db, resp.body); + + // Query the results from the cache + const query = await namedQuery(db, 'latest-stories-query'); + const storiesSnap = await getDocsFromCache(query); + + // Use the results + // ... +} +// [END fs_bundle_load_modular] \ No newline at end of file From 8d7c2207f6f1ff8a767d070f1d690c5627c07094 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 19 Mar 2021 04:02:42 -0700 Subject: [PATCH 111/235] Auto-update dependencies. (#124) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 59f26bdc..5db47115 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.0" + "firebase": "^8.3.1" } } diff --git a/auth/package.json b/auth/package.json index 325eb14e..4fbd49df 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.0", + "firebase": "^8.3.1", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index 4ee9aef2..90bf52ee 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.0" + "firebase": "^8.3.1" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 5717d947..e6e46207 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.0" + "firebase": "^8.3.1" } } diff --git a/firestore/package.json b/firestore/package.json index 11dd0ac4..7b7b880d 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.0", + "firebase": "^8.3.1", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 4e5cf591..7a96e04c 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.0" + "firebase": "^8.3.1" } } diff --git a/installations/package.json b/installations/package.json index 68aa047e..216dd060 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.0" + "firebase": "^8.3.1" } } diff --git a/messaging/package.json b/messaging/package.json index 1a61fafe..9b1a8c91 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.0" + "firebase": "^8.3.1" } } diff --git a/perf/package.json b/perf/package.json index 45b1bdc2..9099a7dc 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.0" + "firebase": "^8.3.1" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index c13fe2c6..3a713b76 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.0" + "firebase": "^8.3.1" } } diff --git a/storage/package.json b/storage/package.json index 8bcd5013..f134a6c7 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.0" + "firebase": "^8.3.1" } } From 206ed040feb7f76fd5332cdc8e006c4443884964 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 19 Mar 2021 05:17:48 -0700 Subject: [PATCH 112/235] Auto-update dependencies. (#125) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 174f14bd..11d4c84f 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index d1869db6..7589f6f6 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.3.0/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.3.0/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.3.1/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.3.1/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From ae35741af1fa521de7b3afcd122e694b1e5766ba Mon Sep 17 00:00:00 2001 From: Grant Timmerman <744973+grant@users.noreply.github.com> Date: Tue, 23 Mar 2021 10:23:02 -0500 Subject: [PATCH 113/235] docs: update region tag prefix to fb_functions_ (#127) --- functions-next/callable.js | 8 ++++---- functions-next/emulator-suite.js | 8 ++++---- functions/callable.js | 8 ++++---- functions/emulator-suite.js | 4 ++-- ...ll_add_message.js => fb_functions_call_add_message.js} | 4 ++-- ...ge_error.js => fb_functions_call_add_message_error.js} | 4 ++-- ...ons_callable_call.js => fb_functions_callable_call.js} | 4 ++-- ...ulator_connect.js => fb_functions_emulator_connect.js} | 4 ++-- 8 files changed, 22 insertions(+), 22 deletions(-) rename snippets/functions-next/callable/{functions_call_add_message.js => fb_functions_call_add_message.js} (85%) rename snippets/functions-next/callable/{functions_call_add_message_error.js => fb_functions_call_add_message_error.js} (86%) rename snippets/functions-next/emulator-suite/{functions_callable_call.js => fb_functions_callable_call.js} (85%) rename snippets/functions-next/emulator-suite/{functions_emulator_connect.js => fb_functions_emulator_connect.js} (80%) diff --git a/functions-next/callable.js b/functions-next/callable.js index 8a8a56ab..4b866cd3 100644 --- a/functions-next/callable.js +++ b/functions-next/callable.js @@ -4,7 +4,7 @@ export function callAddMessage(firebaseApp) { const messageText = "Hello, World!"; - // [START functions_call_add_message] + // [START fb_functions_call_add_message] const { getFunctions, httpsCallable } = require("firebase/functions"); const functions = getFunctions(firebaseApp); @@ -16,13 +16,13 @@ export function callAddMessage(firebaseApp) { const data = result.data; const sanitizedMessage = data.text; }); - // [END functions_call_add_message] + // [END fb_functions_call_add_message] } export function callAddMessageError(firebaseApp) { const messageText = "Hello, World!"; - // [START functions_call_add_message_error] + // [START fb_functions_call_add_message_error] const { getFunctions, httpsCallable } = require("firebase/functions"); const functions = getFunctions(firebaseApp); @@ -41,5 +41,5 @@ export function callAddMessageError(firebaseApp) { const details = error.details; // ... }); - // [END functions_call_add_message_error] + // [END fb_functions_call_add_message_error] } diff --git a/functions-next/emulator-suite.js b/functions-next/emulator-suite.js index 8f1fb043..1f519a2e 100644 --- a/functions-next/emulator-suite.js +++ b/functions-next/emulator-suite.js @@ -10,17 +10,17 @@ initializeApp({ }); export function emulatorSettings() { - // [START functions_emulator_connect] + // [START fb_functions_emulator_connect] const { getApp } = require("firebase/app"); const { getFunctions, useFunctionsEmulator } = require("firebase/functions"); const functions = getFunctions(getApp()); useFunctionsEmulator(functions, "localhost", 5001); - // [END functions_emulator_connect] + // [END fb_functions_emulator_connect] } export async function callFunction() { - // [START functions_callable_call] + // [START fb_functions_callable_call] const { getApp } = require("firebase/app"); const { getFunctions, httpsCallable } = require("firebase/functions"); @@ -32,5 +32,5 @@ export async function callFunction() { const data = result.data; const sanitizedMessage = data.text; // ... - // [END functions_callable_call] + // [END fb_functions_callable_call] } diff --git a/functions/callable.js b/functions/callable.js index 5cb6a515..2b605ae1 100644 --- a/functions/callable.js +++ b/functions/callable.js @@ -4,20 +4,20 @@ import "firebase/functions"; function callAddMessage() { const messageText = "Hello, World!"; - // [START functions_call_add_message] + // [START fb_functions_call_add_message] var addMessage = firebase.functions().httpsCallable('addMessage'); addMessage({ text: messageText }) .then((result) => { // Read result of the Cloud Function. var sanitizedMessage = result.data.text; }); - // [END functions_call_add_message] + // [END fb_functions_call_add_message] } function callAddMessageError() { const messageText = "Hello, World!"; - // [START functions_call_add_message_error] + // [START fb_functions_call_add_message_error] var addMessage = firebase.functions().httpsCallable('addMessage'); addMessage({ text: messageText }) .then((result) => { @@ -31,5 +31,5 @@ function callAddMessageError() { var details = error.details; // ... }); - // [END functions_call_add_message_error] + // [END fb_functions_call_add_message_error] } diff --git a/functions/emulator-suite.js b/functions/emulator-suite.js index e2c244ca..a9cdc7d7 100644 --- a/functions/emulator-suite.js +++ b/functions/emulator-suite.js @@ -2,7 +2,7 @@ import firebase from "firebase/app"; import "firebase/functions"; function emulatorSettings() { - // [START functions_emulator_connect] + // [START fb_functions_emulator_connect] firebase.functions().useEmulator("localhost", 5001); - // [END functions_emulator_connect] + // [END fb_functions_emulator_connect] } diff --git a/snippets/functions-next/callable/functions_call_add_message.js b/snippets/functions-next/callable/fb_functions_call_add_message.js similarity index 85% rename from snippets/functions-next/callable/functions_call_add_message.js rename to snippets/functions-next/callable/fb_functions_call_add_message.js index a524ce66..c2e1b34f 100644 --- a/snippets/functions-next/callable/functions_call_add_message.js +++ b/snippets/functions-next/callable/fb_functions_call_add_message.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START functions_call_add_message_modular] +// [START fb_functions_call_add_message_modular] import { getFunctions, httpsCallable } from "firebase/functions"; const functions = getFunctions(firebaseApp); @@ -15,4 +15,4 @@ addMessage({ text: messageText }) const data = result.data; const sanitizedMessage = data.text; }); -// [END functions_call_add_message_modular] \ No newline at end of file +// [END fb_functions_call_add_message_modular] \ No newline at end of file diff --git a/snippets/functions-next/callable/functions_call_add_message_error.js b/snippets/functions-next/callable/fb_functions_call_add_message_error.js similarity index 86% rename from snippets/functions-next/callable/functions_call_add_message_error.js rename to snippets/functions-next/callable/fb_functions_call_add_message_error.js index ee54b65f..e5186ea9 100644 --- a/snippets/functions-next/callable/functions_call_add_message_error.js +++ b/snippets/functions-next/callable/fb_functions_call_add_message_error.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START functions_call_add_message_error_modular] +// [START fb_functions_call_add_message_error_modular] import { getFunctions, httpsCallable } from "firebase/functions"; const functions = getFunctions(firebaseApp); @@ -22,4 +22,4 @@ addMessage({ text: messageText }) const details = error.details; // ... }); -// [END functions_call_add_message_error_modular] \ No newline at end of file +// [END fb_functions_call_add_message_error_modular] \ No newline at end of file diff --git a/snippets/functions-next/emulator-suite/functions_callable_call.js b/snippets/functions-next/emulator-suite/fb_functions_callable_call.js similarity index 85% rename from snippets/functions-next/emulator-suite/functions_callable_call.js rename to snippets/functions-next/emulator-suite/fb_functions_callable_call.js index 4174cbdf..2619806b 100644 --- a/snippets/functions-next/emulator-suite/functions_callable_call.js +++ b/snippets/functions-next/emulator-suite/fb_functions_callable_call.js @@ -3,7 +3,7 @@ // // To make edits to the snippets in this file, please edit the source -// [START functions_callable_call_modular] +// [START fb_functions_callable_call_modular] import { getApp } from "firebase/app"; import { getFunctions, httpsCallable } from "firebase/functions"; @@ -15,4 +15,4 @@ const result = await addMessage({ text: ''}); const data = result.data; const sanitizedMessage = data.text; // ... -// [END functions_callable_call_modular] \ No newline at end of file +// [END fb_functions_callable_call_modular] \ No newline at end of file diff --git a/snippets/functions-next/emulator-suite/functions_emulator_connect.js b/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js similarity index 80% rename from snippets/functions-next/emulator-suite/functions_emulator_connect.js rename to snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js index e9d5fead..62fc3dd2 100644 --- a/snippets/functions-next/emulator-suite/functions_emulator_connect.js +++ b/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js @@ -3,10 +3,10 @@ // // To make edits to the snippets in this file, please edit the source -// [START functions_emulator_connect_modular] +// [START fb_functions_emulator_connect_modular] import { getApp } from "firebase/app"; import { getFunctions, useFunctionsEmulator } from "firebase/functions"; const functions = getFunctions(getApp()); useFunctionsEmulator(functions, "localhost", 5001); -// [END functions_emulator_connect_modular] \ No newline at end of file +// [END fb_functions_emulator_connect_modular] \ No newline at end of file From c93b4a40600b0615b72f54d0d585d0a6cd4a0b9d Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 1 Apr 2021 02:32:01 -0700 Subject: [PATCH 114/235] Auto-update dependencies. (#128) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 5db47115..2f87eaf0 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.1" + "firebase": "^8.3.2" } } diff --git a/auth/package.json b/auth/package.json index 4fbd49df..77a36fd2 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.1", + "firebase": "^8.3.2", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index 90bf52ee..ab6ad90d 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.1" + "firebase": "^8.3.2" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index e6e46207..caa83383 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.1" + "firebase": "^8.3.2" } } diff --git a/firestore/package.json b/firestore/package.json index 7b7b880d..806fdb30 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.1", + "firebase": "^8.3.2", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 7a96e04c..9cda8101 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.1" + "firebase": "^8.3.2" } } diff --git a/installations/package.json b/installations/package.json index 216dd060..1d2f4cec 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.1" + "firebase": "^8.3.2" } } diff --git a/messaging/package.json b/messaging/package.json index 9b1a8c91..8a389487 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.1" + "firebase": "^8.3.2" } } diff --git a/perf/package.json b/perf/package.json index 9099a7dc..7d14e302 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.1" + "firebase": "^8.3.2" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 3a713b76..251d1f2f 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.1" + "firebase": "^8.3.2" } } diff --git a/storage/package.json b/storage/package.json index f134a6c7..2e146416 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.1" + "firebase": "^8.3.2" } } From f61ee63d407f4a71ef9e677284c292b0a083d723 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 1 Apr 2021 05:27:04 -0700 Subject: [PATCH 115/235] Auto-update dependencies. (#129) * Auto-update dependencies. * Auto-update dependencies. --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 11d4c84f..c74ad8de 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 7589f6f6..9392cc13 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.3.1/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.3.1/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.3.2/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.3.2/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From e70c313cb393a23892ba1dd346c4505ea2637cec Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 9 Apr 2021 06:33:41 -0400 Subject: [PATCH 116/235] Update RTDB snippets to new API (#132) --- database-next/emulator-suite.js | 8 +-- database-next/lists-of-data.js | 38 ++++++------ database-next/offline.js | 54 ++++++++--------- database-next/read-and-write.js | 60 ++++++++++--------- .../emulator-suite/rtdb_emulator_connect.js | 4 +- .../emulator-suite/rtdb_emulator_flush.js | 4 +- .../rtdb_social_listen_children.js | 10 ++-- .../lists-of-data/rtdb_social_listen_value.js | 8 ++- .../lists-of-data/rtdb_social_most_starred.js | 4 +- .../lists-of-data/rtdb_social_most_viewed.js | 4 +- .../lists-of-data/rtdb_social_push.js | 8 +-- .../lists-of-data/rtdb_social_recent.js | 4 +- .../offline/rtdb_detect_connection_state.js | 6 +- .../offline/rtdb_estimate_clock_skew.js | 6 +- .../offline/rtdb_ondisconnect_callback.js | 2 +- .../offline/rtdb_ondisconnect_cancel.js | 2 +- .../offline/rtdb_ondisconnect_simple.js | 6 +- .../offline/rtdb_sample_presence_app.js | 18 +++--- .../offline/rtdb_set_server_timestamp.js | 6 +- .../rtdb_social_completion_callback.js | 16 ++--- .../rtdb_social_listen_star_count.js | 6 +- .../rtdb_social_single_value_read.js | 6 +- .../rtdb_social_star_transaction.js | 6 +- .../rtdb_social_write_fan_out.js | 4 +- .../read-and-write/rtdb_write_new_user.js | 4 +- .../rtdb_write_new_user_completion.js | 16 ++--- 26 files changed, 159 insertions(+), 151 deletions(-) diff --git a/database-next/emulator-suite.js b/database-next/emulator-suite.js index cdcf4896..c19f6829 100644 --- a/database-next/emulator-suite.js +++ b/database-next/emulator-suite.js @@ -11,22 +11,22 @@ const firebaseApp = initializeApp({ function onDocumentReady() { // [START rtdb_emulator_connect] - const { getDatabase } = require("firebase/database"); + const { getDatabase, useDatabaseEmulator } = require("firebase/database"); const db = getDatabase(firebaseApp); if (location.hostname === "localhost") { // Point to the RTDB emulator running on localhost. - db.useEmulator("localhost", 9000); + useDatabaseEmulator(db, "localhost", 9000); } // [END rtdb_emulator_connect] } function flushRealtimeDatabase() { // [START rtdb_emulator_flush] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, set } = require("firebase/database"); // With a database Reference, write null to clear the database. const db = getDatabase(firebaseApp); - db.ref().set(null); + set(ref(db), null); // [END rtdb_emulator_flush] } diff --git a/database-next/lists-of-data.js b/database-next/lists-of-data.js index b19371e4..8e47c1dd 100644 --- a/database-next/lists-of-data.js +++ b/database-next/lists-of-data.js @@ -11,13 +11,13 @@ const firebaseApp = initializeApp({ function socialPush() { // [START rtdb_social_push] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, push, set } = require("firebase/database"); // Create a new post reference with an auto-generated id const db = getDatabase(firebaseApp); - const postListRef = db.ref('posts'); - const newPostRef = postListRef.push(); - newPostRef.set({ + const postListRef = ref(db, 'posts'); + const newPostRef = push(postListRef); + set(newPostRef, { // ... }); // [END rtdb_social_push] @@ -31,19 +31,19 @@ function socialListenChildren() { function deleteComment(el, key) {}; // [START rtdb_social_listen_children] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, onChildAdded, onChildChanged, onChildRemoved } = require("firebase/database"); const db = getDatabase(firebaseApp); - const commentsRef = db.ref('post-comments/' + postId); - commentsRef.on('child_added', (data) => { + const commentsRef = ref(db, 'post-comments/' + postId); + onChildAdded(commentsRef, (data) => { addCommentElement(postElement, data.key, data.val().text, data.val().author); }); - commentsRef.on('child_changed', (data) => { + onChildChanged(commentsRef, (data) => { setCommentValues(postElement, data.key, data.val().text, data.val().author); }); - commentsRef.on('child_removed', (data) => { + onChildRemoved(commentsRef, (data) => { deleteComment(postElement, data.key); }); // [END rtdb_social_listen_children] @@ -52,48 +52,50 @@ function socialListenChildren() { function socialListenValue() { // [START rtdb_social_listen_value] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, onValue } = require("firebase/database"); const db = getDatabase(firebaseApp); - const ref = db.ref('/a/b/c'); + const dbRef = ref(db, '/a/b/c'); - ref.once('value', (snapshot) => { + onValue(dbRef, (snapshot) => { snapshot.forEach((childSnapshot) => { const childKey = childSnapshot.key; const childData = childSnapshot.val(); // ... }); + }, { + onlyOnce: true }); // [END rtdb_social_listen_value] } function socialMostStarred() { // [START rtdb_social_most_starred] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, query, orderByChild } = require("firebase/database"); const { getAuth } = require("firebase/auth"); const db = getDatabase(firebaseApp); const auth = getAuth(firebaseApp); const myUserId = auth.currentUser.uid; - const topUserPostsRef = db.ref('user-posts/' + myUserId).orderByChild('starCount'); + const topUserPostsRef = query(ref(db, 'user-posts/' + myUserId), orderByChild('starCount')); // [END rtdb_social_most_starred] } function socialMostViewed() { // [START rtdb_social_most_viewed] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, query, orderByChild } = require("firebase/database"); const db = getDatabase(firebaseApp); - const mostViewedPosts = db.ref('posts').orderByChild('metrics/views'); + const mostViewedPosts = query(ref(db, 'posts'), orderByChild('metrics/views')); // [END rtdb_social_most_viewed] } function socialRecent() { // [START rtdb_social_recent] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, query, limitToLast } = require("firebase/database"); const db = getDatabase(firebaseApp); - const recentPostsRef = db.ref('posts').limitToLast(100); + const recentPostsRef = query(ref(db, 'posts'), limitToLast(100)); // [END rtdb_social_recent] } diff --git a/database-next/offline.js b/database-next/offline.js index 461f3854..49009268 100644 --- a/database-next/offline.js +++ b/database-next/offline.js @@ -11,23 +11,23 @@ const firebaseApp = initializeApp({ function onDisconnectSimple() { // [START rtdb_ondisconnect_simple] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, onDisconnect } = require("firebase/database"); const db = getDatabase(firebaseApp); - const presenceRef = db.ref("disconnectmessage"); + const presenceRef = ref(db, "disconnectmessage"); // Write a string when this client loses connection - presenceRef.onDisconnect().set("I disconnected!"); + onDisconnect(presenceRef).set("I disconnected!"); // [END rtdb_ondisconnect_simple] } function onDisconnectCallback() { - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, onDisconnect } = require("firebase/database"); const db = getDatabase(firebaseApp); - const presenceRef = db.ref("disconnectmessage"); + const presenceRef = ref(db, "disconnectmessage"); // [START rtdb_ondisconnect_callback] - presenceRef.onDisconnect().remove((err) => { + onDisconnect(presenceRef).remove().catch((err) => { if (err) { console.error("could not establish onDisconnect event", err); } @@ -36,13 +36,13 @@ function onDisconnectCallback() { } function onDisconnectCancel() { - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, onDisconnect } = require("firebase/database"); const db = getDatabase(firebaseApp); - const presenceRef = db.ref("disconnectmessage"); + const presenceRef = ref(db, "disconnectmessage"); // [START rtdb_ondisconnect_cancel] - const onDisconnectRef = presenceRef.onDisconnect(); + const onDisconnectRef = onDisconnect(presenceRef); onDisconnectRef.set("I disconnected"); // some time later when we change our minds onDisconnectRef.cancel(); @@ -51,11 +51,11 @@ function onDisconnectCancel() { function detectConnectionState() { // [START rtdb_detect_connection_state] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, onValue } = require("firebase/database"); const db = getDatabase(firebaseApp); - const connectedRef = db.ref(".info/connected"); - connectedRef.on("value", (snap) => { + const connectedRef = ref(db, ".info/connected"); + onValue(connectedRef, (snap) => { if (snap.val() === true) { console.log("connected"); } else { @@ -67,21 +67,21 @@ function detectConnectionState() { function setServerTimestamp() { // [START rtdb_set_server_timestamp] - const { getDatabase, ServerValue } = require("firebase/database"); + const { getDatabase, ref, onDisconnect, serverTimestamp } = require("firebase/database"); const db = getDatabase(firebaseApp); - const userLastOnlineRef = db.ref("users/joe/lastOnline"); - userLastOnlineRef.onDisconnect().set(ServerValue.TIMESTAMP); + const userLastOnlineRef = ref(db, "users/joe/lastOnline"); + onDisconnect(userLastOnlineRef).set(serverTimestamp()); // [END rtdb_set_server_timestamp] } function estimateClockSkew() { // [START rtdb_estimate_clock_skew] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, onValue } = require("firebase/database"); const db = getDatabase(firebaseApp); - const offsetRef = db.ref(".info/serverTimeOffset"); - offsetRef.on("value", (snap) => { + const offsetRef = ref(db, ".info/serverTimeOffset"); + onValue(offsetRef, (snap) => { const offset = snap.val(); const estimatedServerTimeMs = new Date().getTime() + offset; }); @@ -90,31 +90,31 @@ function estimateClockSkew() { function samplePresenceApp() { // [START rtdb_sample_presence_app] - const { getDatabase, ServerValue } = require("firebase/database"); + const { getDatabase, ref, onValue, push, onDisconnect, set, serverTimestamp } = require("firebase/database"); // Since I can connect from multiple devices or browser tabs, we store each connection instance separately // any time that connectionsRef's value is null (i.e. has no children) I am offline const db = getDatabase(firebaseApp); - const myConnectionsRef = db.ref('users/joe/connections'); + const myConnectionsRef = ref(db, 'users/joe/connections'); // stores the timestamp of my last disconnect (the last time I was seen online) - const lastOnlineRef = db.ref('users/joe/lastOnline'); + const lastOnlineRef = ref(db, 'users/joe/lastOnline'); - const connectedRef = db.ref('.info/connected'); - connectedRef.on('value', (snap) => { + const connectedRef = ref(db, '.info/connected'); + onValue(connectedRef, (snap) => { if (snap.val() === true) { // We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect) - const con = myConnectionsRef.push(); + const con = push(myConnectionsRef); // When I disconnect, remove this device - con.onDisconnect().remove(); + onDisconnect(con).remove(); // Add this device to my connections list // this value could contain info about the device or a timestamp too - con.set(true); + set(con, true); // When I disconnect, update the last time I was seen online - lastOnlineRef.onDisconnect().set(ServerValue.TIMESTAMP); + onDisconnect(lastOnlineRef).set(serverTimestamp()); } }); // [END rtdb_sample_presence_app] diff --git a/database-next/read-and-write.js b/database-next/read-and-write.js index 6d890183..6e3ac273 100644 --- a/database-next/read-and-write.js +++ b/database-next/read-and-write.js @@ -11,11 +11,11 @@ const firebaseApp = initializeApp({ function writeUserData_wrapped() { // [START rtdb_write_new_user] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, set} = require("firebase/database"); function writeUserData(userId, name, email, imageUrl) { const db = getDatabase(firebaseApp); - db.ref('users/' + userId).set({ + set(ref(db, 'users/' + userId), { username: name, email: email, profile_picture : imageUrl @@ -27,19 +27,19 @@ function writeUserData_wrapped() { function writeUserDataWithCompletion(userId, name, email, imageUrl) { // [START rtdb_write_new_user_completion] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, set } = require("firebase/database"); const db = getDatabase(firebaseApp); - db.ref('users/' + userId).set({ + set(ref(db, 'users/' + userId), { username: name, email: email, profile_picture : imageUrl - }, (error) => { - if (error) { - // The write failed... - } else { - // Data saved successfully! - } + }) + .then(() => { + // Data saved successfully! + }) + .catch((error) => { + // The write failed... }); // [END rtdb_write_new_user_completion] } @@ -52,11 +52,11 @@ function socialListenStarCount() { } // [START rtdb_social_listen_star_count] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, onValue} = require("firebase/database"); const db = getDatabase(firebaseApp); - const starCountRef = db.ref('posts/' + postId + '/starCount'); - starCountRef.on('value', (snapshot) => { + const starCountRef = ref(db, 'posts/' + postId + '/starCount'); + onValue(starCountRef, (snapshot) => { const data = snapshot.val(); updateStarCount(postElement, data); }); @@ -65,22 +65,24 @@ function socialListenStarCount() { function socialSingleValueRead() { // [START rtdb_social_single_value_read] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, onValue } = require("firebase/database"); const { getAuth } = require("firebase/auth"); const db = getDatabase(firebaseApp); const auth = getAuth(firebaseApp); const userId = auth.currentUser.uid; - return db.ref('/users/' + userId).once('value').then((snapshot) => { + return onValue(ref(db, '/users/' + userId), (snapshot) => { const username = (snapshot.val() && snapshot.val().username) || 'Anonymous'; // ... + }, { + onlyOnce: true }); // [END rtdb_social_single_value_read] } function writeNewPost_wrapped() { - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, child, push, update } = require("firebase/database"); // [START rtdb_social_write_fan_out] function writeNewPost(uid, username, picture, title, body) { @@ -97,14 +99,14 @@ function writeNewPost_wrapped() { }; // Get a key for a new Post. - const newPostKey = db.ref().child('posts').push().key; + const newPostKey = push(child(ref(db), 'posts')).key; // Write the new post's data simultaneously in the posts list and the user's post list. const updates = {}; updates['/posts/' + newPostKey] = postData; updates['/user-posts/' + uid + '/' + newPostKey] = postData; - return db.ref().update(updates); + return update(ref(db), updates); } // [END rtdb_social_write_fan_out] } @@ -115,32 +117,32 @@ function socialCompletionCallback() { const imageUrl = "https://example.com/image.png"; // [START rtdb_social_completion_callback] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, set } = require("firebase/database"); const db = getDatabase(firebaseApp); - db.ref('users/' + userId).set({ + set(ref(db, 'users/' + userId), { username: name, email: email, profile_picture : imageUrl - }, (error) => { - if (error) { - // The write failed... - } else { - // Data saved successfully! - } + }) + .then(() => { + // Data saved successfully! + }) + .catch((error) => { + // The write failed... }); // [END rtdb_social_completion_callback] } function toggleStar_wrapped() { // [START rtdb_social_star_transaction] - const { getDatabase } = require("firebase/database"); + const { getDatabase, ref, runTransaction } = require("firebase/database"); function toggleStar(uid) { const db = getDatabase(firebaseApp); - const postRef = db.ref('/posts/foo-bar-123'); + const postRef = ref(db, '/posts/foo-bar-123'); - postRef.transaction((post) => { + runTransaction(postRef, (post) => { if (post) { if (post.stars && post.stars[uid]) { post.starCount--; diff --git a/snippets/database-next/emulator-suite/rtdb_emulator_connect.js b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js index c16f0210..b666d9b1 100644 --- a/snippets/database-next/emulator-suite/rtdb_emulator_connect.js +++ b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js @@ -4,11 +4,11 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_emulator_connect_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, useDatabaseEmulator } from "firebase/database"; const db = getDatabase(firebaseApp); if (location.hostname === "localhost") { // Point to the RTDB emulator running on localhost. - db.useEmulator("localhost", 9000); + useDatabaseEmulator(db, "localhost", 9000); } // [END rtdb_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/database-next/emulator-suite/rtdb_emulator_flush.js b/snippets/database-next/emulator-suite/rtdb_emulator_flush.js index 66f8b282..5f0e3f5c 100644 --- a/snippets/database-next/emulator-suite/rtdb_emulator_flush.js +++ b/snippets/database-next/emulator-suite/rtdb_emulator_flush.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_emulator_flush_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, set } from "firebase/database"; // With a database Reference, write null to clear the database. const db = getDatabase(firebaseApp); -db.ref().set(null); +set(ref(db), null); // [END rtdb_emulator_flush_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_listen_children.js b/snippets/database-next/lists-of-data/rtdb_social_listen_children.js index 5aefb875..a527edeb 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_listen_children.js +++ b/snippets/database-next/lists-of-data/rtdb_social_listen_children.js @@ -4,19 +4,19 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_social_listen_children_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, onChildAdded, onChildChanged, onChildRemoved } from "firebase/database"; const db = getDatabase(firebaseApp); -const commentsRef = db.ref('post-comments/' + postId); -commentsRef.on('child_added', (data) => { +const commentsRef = ref(db, 'post-comments/' + postId); +onChildAdded(commentsRef, (data) => { addCommentElement(postElement, data.key, data.val().text, data.val().author); }); -commentsRef.on('child_changed', (data) => { +onChildChanged(commentsRef, (data) => { setCommentValues(postElement, data.key, data.val().text, data.val().author); }); -commentsRef.on('child_removed', (data) => { +onChildRemoved(commentsRef, (data) => { deleteComment(postElement, data.key); }); // [END rtdb_social_listen_children_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_listen_value.js b/snippets/database-next/lists-of-data/rtdb_social_listen_value.js index 3958a0d9..7250cc86 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_listen_value.js +++ b/snippets/database-next/lists-of-data/rtdb_social_listen_value.js @@ -4,16 +4,18 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_social_listen_value_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, onValue } from "firebase/database"; const db = getDatabase(firebaseApp); -const ref = db.ref('/a/b/c'); +const dbRef = ref(db, '/a/b/c'); -ref.once('value', (snapshot) => { +onValue(dbRef, (snapshot) => { snapshot.forEach((childSnapshot) => { const childKey = childSnapshot.key; const childData = childSnapshot.val(); // ... }); +}, { + onlyOnce: true }); // [END rtdb_social_listen_value_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_most_starred.js b/snippets/database-next/lists-of-data/rtdb_social_most_starred.js index 8c20de7a..96354b52 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_most_starred.js +++ b/snippets/database-next/lists-of-data/rtdb_social_most_starred.js @@ -4,12 +4,12 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_social_most_starred_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, query, orderByChild } from "firebase/database"; import { getAuth } from "firebase/auth"; const db = getDatabase(firebaseApp); const auth = getAuth(firebaseApp); const myUserId = auth.currentUser.uid; -const topUserPostsRef = db.ref('user-posts/' + myUserId).orderByChild('starCount'); +const topUserPostsRef = query(ref(db, 'user-posts/' + myUserId), orderByChild('starCount')); // [END rtdb_social_most_starred_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js b/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js index 2f5c03f8..3d661562 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js +++ b/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js @@ -4,8 +4,8 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_social_most_viewed_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, query, orderByChild } from "firebase/database"; const db = getDatabase(firebaseApp); -const mostViewedPosts = db.ref('posts').orderByChild('metrics/views'); +const mostViewedPosts = query(ref(db, 'posts'), orderByChild('metrics/views')); // [END rtdb_social_most_viewed_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_push.js b/snippets/database-next/lists-of-data/rtdb_social_push.js index e3c7f81c..313ff67c 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_push.js +++ b/snippets/database-next/lists-of-data/rtdb_social_push.js @@ -4,13 +4,13 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_social_push_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, push, set } from "firebase/database"; // Create a new post reference with an auto-generated id const db = getDatabase(firebaseApp); -const postListRef = db.ref('posts'); -const newPostRef = postListRef.push(); -newPostRef.set({ +const postListRef = ref(db, 'posts'); +const newPostRef = push(postListRef); +set(newPostRef, { // ... }); // [END rtdb_social_push_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_recent.js b/snippets/database-next/lists-of-data/rtdb_social_recent.js index 58fa2e38..a946817f 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_recent.js +++ b/snippets/database-next/lists-of-data/rtdb_social_recent.js @@ -4,8 +4,8 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_social_recent_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, query, limitToLast } from "firebase/database"; const db = getDatabase(firebaseApp); -const recentPostsRef = db.ref('posts').limitToLast(100); +const recentPostsRef = query(ref(db, 'posts'), limitToLast(100)); // [END rtdb_social_recent_modular] \ No newline at end of file diff --git a/snippets/database-next/offline/rtdb_detect_connection_state.js b/snippets/database-next/offline/rtdb_detect_connection_state.js index 3756f5be..b2bedd44 100644 --- a/snippets/database-next/offline/rtdb_detect_connection_state.js +++ b/snippets/database-next/offline/rtdb_detect_connection_state.js @@ -4,11 +4,11 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_detect_connection_state_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, onValue } from "firebase/database"; const db = getDatabase(firebaseApp); -const connectedRef = db.ref(".info/connected"); -connectedRef.on("value", (snap) => { +const connectedRef = ref(db, ".info/connected"); +onValue(connectedRef, (snap) => { if (snap.val() === true) { console.log("connected"); } else { diff --git a/snippets/database-next/offline/rtdb_estimate_clock_skew.js b/snippets/database-next/offline/rtdb_estimate_clock_skew.js index cdb19491..0d7fea48 100644 --- a/snippets/database-next/offline/rtdb_estimate_clock_skew.js +++ b/snippets/database-next/offline/rtdb_estimate_clock_skew.js @@ -4,11 +4,11 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_estimate_clock_skew_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, onValue } from "firebase/database"; const db = getDatabase(firebaseApp); -const offsetRef = db.ref(".info/serverTimeOffset"); -offsetRef.on("value", (snap) => { +const offsetRef = ref(db, ".info/serverTimeOffset"); +onValue(offsetRef, (snap) => { const offset = snap.val(); const estimatedServerTimeMs = new Date().getTime() + offset; }); diff --git a/snippets/database-next/offline/rtdb_ondisconnect_callback.js b/snippets/database-next/offline/rtdb_ondisconnect_callback.js index 6af1ee61..6b7f2950 100644 --- a/snippets/database-next/offline/rtdb_ondisconnect_callback.js +++ b/snippets/database-next/offline/rtdb_ondisconnect_callback.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_ondisconnect_callback_modular] -presenceRef.onDisconnect().remove((err) => { +onDisconnect(presenceRef).remove().catch((err) => { if (err) { console.error("could not establish onDisconnect event", err); } diff --git a/snippets/database-next/offline/rtdb_ondisconnect_cancel.js b/snippets/database-next/offline/rtdb_ondisconnect_cancel.js index 7af11312..f5c3c972 100644 --- a/snippets/database-next/offline/rtdb_ondisconnect_cancel.js +++ b/snippets/database-next/offline/rtdb_ondisconnect_cancel.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_ondisconnect_cancel_modular] -const onDisconnectRef = presenceRef.onDisconnect(); +const onDisconnectRef = onDisconnect(presenceRef); onDisconnectRef.set("I disconnected"); // some time later when we change our minds onDisconnectRef.cancel(); diff --git a/snippets/database-next/offline/rtdb_ondisconnect_simple.js b/snippets/database-next/offline/rtdb_ondisconnect_simple.js index eedfab7f..838ab744 100644 --- a/snippets/database-next/offline/rtdb_ondisconnect_simple.js +++ b/snippets/database-next/offline/rtdb_ondisconnect_simple.js @@ -4,10 +4,10 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_ondisconnect_simple_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, onDisconnect } from "firebase/database"; const db = getDatabase(firebaseApp); -const presenceRef = db.ref("disconnectmessage"); +const presenceRef = ref(db, "disconnectmessage"); // Write a string when this client loses connection -presenceRef.onDisconnect().set("I disconnected!"); +onDisconnect(presenceRef).set("I disconnected!"); // [END rtdb_ondisconnect_simple_modular] \ No newline at end of file diff --git a/snippets/database-next/offline/rtdb_sample_presence_app.js b/snippets/database-next/offline/rtdb_sample_presence_app.js index bef04145..e093238e 100644 --- a/snippets/database-next/offline/rtdb_sample_presence_app.js +++ b/snippets/database-next/offline/rtdb_sample_presence_app.js @@ -4,31 +4,31 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_sample_presence_app_modular] -import { getDatabase, ServerValue } from "firebase/database"; +import { getDatabase, ref, onValue, push, onDisconnect, set, serverTimestamp } from "firebase/database"; // Since I can connect from multiple devices or browser tabs, we store each connection instance separately // any time that connectionsRef's value is null (i.e. has no children) I am offline const db = getDatabase(firebaseApp); -const myConnectionsRef = db.ref('users/joe/connections'); +const myConnectionsRef = ref(db, 'users/joe/connections'); // stores the timestamp of my last disconnect (the last time I was seen online) -const lastOnlineRef = db.ref('users/joe/lastOnline'); +const lastOnlineRef = ref(db, 'users/joe/lastOnline'); -const connectedRef = db.ref('.info/connected'); -connectedRef.on('value', (snap) => { +const connectedRef = ref(db, '.info/connected'); +onValue(connectedRef, (snap) => { if (snap.val() === true) { // We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect) - const con = myConnectionsRef.push(); + const con = push(myConnectionsRef); // When I disconnect, remove this device - con.onDisconnect().remove(); + onDisconnect(con).remove(); // Add this device to my connections list // this value could contain info about the device or a timestamp too - con.set(true); + set(con, true); // When I disconnect, update the last time I was seen online - lastOnlineRef.onDisconnect().set(ServerValue.TIMESTAMP); + onDisconnect(lastOnlineRef).set(serverTimestamp()); } }); // [END rtdb_sample_presence_app_modular] \ No newline at end of file diff --git a/snippets/database-next/offline/rtdb_set_server_timestamp.js b/snippets/database-next/offline/rtdb_set_server_timestamp.js index f9319e07..14850121 100644 --- a/snippets/database-next/offline/rtdb_set_server_timestamp.js +++ b/snippets/database-next/offline/rtdb_set_server_timestamp.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_set_server_timestamp_modular] -import { getDatabase, ServerValue } from "firebase/database"; +import { getDatabase, ref, onDisconnect, serverTimestamp } from "firebase/database"; const db = getDatabase(firebaseApp); -const userLastOnlineRef = db.ref("users/joe/lastOnline"); -userLastOnlineRef.onDisconnect().set(ServerValue.TIMESTAMP); +const userLastOnlineRef = ref(db, "users/joe/lastOnline"); +onDisconnect(userLastOnlineRef).set(serverTimestamp()); // [END rtdb_set_server_timestamp_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_social_completion_callback.js b/snippets/database-next/read-and-write/rtdb_social_completion_callback.js index 5251b5c4..cb22a488 100644 --- a/snippets/database-next/read-and-write/rtdb_social_completion_callback.js +++ b/snippets/database-next/read-and-write/rtdb_social_completion_callback.js @@ -4,18 +4,18 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_social_completion_callback_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, set } from "firebase/database"; const db = getDatabase(firebaseApp); -db.ref('users/' + userId).set({ +set(ref(db, 'users/' + userId), { username: name, email: email, profile_picture : imageUrl -}, (error) => { - if (error) { - // The write failed... - } else { - // Data saved successfully! - } +}) +.then(() => { + // Data saved successfully! +}) +.catch((error) => { + // The write failed... }); // [END rtdb_social_completion_callback_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js b/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js index 186afb4f..3a7c7e85 100644 --- a/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js +++ b/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js @@ -4,11 +4,11 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_social_listen_star_count_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, onValue} from "firebase/database"; const db = getDatabase(firebaseApp); -const starCountRef = db.ref('posts/' + postId + '/starCount'); -starCountRef.on('value', (snapshot) => { +const starCountRef = ref(db, 'posts/' + postId + '/starCount'); +onValue(starCountRef, (snapshot) => { const data = snapshot.val(); updateStarCount(postElement, data); }); diff --git a/snippets/database-next/read-and-write/rtdb_social_single_value_read.js b/snippets/database-next/read-and-write/rtdb_social_single_value_read.js index b5bfc662..5e68d8c1 100644 --- a/snippets/database-next/read-and-write/rtdb_social_single_value_read.js +++ b/snippets/database-next/read-and-write/rtdb_social_single_value_read.js @@ -4,15 +4,17 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_social_single_value_read_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, onValue } from "firebase/database"; import { getAuth } from "firebase/auth"; const db = getDatabase(firebaseApp); const auth = getAuth(firebaseApp); const userId = auth.currentUser.uid; -return db.ref('/users/' + userId).once('value').then((snapshot) => { +return onValue(ref(db, '/users/' + userId), (snapshot) => { const username = (snapshot.val() && snapshot.val().username) || 'Anonymous'; // ... +}, { + onlyOnce: true }); // [END rtdb_social_single_value_read_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_social_star_transaction.js b/snippets/database-next/read-and-write/rtdb_social_star_transaction.js index 9c905d2c..9f0679a8 100644 --- a/snippets/database-next/read-and-write/rtdb_social_star_transaction.js +++ b/snippets/database-next/read-and-write/rtdb_social_star_transaction.js @@ -4,13 +4,13 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_social_star_transaction_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, runTransaction } from "firebase/database"; function toggleStar(uid) { const db = getDatabase(firebaseApp); - const postRef = db.ref('/posts/foo-bar-123'); + const postRef = ref(db, '/posts/foo-bar-123'); - postRef.transaction((post) => { + runTransaction(postRef, (post) => { if (post) { if (post.stars && post.stars[uid]) { post.starCount--; diff --git a/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js b/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js index 0c2973c4..d51a23eb 100644 --- a/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js +++ b/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js @@ -18,13 +18,13 @@ function writeNewPost(uid, username, picture, title, body) { }; // Get a key for a new Post. - const newPostKey = db.ref().child('posts').push().key; + const newPostKey = push(child(ref(db), 'posts')).key; // Write the new post's data simultaneously in the posts list and the user's post list. const updates = {}; updates['/posts/' + newPostKey] = postData; updates['/user-posts/' + uid + '/' + newPostKey] = postData; - return db.ref().update(updates); + return update(ref(db), updates); } // [END rtdb_social_write_fan_out_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_write_new_user.js b/snippets/database-next/read-and-write/rtdb_write_new_user.js index c6a84358..85f0ad83 100644 --- a/snippets/database-next/read-and-write/rtdb_write_new_user.js +++ b/snippets/database-next/read-and-write/rtdb_write_new_user.js @@ -4,11 +4,11 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_write_new_user_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, set} from "firebase/database"; function writeUserData(userId, name, email, imageUrl) { const db = getDatabase(firebaseApp); - db.ref('users/' + userId).set({ + set(ref(db, 'users/' + userId), { username: name, email: email, profile_picture : imageUrl diff --git a/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js b/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js index cd10104d..41dffc81 100644 --- a/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js +++ b/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js @@ -4,18 +4,18 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_write_new_user_completion_modular] -import { getDatabase } from "firebase/database"; +import { getDatabase, ref, set } from "firebase/database"; const db = getDatabase(firebaseApp); -db.ref('users/' + userId).set({ +set(ref(db, 'users/' + userId), { username: name, email: email, profile_picture : imageUrl -}, (error) => { - if (error) { - // The write failed... - } else { - // Data saved successfully! - } +}) +.then(() => { + // Data saved successfully! +}) +.catch((error) => { + // The write failed... }); // [END rtdb_write_new_user_completion_modular] \ No newline at end of file From 554bf3657a9a4f68539af36a3736e281f05f83e4 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 9 Apr 2021 06:44:55 -0400 Subject: [PATCH 117/235] Add RTDB get() snippet (#133) --- database-next/read-and-write.js | 16 ++++++++++++++++ database/read-and-write.js | 15 +++++++++++++++ .../read-and-write/rtdb_read_once_get.js | 19 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 snippets/database-next/read-and-write/rtdb_read_once_get.js diff --git a/database-next/read-and-write.js b/database-next/read-and-write.js index 6e3ac273..db7da0db 100644 --- a/database-next/read-and-write.js +++ b/database-next/read-and-write.js @@ -161,3 +161,19 @@ function toggleStar_wrapped() { // [END rtdb_social_star_transaction] } +function readOnceWithGet(userId) { + // [START rtdb_read_once_get] + const { getDatabase, ref, child, get } = require("firebase/database"); + + const dbRef = ref(getDatabase(firebaseApp)); + get(child(dbRef, `users/${userId}`)).then((snapshot) => { + if (snapshot.exists()) { + console.log(snapshot.val()); + } else { + console.log("No data available"); + } + }).catch((error) => { + console.error(error); + }); + // [END rtdb_read_once_get] +} diff --git a/database/read-and-write.js b/database/read-and-write.js index 59336c8f..e14b741b 100644 --- a/database/read-and-write.js +++ b/database/read-and-write.js @@ -123,3 +123,18 @@ function toggleStar(postRef, uid) { }); } // [END rtdb_social_star_transaction] + +function readOnceWithGet(userId) { + // [START rtdb_read_once_get] + const dbRef = firebase.database().ref(); + dbRef.child("users").child(userId).get().then((snapshot) => { + if (snapshot.exists()) { + console.log(snapshot.val()); + } else { + console.log("No data available"); + } + }).catch((error) => { + console.error(error); + }); + // [END rtdb_read_once_get] +} diff --git a/snippets/database-next/read-and-write/rtdb_read_once_get.js b/snippets/database-next/read-and-write/rtdb_read_once_get.js new file mode 100644 index 00000000..13799f3a --- /dev/null +++ b/snippets/database-next/read-and-write/rtdb_read_once_get.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./database-next/read-and-write.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_read_once_get_modular] +import { getDatabase, ref, child, get } from "firebase/database"; + +const dbRef = ref(getDatabase(firebaseApp)); +get(child(dbRef, `users/${userId}`)).then((snapshot) => { + if (snapshot.exists()) { + console.log(snapshot.val()); + } else { + console.log("No data available"); + } +}).catch((error) => { + console.error(error); +}); +// [END rtdb_read_once_get_modular] \ No newline at end of file From 8afe3fad0bca9d6ecc49dbfb20bbe4719be1da2c Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 9 Apr 2021 04:15:23 -0700 Subject: [PATCH 118/235] Auto-update dependencies. (#131) Co-authored-by: Sam Stern --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 2f87eaf0..3883772f 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.2" + "firebase": "^8.3.3" } } diff --git a/auth/package.json b/auth/package.json index 77a36fd2..bb6f53ad 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.2", + "firebase": "^8.3.3", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index ab6ad90d..52076305 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.2" + "firebase": "^8.3.3" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index caa83383..4e0c769f 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.2" + "firebase": "^8.3.3" } } diff --git a/firestore/package.json b/firestore/package.json index 806fdb30..788d5a65 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.2", + "firebase": "^8.3.3", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 9cda8101..68327016 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.2" + "firebase": "^8.3.3" } } diff --git a/installations/package.json b/installations/package.json index 1d2f4cec..2c2ac3bf 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.2" + "firebase": "^8.3.3" } } diff --git a/messaging/package.json b/messaging/package.json index 8a389487..c53fa8c6 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.2" + "firebase": "^8.3.3" } } diff --git a/perf/package.json b/perf/package.json index 7d14e302..3fda34fd 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.2" + "firebase": "^8.3.3" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 251d1f2f..45a411e2 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.2" + "firebase": "^8.3.3" } } diff --git a/storage/package.json b/storage/package.json index 2e146416..b777b198 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.2" + "firebase": "^8.3.3" } } From d9fbdfc0e39725e16c6d720ba04e801baf94fd4c Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 9 Apr 2021 08:36:54 -0400 Subject: [PATCH 119/235] Remove default app where possible (#135) --- analytics-next/ecommerce.js | 33 +++++++------------ analytics-next/index.js | 16 +++------ auth-next/anonymous.js | 10 +----- auth-next/apple.js | 20 ++++------- auth-next/auth-state-persistence.js | 12 ++----- auth-next/cordova.js | 12 ++----- auth-next/custom-email-handler.js | 8 ----- auth-next/custom.js | 10 +----- auth-next/email-link-auth.js | 18 +++------- auth-next/email.js | 16 +++------ auth-next/emulator-suite.js | 10 +----- auth-next/facebook.js | 16 +++------ auth-next/github.js | 12 ++----- auth-next/google-signin.js | 16 +++------ auth-next/index.js | 18 +++------- auth-next/link-multiple-accounts.js | 20 ++++------- auth-next/microsoft-oauth.js | 18 +++------- auth-next/phone-auth.js | 16 +++------ auth-next/service-worker-sessions.js | 14 ++------ auth-next/twitter.js | 12 ++----- auth-next/yahoo-oauth.js | 18 +++------- database-next/emulator-suite.js | 12 ++----- database-next/index.js | 10 +----- database-next/lists-of-data.js | 22 ++++--------- database-next/offline.js | 22 ++++--------- database-next/read-and-write.js | 28 ++++++---------- firestore-next/emulator-suite.js | 4 +-- functions-next/callable.js | 6 ++-- messaging-next/index.js | 16 +++------ perf-next/index.js | 13 ++------ remoteconfig-next/index.js | 10 +----- .../ecommerce/analytics_ecommerce_add_cart.js | 2 +- .../ecommerce/analytics_ecommerce_checkout.js | 2 +- .../analytics_ecommerce_payment_info.js | 2 +- .../analytics_ecommerce_promotions.js | 2 +- .../ecommerce/analytics_ecommerce_purchase.js | 2 +- .../ecommerce/analytics_ecommerce_refund.js | 2 +- .../analytics_ecommerce_remove_cart.js | 2 +- .../analytics_ecommerce_select_item.js | 2 +- .../analytics_ecommerce_shipping_info.js | 2 +- .../analytics_ecommerce_view_cart.js | 2 +- .../analytics_ecommerce_view_item_details.js | 2 +- .../analytics_ecommerce_view_item_list.js | 2 +- .../index/analytics_initialize.js | 2 +- .../index/analytics_log_event.js | 2 +- .../analytics_log_event_custom_params.js | 2 +- .../index/analytics_log_event_params.js | 2 +- .../index/analytics_set_user_properties.js | 2 +- .../auth-next/anonymous/auth_anon_sign_in.js | 2 +- .../apple/auth_apple_link_facebook.js | 2 +- .../apple/auth_apple_reauthenticate_popup.js | 2 +- .../apple/auth_apple_signin_nonce.js | 2 +- .../apple/auth_apple_signin_popup.js | 2 +- .../apple/auth_apple_signin_redirect.js | 2 +- .../auth_apple_signin_redirect_result.js | 2 +- .../auth_set_persistence_none.js | 2 +- .../auth_set_persistence_session.js | 2 +- .../cordova/auth_cordova_redirect_result.js | 2 +- .../cordova/auth_cordova_sign_in_redirect.js | 2 +- .../auth-next/custom/auth_sign_in_custom.js | 2 +- .../email-link-auth/auth_email_link_link.js | 2 +- .../email-link-auth/auth_email_link_reauth.js | 2 +- .../email-link-auth/auth_email_link_send.js | 2 +- .../email-link-auth/email_link_complete.js | 2 +- .../email_link_diferentiate.js | 2 +- .../email/auth_send_email_verification.js | 2 +- .../email/auth_send_password_reset.js | 2 +- .../auth-next/email/auth_signin_password.js | 2 +- .../auth-next/email/auth_signup_password.js | 2 +- .../emulator-suite/auth_emulator_connect.js | 2 +- .../facebook/auth_facebook_callback.js | 2 +- .../auth_facebook_signin_credential.js | 2 +- .../facebook/auth_facebook_signin_popup.js | 2 +- .../auth_facebook_signin_redirect_result.js | 2 +- .../github/auth_github_signin_popup.js | 2 +- .../auth_github_signin_redirect_result.js | 2 +- .../google-signin/auth_google_build_signin.js | 2 +- .../google-signin/auth_google_callback.js | 2 +- .../google-signin/auth_google_signin_popup.js | 2 +- .../auth_google_signin_redirect_result.js | 2 +- .../auth-next/index/auth_set_language_code.js | 2 +- snippets/auth-next/index/auth_sign_out.js | 2 +- .../auth-next/index/auth_signin_credential.js | 2 +- .../auth-next/index/auth_signin_redirect.js | 2 +- .../auth-next/index/auth_state_listener.js | 2 +- .../auth_anonymous_link.js | 2 +- .../auth_link_with_popup.js | 2 +- .../auth_link_with_redirect.js | 2 +- .../auth_merge_accounts.js | 2 +- .../auth_simple_link.js | 2 +- .../auth_unlink_provider.js | 2 +- .../microsoft-oauth/auth_msft_link_popup.js | 2 +- .../microsoft-oauth/auth_msft_reauth_popup.js | 2 +- .../microsoft-oauth/auth_msft_signin_popup.js | 2 +- .../auth_msft_signin_redirect.js | 2 +- .../auth_msft_signin_redirect_result.js | 2 +- ...auth_phone_recaptcha_verifier_invisible.js | 2 +- .../auth_phone_recaptcha_verifier_simple.js | 2 +- .../auth_phone_recaptcha_verifier_visible.js | 2 +- .../auth-next/phone-auth/auth_phone_signin.js | 2 +- .../auth_svc_get_idtoken.js | 2 +- .../auth_svc_sign_in_email.js | 2 +- .../auth_svc_subscribe.js | 2 +- .../twitter/auth_twitter_signin_popup.js | 2 +- .../auth_twitter_signin_redirect_result.js | 2 +- .../yahoo-oauth/auth_yahoo_link_popup.js | 2 +- .../yahoo-oauth/auth_yahoo_reauth_popup.js | 2 +- .../yahoo-oauth/auth_yahoo_signin_popup.js | 2 +- .../yahoo-oauth/auth_yahoo_signin_redirect.js | 2 +- .../auth_yahoo_signin_redirect_result.js | 2 +- .../emulator-suite/rtdb_emulator_connect.js | 2 +- .../emulator-suite/rtdb_emulator_flush.js | 2 +- .../database-next/index/rtdb_get_reference.js | 2 +- .../rtdb_social_listen_children.js | 2 +- .../lists-of-data/rtdb_social_listen_value.js | 2 +- .../lists-of-data/rtdb_social_most_starred.js | 4 +-- .../lists-of-data/rtdb_social_most_viewed.js | 2 +- .../lists-of-data/rtdb_social_push.js | 2 +- .../lists-of-data/rtdb_social_recent.js | 2 +- .../offline/rtdb_detect_connection_state.js | 2 +- .../offline/rtdb_estimate_clock_skew.js | 2 +- .../offline/rtdb_ondisconnect_simple.js | 2 +- .../offline/rtdb_sample_presence_app.js | 2 +- .../offline/rtdb_set_server_timestamp.js | 2 +- .../read-and-write/rtdb_read_once_get.js | 2 +- .../rtdb_social_completion_callback.js | 2 +- .../rtdb_social_listen_star_count.js | 2 +- .../rtdb_social_single_value_read.js | 4 +-- .../rtdb_social_star_transaction.js | 2 +- .../rtdb_social_write_fan_out.js | 2 +- .../read-and-write/rtdb_write_new_user.js | 4 +-- .../rtdb_write_new_user_completion.js | 2 +- .../emulator-suite/fs_emulator_connect.js | 2 +- .../callable/fb_functions_call_add_message.js | 2 +- .../fb_functions_call_add_message_error.js | 2 +- .../index/messaging_delete_token.js | 2 +- .../index/messaging_get_messaging_object.js | 2 +- .../index/messaging_get_token.js | 2 +- .../index/messaging_receive_message.js | 2 +- snippets/perf-next/index/perf_get_instance.js | 2 +- .../index/rc_get_instance.js | 2 +- .../create-reference/storage_create_ref.js | 2 +- .../storage_create_ref_child.js | 2 +- .../create-reference/storage_navigate_ref.js | 2 +- .../storage_navigate_ref_chain.js | 2 +- .../storage_ref_full_example.js | 2 +- .../storage_ref_properties.js | 2 +- .../delete-files/storage_delete_file.js | 2 +- .../storage_download_create_ref.js | 2 +- .../storage_download_full_example.js | 2 +- .../storage_download_via_url.js | 2 +- .../file-metadata/storage_delete_metadata.js | 2 +- .../file-metadata/storage_get_metadata.js | 2 +- .../file-metadata/storage_update_metadata.js | 2 +- .../index/storage_multiple_buckets.js | 2 ++ .../storage-next/index/storage_on_complete.js | 2 +- .../list-files/storage_list_all.js | 2 +- .../list-files/storage_list_paginate.js | 2 +- .../upload-files/storage_manage_uploads.js | 2 +- .../upload-files/storage_monitor_upload.js | 2 +- .../upload-files/storage_upload_blob.js | 2 +- .../upload-files/storage_upload_bytes.js | 2 +- .../storage_upload_handle_error.js | 2 +- .../upload-files/storage_upload_metadata.js | 2 +- .../upload-files/storage_upload_ref.js | 2 +- .../upload-files/storage_upload_string.js | 2 +- storage-next/create-reference.js | 20 ++++------- storage-next/delete-files.js | 10 +----- storage-next/download-files.js | 14 ++------ storage-next/file-metadata.js | 14 ++------ storage-next/index.js | 12 ++----- storage-next/list-files.js | 12 ++----- storage-next/upload-files.js | 24 +++++--------- 173 files changed, 284 insertions(+), 566 deletions(-) diff --git a/analytics-next/ecommerce.js b/analytics-next/ecommerce.js index b14f0eb2..c4c7807c 100644 --- a/analytics-next/ecommerce.js +++ b/analytics-next/ecommerce.js @@ -1,15 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - - // [START analytics_ecommerce_items] // A pair of jeggings const item_jeggings = { @@ -54,7 +45,7 @@ function ecommerceViewItemList() { }; // Log event - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'view_item_list', params1); // [END analytics_ecommerce_view_item_list] } @@ -71,7 +62,7 @@ function ecommerceSelectItem() { }; // Log event - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'select_item', params2); // [END analytics_ecommerce_select_item] } @@ -88,7 +79,7 @@ function ecommerceViewItemDetails() { }; // Log event - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'view_item', params3); // [END analytics_ecommerce_view_item_details] } @@ -111,7 +102,7 @@ function ecommerceAddCart() { }; // Log event when a product is added to a wishlist - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'add_to_wishlist', params4); // Log event when a product is added to the cart @@ -142,7 +133,7 @@ function ecommerceViewCart() { }; // Log event when the cart is viewed - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'view_cart', params5); // [END analytics_ecommerce_view_cart] } @@ -159,7 +150,7 @@ function ecommerceRemoveCart() { }; // Log event - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'remove_from_cart', params6); // [END analytics_ecommerce_remove_cart] } @@ -177,7 +168,7 @@ function ecommerceCheckout() { }; // Log event - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'begin_checkout', params7); // [END analytics_ecommerce_checkout] } @@ -196,7 +187,7 @@ function ecommerceShippingInfo() { }; // Log event - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'add_shipping_info', params8); // [END analytics_ecommerce_shipping_info] } @@ -215,7 +206,7 @@ function ecommercePaymentInfo() { }; // Log event - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'add_payment_info', params9); // [END analytics_ecommerce_payment_info] } @@ -237,7 +228,7 @@ function ecommercePurchase() { }; // Log event - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'purchase', params10); // [END analytics_ecommerce_purchase] } @@ -264,7 +255,7 @@ function ecommerceRefund() { params11.items.push(refundedProduct); // Log event - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'refund', params11); // [END analytics_ecommerce_refund] } @@ -284,7 +275,7 @@ function ecommercePromotions() { }; // Log event when a promotion is displayed - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'view_promotion', params12); // Log event when a promotion is selected diff --git a/analytics-next/index.js b/analytics-next/index.js index 047f1289..a93de88a 100644 --- a/analytics-next/index.js +++ b/analytics-next/index.js @@ -3,17 +3,11 @@ import { initializeApp } from "firebase/app"; -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function initialize() { // [START analytics_initialize] const { getAnalytics } = require("firebase/analytics"); - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); // [END analytics_initialize] } @@ -21,7 +15,7 @@ function logEvent() { // [START analytics_log_event] const { getAnalytics, logEvent } = require("firebase/analytics"); - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'notification_received'); // [END analytics_log_event] } @@ -30,7 +24,7 @@ function logEventParams() { // [START analytics_log_event_params] const { getAnalytics, logEvent } = require("firebase/analytics"); - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'select_content', { content_type: 'image', content_id: 'P12453', @@ -43,7 +37,7 @@ function logEventCustomParams() { // [START analytics_log_event_custom_params] const { getAnalytics, logEvent } = require("firebase/analytics"); - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); logEvent(analytics, 'goal_completion', { name: 'lever_puzzle'}); // [END analytics_log_event_custom_params] } @@ -52,7 +46,7 @@ function setUserProperties() { // [START analytics_set_user_properties] const { getAnalytics, setUserProperties } = require("firebase/analytics"); - const analytics = getAnalytics(firebaseApp); + const analytics = getAnalytics(); setUserProperties(analytics, { favorite_food: 'apples' }); // [END analytics_set_user_properties] } diff --git a/auth-next/anonymous.js b/auth-next/anonymous.js index 56a56c39..33d5a936 100644 --- a/auth-next/anonymous.js +++ b/auth-next/anonymous.js @@ -1,19 +1,11 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - function anonSignIn() { // [START auth_anon_sign_in] const { getAuth, signInAnonymously } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInAnonymously(auth) .then(() => { // Signed in.. diff --git a/auth-next/apple.js b/auth-next/apple.js index 177aa065..29a33dea 100644 --- a/auth-next/apple.js +++ b/auth-next/apple.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/apple.md function appleProvider() { @@ -35,7 +27,7 @@ function appleSignInPopup(provider) { // [START auth_apple_signin_popup] const { getAuth, signInWithPopup, OAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // The signed-in user info. @@ -66,7 +58,7 @@ function appleSignInRedirect(provider) { // [START auth_apple_signin_redirect] const { getAuth, signInWithRedirect } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithRedirect(auth, provider); // [END auth_apple_signin_redirect] } @@ -76,7 +68,7 @@ function appleSignInRedirectResult() { const { getAuth, getRedirectResult, OAuthProvider } = require("firebase/auth"); // Result from Redirect auth flow. - const auth = getAuth(firebaseApp); + const auth = getAuth(); getRedirectResult(auth) .then((result) => { const credential = OAuthProvider.credentialFromResult(result); @@ -107,7 +99,7 @@ function appleReauthenticatePopup() { const { getAuth, reauthenticateWithPopup, OAuthProvider } = require("firebase/auth"); // Result from Redirect auth flow. - const auth = getAuth(firebaseApp); + const auth = getAuth(); const provider = new OAuthProvider('apple.com'); reauthenticateWithPopup(auth.currentUser, provider) @@ -144,7 +136,7 @@ function appleLinkFacebook() { // [START auth_apple_link_facebook] const { getAuth, linkWithPopup, FacebookAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); const provider = new FacebookAuthProvider(); provider.addScope('user_birthday'); @@ -192,7 +184,7 @@ function appleSignInNonce(appleIdToken, unhashedNonce,) { // [START auth_apple_signin_nonce] const { getAuth, signInWithCredential, OAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); // Build Firebase credential with the Apple ID token. const provider = new OAuthProvider('apple.com'); diff --git a/auth-next/auth-state-persistence.js b/auth-next/auth-state-persistence.js index cef52522..2d36c429 100644 --- a/auth-next/auth-state-persistence.js +++ b/auth-next/auth-state-persistence.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - function setPersistenceSession() { const email = "..."; const password = "..."; @@ -16,7 +8,7 @@ function setPersistenceSession() { // [START auth_set_persistence_session] const { getAuth, setPersistence, signInWithEmailAndPassword, browserSessionPersistence } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); setPersistence(auth, browserSessionPersistence) .then(() => { // Existing and future Auth states are now persisted in the current @@ -38,7 +30,7 @@ function setPersistenceNone() { // [START auth_set_persistence_none] const { getAuth, setPersistence, signInWithRedirect, inMemoryPersistence, GoogleAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); setPersistence(auth, inMemoryPersistence) .then(() => { const provider = new GoogleAuthProvider(); diff --git a/auth-next/cordova.js b/auth-next/cordova.js index ec637576..1823b33c 100644 --- a/auth-next/cordova.js +++ b/auth-next/cordova.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/cordova.md function createGoogleProvider() { @@ -23,7 +15,7 @@ function cordovaSignInRedirect() { // [START auth_cordova_sign_in_redirect] const { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithRedirect(auth, new GoogleAuthProvider()) .then(() => { return getRedirectResult(auth); @@ -50,7 +42,7 @@ function cordovaRedirectResult() { // [START auth_cordova_redirect_result] const { getAuth, getRedirectResult, GoogleAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); getRedirectResult(auth) .then((result) => { const credential = GoogleAuthProvider.credentialFromResult(result); diff --git a/auth-next/custom-email-handler.js b/auth-next/custom-email-handler.js index eccb9219..728baff8 100644 --- a/auth-next/custom-email-handler.js +++ b/auth-next/custom-email-handler.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/custom-email-handler.md function handleUserManagementQueryParams() { diff --git a/auth-next/custom.js b/auth-next/custom.js index 8f4ac547..8975672e 100644 --- a/auth-next/custom.js +++ b/auth-next/custom.js @@ -1,21 +1,13 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - function signInCustom() { const token = "token123"; // [START auth_sign_in_custom] const { getAuth, signInWithCustomToken } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithCustomToken(auth, token) .then((userCredential) => { // Signed in diff --git a/auth-next/email-link-auth.js b/auth-next/email-link-auth.js index a2ec5cf5..59ea2115 100644 --- a/auth-next/email-link-auth.js +++ b/auth-next/email-link-auth.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/email-link-auth.md function emailLinkActionCodeSettings() { @@ -36,7 +28,7 @@ function emailLinkSend(email, actionCodeSettings) { // [START auth_email_link_send] const { getAuth, sendSignInLinkToEmail } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); sendSignInLinkToEmail(auth, email, actionCodeSettings) .then(() => { // The link was successfully sent. Inform the user. @@ -58,7 +50,7 @@ function emailLinkComplete() { const { getAuth, isSignInWithEmailLink, signInWithEmailLink } = require("firebase/auth"); // Confirm the link is a sign-in with email link. - const auth = getAuth(firebaseApp); + const auth = getAuth(); if (isSignInWithEmailLink(auth, window.location.href)) { // Additional state parameters can also be passed via URL. // This can be used to continue the user's intended action before triggering @@ -99,7 +91,7 @@ function emailLinkLink(email) { email, window.location.href); // Link the credential to the current user. - const auth = getAuth(firebaseApp); + const auth = getAuth(); linkWithCredential(auth.currentUser, credential) .then((usercred) => { // The provider is now successfully linked. @@ -120,7 +112,7 @@ function emailLinkReauth(email) { email, window.location.href); // Re-authenticate the user with this credential. - const auth = getAuth(firebaseApp); + const auth = getAuth(); reauthenticateWithCredential(auth.currentUser, credential) .then((usercred) => { // The user is now successfully re-authenticated and can execute sensitive @@ -139,7 +131,7 @@ function emailLinkDifferentiate() { // After asking the user for their email. const email = window.prompt('Please provide your email'); - const auth = getAuth(firebaseApp); + const auth = getAuth(); fetchSignInMethodsForEmail(auth, email) .then((signInMethods) => { // This returns the same array as fetchProvidersForEmail but for email diff --git a/auth-next/email.js b/auth-next/email.js index 7285185a..b00551c8 100644 --- a/auth-next/email.js +++ b/auth-next/email.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - function signInWithEmailPassword() { const email = "test@example.com"; const password = "hunter2"; @@ -16,7 +8,7 @@ function signInWithEmailPassword() { // [START auth_signin_password] const { getAuth, signInWithEmailAndPassword } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithEmailAndPassword(auth, email, password) .then((userCredential) => { // Signed in @@ -37,7 +29,7 @@ function signUpWithEmailPassword() { // [START auth_signup_password] const { getAuth, createUserWithEmailAndPassword } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); createUserWithEmailAndPassword(auth, email, password) .then((userCredential) => { // Signed in @@ -56,7 +48,7 @@ function sendEmailVerification() { // [START auth_send_email_verification] const { getAuth, sendEmailVerification } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); sendEmailVerification(auth.currentUser) .then(() => { // Email verification sent! @@ -71,7 +63,7 @@ function sendPasswordReset() { // [START auth_send_password_reset] const { getAuth, sendPasswordResetEmail } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); sendPasswordResetEmail(auth, email) .then(() => { // Password reset email sent! diff --git a/auth-next/emulator-suite.js b/auth-next/emulator-suite.js index aca56cff..ed24e78b 100644 --- a/auth-next/emulator-suite.js +++ b/auth-next/emulator-suite.js @@ -1,19 +1,11 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - function emulatorConnect() { // [START auth_emulator_connect] const { getAuth, useAuthEmulator } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); useAuthEmulator(auth, "http://localhost:9099"); // [END auth_emulator_connect] } diff --git a/auth-next/facebook.js b/auth-next/facebook.js index 0ec084bd..4b61f4be 100644 --- a/auth-next/facebook.js +++ b/auth-next/facebook.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - function facebookProvider() { // [START auth_facebook_provider_create] const { FacebookAuthProvider } = require("firebase/auth"); @@ -31,7 +23,7 @@ function facebookSignInPopup(provider) { // [START auth_facebook_signin_popup] const { getAuth, signInWithPopup, FacebookAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // The signed-in user info. @@ -61,7 +53,7 @@ function facebookSignInRedirectResult() { // [START auth_facebook_signin_redirect_result] const { getAuth, getRedirectResult, FacebookAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); getRedirectResult(auth) .then((result) => { // This gives you a Facebook Access Token. You can use it to access the Facebook API. @@ -90,7 +82,7 @@ function checkLoginState_wrapper() { // [START auth_facebook_callback] const { getAuth, onAuthStateChanged, signInWithCredential, signOut, FacebookAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); function checkLoginState(response) { if (response.authResponse) { @@ -153,7 +145,7 @@ function authWithCredential(credential) { const { getAuth, signInWithCredential, FacebookAuthProvider } = require("firebase/auth"); // Sign in with the credential from the Facebook user. - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithCredential(auth, credential) .then((result) => { // Signed in diff --git a/auth-next/github.js b/auth-next/github.js index 0289a53b..941a9047 100644 --- a/auth-next/github.js +++ b/auth-next/github.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - function githubProvider() { // [START auth_github_provider_create] const { GithubAuthProvider } = require("firebase/auth"); @@ -39,7 +31,7 @@ function githubSignInPopup(provider) { // [START auth_github_signin_popup] const { getAuth, signInWithPopup, GithubAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // This gives you a GitHub Access Token. You can use it to access the GitHub API. @@ -66,7 +58,7 @@ function githubSignInRedirectResult() { // [START auth_github_signin_redirect_result] const { getAuth, getRedirectResult, GithubAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); getRedirectResult(auth) .then((result) => { const credential = GithubAuthProvider.credentialFromResult(result); diff --git a/auth-next/google-signin.js b/auth-next/google-signin.js index 4661212b..78b79a61 100644 --- a/auth-next/google-signin.js +++ b/auth-next/google-signin.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/google-signin.md function googleProvider() { @@ -33,7 +25,7 @@ function googleSignInPopup(provider) { // [START auth_google_signin_popup] const { getAuth, signInWithPopup, GoogleAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // This gives you a Google Access Token. You can use it to access the Google API. @@ -59,7 +51,7 @@ function googleSignInRedirectResult() { // [START auth_google_signin_redirect_result] const { getAuth, getRedirectResult, GoogleAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); getRedirectResult(auth) .then((result) => { // This gives you a Google Access Token. You can use it to access Google APIs. @@ -89,7 +81,7 @@ function googleBuildAndSignIn(id_token) { const credential = GoogleAuthProvider.credential(id_token); // Sign in with credential from the Google user. - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithCredential(auth, credential).catch((error) => { // Handle Errors here. const errorCode = error.code; @@ -111,7 +103,7 @@ function onSignIn_wrapper() { // [START auth_google_callback] const { getAuth, onAuthStateChanged, signInWithCredential, GoogleAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); function onSignIn(googleUser) { console.log('Google Auth Response', googleUser); diff --git a/auth-next/index.js b/auth-next/index.js index bf5bec57..9c8168b8 100644 --- a/auth-next/index.js +++ b/auth-next/index.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - // ========================================================================================== // Docs: Snippets in this file are "general purpose" and are used on more than one docs page // ========================================================================================== @@ -43,7 +35,7 @@ function signOut() { // [START auth_sign_out] const { getAuth, signOut } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signOut(auth).then(() => { // Sign-out successful. }).catch((error) => { @@ -56,7 +48,7 @@ function authStateListener() { // [START auth_state_listener] const { getAuth, onAuthStateChanged } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); onAuthStateChanged(auth, (user) => { if (user) { // User is signed in, see docs for a list of available properties @@ -75,7 +67,7 @@ function setLanguageCode() { // [START auth_set_language_code] const { getAuth } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); auth.languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. // firebase.auth().useDeviceLanguage(); @@ -87,7 +79,7 @@ function authWithCredential(credential) { const { getAuth, signInWithCredential } = require("firebase/auth"); // Sign in with the credential from the user. - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithCredential(auth, credential) .then((result) => { // Signed in @@ -108,7 +100,7 @@ function signInRedirect(provider) { // [START auth_signin_redirect] const { getAuth, signInWithRedirect } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithRedirect(auth, provider); // [END auth_signin_redirect] } diff --git a/auth-next/link-multiple-accounts.js b/auth-next/link-multiple-accounts.js index 0c612af9..34c0db58 100644 --- a/auth-next/link-multiple-accounts.js +++ b/auth-next/link-multiple-accounts.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - const MyUserDataRepo = function() {}; MyUserDataRepo.prototype.merge = function(data1, data2) { @@ -47,7 +39,7 @@ function simpleLink(credential) { // [START auth_simple_link] const { getAuth, linkWithCredential } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); linkWithCredential(auth.currentUser, credential) .then((usercred) => { const user = usercred.user; @@ -62,7 +54,7 @@ function anonymousLink(credential) { // [START auth_anonymous_link] const { getAuth, linkWithCredential } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); linkWithCredential(auth.currentUser, credential) .then((usercred) => { const user = usercred.user; @@ -78,7 +70,7 @@ function linkWithPopup() { const { getAuth, linkWithPopup, GoogleAuthProvider } = require("firebase/auth"); const provider = new GoogleAuthProvider(); - const auth = getAuth(firebaseApp); + const auth = getAuth(); linkWithPopup(auth.currentUser, provider).then((result) => { // Accounts successfully linked. const credential = GoogleAuthProvider.credentialFromResult(result); @@ -96,7 +88,7 @@ function linkWithRedirect() { const { getAuth, linkWithRedirect, GoogleAuthProvider } = require("firebase/auth"); const provider = new GoogleAuthProvider(); - const auth = getAuth(firebaseApp); + const auth = getAuth(); linkWithRedirect(auth.currentUser, provider) .then(/* ... */) .catch(/* ... */); @@ -126,7 +118,7 @@ function mergeAccounts(newCredential) { const repo = new MyUserDataRepo(); // Get reference to the currently signed-in user - const auth = getAuth(firebaseApp); + const auth = getAuth(); const prevUser = auth.currentUser; // Get the data which you will want to merge. This should be done now @@ -180,7 +172,7 @@ function unlink(providerId) { // [START auth_unlink_provider] const { getAuth, unlink } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); unlink(auth.currentUser, providerId).then(() => { // Auth provider unlinked from account // ... diff --git a/auth-next/microsoft-oauth.js b/auth-next/microsoft-oauth.js index 0179ffc6..be0abffd 100644 --- a/auth-next/microsoft-oauth.js +++ b/auth-next/microsoft-oauth.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/microsoft-oauth.md function msftCreateProvider() { @@ -47,7 +39,7 @@ function msftSignInPopup(provider) { // [START auth_msft_signin_popup] const { getAuth, signInWithPopup, OAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // User is signed in. @@ -68,7 +60,7 @@ function msftSignInRedirect(provider) { // [START auth_msft_signin_redirect] const { getAuth, signInWithRedirect } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithRedirect(auth, provider); // [END auth_msft_signin_redirect] } @@ -77,7 +69,7 @@ function msftSignInRedirectResult() { // [START auth_msft_signin_redirect_result] const { getAuth, getRedirectResult, OAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); getRedirectResult(auth) .then((result) => { // User is signed in. @@ -99,7 +91,7 @@ function msftLinkWithPopup() { const { getAuth, linkWithPopup, OAuthProvider } = require("firebase/auth"); const provider = new OAuthProvider('microsoft.com'); - const auth = getAuth(firebaseApp); + const auth = getAuth(); linkWithPopup(auth.currentUser, provider) .then((result) => { @@ -122,7 +114,7 @@ function msftReauthPopup() { const { getAuth, reauthenticateWithPopup, OAuthProvider } = require("firebase/auth"); const provider = new OAuthProvider('microsoft.com'); - const auth = getAuth(firebaseApp); + const auth = getAuth(); reauthenticateWithPopup(auth.currentUser, provider) .then((result) => { // User is re-authenticated with fresh tokens minted and diff --git a/auth-next/phone-auth.js b/auth-next/phone-auth.js index 510dd219..cd894c64 100644 --- a/auth-next/phone-auth.js +++ b/auth-next/phone-auth.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - // Mask the global 'window' for this snippet file const window = { recaptchaVerifier: undefined @@ -22,7 +14,7 @@ function recaptchaVerifierInvisible() { // [START auth_phone_recaptcha_verifier_invisible] const { getAuth, RecaptchaVerifier } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); window.recaptchaVerifier = new RecaptchaVerifier('sign-in-button', { 'size': 'invisible', 'callback': (response) => { @@ -37,7 +29,7 @@ function recaptchaVerifierVisible() { // [START auth_phone_recaptcha_verifier_visible] const { getAuth, RecaptchaVerifier } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', { 'size': 'normal', 'callback': (response) => { @@ -56,7 +48,7 @@ function recaptchaVerifierSimple() { // [START auth_phone_recaptcha_verifier_simple] const { getAuth, RecaptchaVerifier } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', {}, auth); // [END auth_phone_recaptcha_verifier_simple] } @@ -85,7 +77,7 @@ function phoneSignIn() { const phoneNumber = getPhoneNumberFromUserInput(); const appVerifier = window.recaptchaVerifier; - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithPhoneNumber(auth, phoneNumber, appVerifier) .then((confirmationResult) => { // SMS sent. Prompt user to type the code from the message, then sign the diff --git a/auth-next/service-worker-sessions.js b/auth-next/service-worker-sessions.js index b9d87cbf..abef386b 100644 --- a/auth-next/service-worker-sessions.js +++ b/auth-next/service-worker-sessions.js @@ -1,21 +1,13 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/service-worker-sessions.md function svcGetIdToken() { // [START auth_svc_get_idtoken] const { getAuth, getIdToken } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); getIdToken(auth.currentUser) .then((idToken) => { // idToken can be passed back to server. @@ -39,7 +31,7 @@ function svcSubscribe(config) { * @return {!Promise} The promise that resolves with an ID token if * available. Otherwise, the promise resolves with null. */ - const auth = getAuth(firebaseApp); + const auth = getAuth(); const getIdTokenPromise = () => { return new Promise((resolve, reject) => { const unsubscribe = onAuthStateChanged(auth, (user) => { @@ -165,7 +157,7 @@ function svcSignInEmail(email, password) { const { getAuth, signInWithEmailAndPassword } = require("firebase/auth"); // Sign in screen. - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithEmailAndPassword(auth, email, password) .then((result) => { // Redirect to profile page after sign-in. The service worker will detect diff --git a/auth-next/twitter.js b/auth-next/twitter.js index 6e204cb3..8024bbe5 100644 --- a/auth-next/twitter.js +++ b/auth-next/twitter.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - function twitterProvider() { // [START auth_twitter_provider_create] const { TwitterAuthProvider } = require("firebase/auth"); @@ -27,7 +19,7 @@ function twitterSignInPopup(provider) { // [START auth_twitter_signin_popup] const { getAuth, signInWithPopup, TwitterAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // This gives you a the Twitter OAuth 1.0 Access Token and Secret. @@ -56,7 +48,7 @@ function twitterSignInRedirectResult() { // [START auth_twitter_signin_redirect_result] const { getAuth, getRedirectResult, TwitterAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); getRedirectResult(auth) .then((result) => { // This gives you a the Twitter OAuth 1.0 Access Token and Secret. diff --git a/auth-next/yahoo-oauth.js b/auth-next/yahoo-oauth.js index e03c9bba..e08150e7 100644 --- a/auth-next/yahoo-oauth.js +++ b/auth-next/yahoo-oauth.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); - // Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/yahoo-oauth.md function yahooProvider() { @@ -40,7 +32,7 @@ function yahooSignInPopup(provider) { // [START auth_yahoo_signin_popup] const { getAuth, signInWithPopup, OAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // IdP data available in result.additionalUserInfo.profile @@ -61,7 +53,7 @@ function yahooSignInRedirect(provider) { // [START auth_yahoo_signin_redirect] const { getAuth, signInWithRedirect } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); signInWithRedirect(auth, provider); // [END auth_yahoo_signin_redirect] } @@ -70,7 +62,7 @@ function yahooSigninRedirectResult() { // [START auth_yahoo_signin_redirect_result] const { getAuth, getRedirectResult, OAuthProvider } = require("firebase/auth"); - const auth = getAuth(firebaseApp); + const auth = getAuth(); getRedirectResult(auth) .then((result) => { // IdP data available in result.additionalUserInfo.profile @@ -92,7 +84,7 @@ function yahooLinkPopup() { const { getAuth, linkWithPopup, OAuthProvider } = require("firebase/auth"); const provider = new OAuthProvider('yahoo.com'); - const auth = getAuth(firebaseApp); + const auth = getAuth(); linkWithPopup(auth.currentUser, provider) .then((result) => { // Yahoo credential is linked to the current user. @@ -114,7 +106,7 @@ function yahooReauthPopup() { const { getAuth, reauthenticateWithPopup, OAuthProvider } = require("firebase/auth"); const provider = new OAuthProvider('yahoo.com'); - const auth = getAuth(firebaseApp); + const auth = getAuth(); reauthenticateWithPopup(auth.currentUser, provider) .then((result) => { // User is re-authenticated with fresh tokens minted and diff --git a/database-next/emulator-suite.js b/database-next/emulator-suite.js index c19f6829..083fea80 100644 --- a/database-next/emulator-suite.js +++ b/database-next/emulator-suite.js @@ -1,19 +1,11 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function onDocumentReady() { // [START rtdb_emulator_connect] const { getDatabase, useDatabaseEmulator } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); if (location.hostname === "localhost") { // Point to the RTDB emulator running on localhost. useDatabaseEmulator(db, "localhost", 9000); @@ -26,7 +18,7 @@ function flushRealtimeDatabase() { const { getDatabase, ref, set } = require("firebase/database"); // With a database Reference, write null to clear the database. - const db = getDatabase(firebaseApp); + const db = getDatabase(); set(ref(db), null); // [END rtdb_emulator_flush] } diff --git a/database-next/index.js b/database-next/index.js index 53c8584d..b0a3400e 100644 --- a/database-next/index.js +++ b/database-next/index.js @@ -1,18 +1,10 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function getReference() { // [START rtdb_get_reference] const { getDatabase } = require("firebase/database"); - const database = getDatabase(firebaseApp); + const database = getDatabase(); // [END rtdb_get_reference] } diff --git a/database-next/lists-of-data.js b/database-next/lists-of-data.js index 8e47c1dd..53afbc08 100644 --- a/database-next/lists-of-data.js +++ b/database-next/lists-of-data.js @@ -1,20 +1,12 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function socialPush() { // [START rtdb_social_push] const { getDatabase, ref, push, set } = require("firebase/database"); // Create a new post reference with an auto-generated id - const db = getDatabase(firebaseApp); + const db = getDatabase(); const postListRef = ref(db, 'posts'); const newPostRef = push(postListRef); set(newPostRef, { @@ -33,7 +25,7 @@ function socialListenChildren() { // [START rtdb_social_listen_children] const { getDatabase, ref, onChildAdded, onChildChanged, onChildRemoved } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); const commentsRef = ref(db, 'post-comments/' + postId); onChildAdded(commentsRef, (data) => { addCommentElement(postElement, data.key, data.val().text, data.val().author); @@ -54,7 +46,7 @@ function socialListenValue() { // [START rtdb_social_listen_value] const { getDatabase, ref, onValue } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); const dbRef = ref(db, '/a/b/c'); onValue(dbRef, (snapshot) => { @@ -74,8 +66,8 @@ function socialMostStarred() { const { getDatabase, ref, query, orderByChild } = require("firebase/database"); const { getAuth } = require("firebase/auth"); - const db = getDatabase(firebaseApp); - const auth = getAuth(firebaseApp); + const db = getDatabase(); + const auth = getAuth(); const myUserId = auth.currentUser.uid; const topUserPostsRef = query(ref(db, 'user-posts/' + myUserId), orderByChild('starCount')); @@ -86,7 +78,7 @@ function socialMostViewed() { // [START rtdb_social_most_viewed] const { getDatabase, ref, query, orderByChild } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); const mostViewedPosts = query(ref(db, 'posts'), orderByChild('metrics/views')); // [END rtdb_social_most_viewed] } @@ -95,7 +87,7 @@ function socialRecent() { // [START rtdb_social_recent] const { getDatabase, ref, query, limitToLast } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); const recentPostsRef = query(ref(db, 'posts'), limitToLast(100)); // [END rtdb_social_recent] } diff --git a/database-next/offline.js b/database-next/offline.js index 49009268..3dd9e22b 100644 --- a/database-next/offline.js +++ b/database-next/offline.js @@ -1,19 +1,11 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function onDisconnectSimple() { // [START rtdb_ondisconnect_simple] const { getDatabase, ref, onDisconnect } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); const presenceRef = ref(db, "disconnectmessage"); // Write a string when this client loses connection onDisconnect(presenceRef).set("I disconnected!"); @@ -23,7 +15,7 @@ function onDisconnectSimple() { function onDisconnectCallback() { const { getDatabase, ref, onDisconnect } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); const presenceRef = ref(db, "disconnectmessage"); // [START rtdb_ondisconnect_callback] @@ -38,7 +30,7 @@ function onDisconnectCallback() { function onDisconnectCancel() { const { getDatabase, ref, onDisconnect } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); const presenceRef = ref(db, "disconnectmessage"); // [START rtdb_ondisconnect_cancel] @@ -53,7 +45,7 @@ function detectConnectionState() { // [START rtdb_detect_connection_state] const { getDatabase, ref, onValue } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); const connectedRef = ref(db, ".info/connected"); onValue(connectedRef, (snap) => { if (snap.val() === true) { @@ -69,7 +61,7 @@ function setServerTimestamp() { // [START rtdb_set_server_timestamp] const { getDatabase, ref, onDisconnect, serverTimestamp } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); const userLastOnlineRef = ref(db, "users/joe/lastOnline"); onDisconnect(userLastOnlineRef).set(serverTimestamp()); // [END rtdb_set_server_timestamp] @@ -79,7 +71,7 @@ function estimateClockSkew() { // [START rtdb_estimate_clock_skew] const { getDatabase, ref, onValue } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); const offsetRef = ref(db, ".info/serverTimeOffset"); onValue(offsetRef, (snap) => { const offset = snap.val(); @@ -94,7 +86,7 @@ function samplePresenceApp() { // Since I can connect from multiple devices or browser tabs, we store each connection instance separately // any time that connectionsRef's value is null (i.e. has no children) I am offline - const db = getDatabase(firebaseApp); + const db = getDatabase(); const myConnectionsRef = ref(db, 'users/joe/connections'); // stores the timestamp of my last disconnect (the last time I was seen online) diff --git a/database-next/read-and-write.js b/database-next/read-and-write.js index db7da0db..717ddeae 100644 --- a/database-next/read-and-write.js +++ b/database-next/read-and-write.js @@ -1,20 +1,12 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function writeUserData_wrapped() { // [START rtdb_write_new_user] - const { getDatabase, ref, set} = require("firebase/database"); + const { getDatabase, ref, set } = require("firebase/database"); function writeUserData(userId, name, email, imageUrl) { - const db = getDatabase(firebaseApp); + const db = getDatabase(); set(ref(db, 'users/' + userId), { username: name, email: email, @@ -29,7 +21,7 @@ function writeUserDataWithCompletion(userId, name, email, imageUrl) { // [START rtdb_write_new_user_completion] const { getDatabase, ref, set } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); set(ref(db, 'users/' + userId), { username: name, email: email, @@ -54,7 +46,7 @@ function socialListenStarCount() { // [START rtdb_social_listen_star_count] const { getDatabase, ref, onValue} = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); const starCountRef = ref(db, 'posts/' + postId + '/starCount'); onValue(starCountRef, (snapshot) => { const data = snapshot.val(); @@ -68,8 +60,8 @@ function socialSingleValueRead() { const { getDatabase, ref, onValue } = require("firebase/database"); const { getAuth } = require("firebase/auth"); - const db = getDatabase(firebaseApp); - const auth = getAuth(firebaseApp); + const db = getDatabase(); + const auth = getAuth(); const userId = auth.currentUser.uid; return onValue(ref(db, '/users/' + userId), (snapshot) => { @@ -86,7 +78,7 @@ function writeNewPost_wrapped() { // [START rtdb_social_write_fan_out] function writeNewPost(uid, username, picture, title, body) { - const db = getDatabase(firebaseApp); + const db = getDatabase(); // A post entry. const postData = { @@ -119,7 +111,7 @@ function socialCompletionCallback() { // [START rtdb_social_completion_callback] const { getDatabase, ref, set } = require("firebase/database"); - const db = getDatabase(firebaseApp); + const db = getDatabase(); set(ref(db, 'users/' + userId), { username: name, email: email, @@ -139,7 +131,7 @@ function toggleStar_wrapped() { const { getDatabase, ref, runTransaction } = require("firebase/database"); function toggleStar(uid) { - const db = getDatabase(firebaseApp); + const db = getDatabase(); const postRef = ref(db, '/posts/foo-bar-123'); runTransaction(postRef, (post) => { @@ -165,7 +157,7 @@ function readOnceWithGet(userId) { // [START rtdb_read_once_get] const { getDatabase, ref, child, get } = require("firebase/database"); - const dbRef = ref(getDatabase(firebaseApp)); + const dbRef = ref(getDatabase()); get(child(dbRef, `users/${userId}`)).then((snapshot) => { if (snapshot.exists()) { console.log(snapshot.val()); diff --git a/firestore-next/emulator-suite.js b/firestore-next/emulator-suite.js index fbbb9599..61463eee 100644 --- a/firestore-next/emulator-suite.js +++ b/firestore-next/emulator-suite.js @@ -1,12 +1,12 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -function onDocumentReady(firebaseApp) { +function onDocumentReady() { // [START fs_emulator_connect] const { getFirestore, useFirestoreEmulator } = require("firebase/firestore"); // firebaseApps previously initialized using initializeApp() - const db = getFirestore(firebaseApp); + const db = getFirestore(); useFirestoreEmulator(db, 'localhost', 8080); // [END fs_emulator_connect] } diff --git a/functions-next/callable.js b/functions-next/callable.js index 4b866cd3..70049563 100644 --- a/functions-next/callable.js +++ b/functions-next/callable.js @@ -1,13 +1,13 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -export function callAddMessage(firebaseApp) { +export function callAddMessage() { const messageText = "Hello, World!"; // [START fb_functions_call_add_message] const { getFunctions, httpsCallable } = require("firebase/functions"); - const functions = getFunctions(firebaseApp); + const functions = getFunctions(); const addMessage = httpsCallable(functions, 'addMessage'); addMessage({ text: messageText }) .then((result) => { @@ -25,7 +25,7 @@ export function callAddMessageError(firebaseApp) { // [START fb_functions_call_add_message_error] const { getFunctions, httpsCallable } = require("firebase/functions"); - const functions = getFunctions(firebaseApp); + const functions = getFunctions(); const addMessage = httpsCallable(functions, 'addMessage'); addMessage({ text: messageText }) .then((result) => { diff --git a/messaging-next/index.js b/messaging-next/index.js index dd800938..491ff84e 100644 --- a/messaging-next/index.js +++ b/messaging-next/index.js @@ -1,19 +1,11 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function getMessagingObject() { // [START messaging_get_messaging_object] const { getMessaging } = require("firebase/messaging"); - const messaging = getMessaging(firebaseApp); + const messaging = getMessaging(); // [END messaging_get_messaging_object] } @@ -25,7 +17,7 @@ function receiveMessage() { // `messaging.onBackgroundMessage` handler. const { getMessaging, onMessage } = require("firebase/messaging"); - const messaging = getMessaging(firebaseApp); + const messaging = getMessaging(); onMessage(messaging, (payload) => { console.log('Message received. ', payload); // ... @@ -39,7 +31,7 @@ function getToken() { // Get registration token. Initially this makes a network call, once retrieved // subsequent calls to getToken will return from cache. - const messaging = getMessaging(firebaseApp); + const messaging = getMessaging(); getToken(messaging, { vapidKey: '' }).then((currentToken) => { if (currentToken) { // Send the token to your server and update the UI if necessary @@ -74,7 +66,7 @@ function deleteToken() { // [START messaging_delete_token] const { getMessaging, deleteToken } = require("firebase/messaging"); - const messaging = getMessaging(firebaseApp); + const messaging = getMessaging(); deleteToken(messaging).then(() => { console.log('Token deleted.'); // ... diff --git a/perf-next/index.js b/perf-next/index.js index 58b70ae7..20f9b4f4 100644 --- a/perf-next/index.js +++ b/perf-next/index.js @@ -1,14 +1,7 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - projectId: '### PROJECT ID ###', - apiKey: '### FIREBASE API KEY ###', - authDomain: '### FIREBASE AUTH DOMAIN ###', -}); -const perf = getInstance(firebaseApp); +const perf = getInstance(); function intialize() { // [START perf_initialize] @@ -29,10 +22,10 @@ function intialize() { // [END perf_initialize] } -export function getInstance(firebaseApp) { +export function getInstance() { // [START perf_get_instance] const { getPerformance } = require("firebase/performance"); - const perf = getPerformance(firebaseApp); + const perf = getPerformance(); // [END perf_get_instance] return perf; diff --git a/remoteconfig-next/index.js b/remoteconfig-next/index.js index 364bcd17..aeeb263a 100644 --- a/remoteconfig-next/index.js +++ b/remoteconfig-next/index.js @@ -1,19 +1,11 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function getInstance() { // [START rc_get_instance] const { getRemoteConfig } = require("firebase/remote-config"); - const remoteConfig = getRemoteConfig(firebaseApp); + const remoteConfig = getRemoteConfig(); // [END rc_get_instance] return remoteConfig; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js index c93b833e..0fc501d9 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js @@ -20,7 +20,7 @@ const params4 = { }; // Log event when a product is added to a wishlist -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'add_to_wishlist', params4); // Log event when a product is added to the cart diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js index 7fc10a6c..0e369459 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js @@ -15,6 +15,6 @@ const params7 = { }; // Log event -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'begin_checkout', params7); // [END analytics_ecommerce_checkout_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js index d4ade3f1..17ea80d1 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js @@ -16,6 +16,6 @@ const params9 = { }; // Log event -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'add_payment_info', params9); // [END analytics_ecommerce_payment_info_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js index 1e0e0e37..a099a1ac 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js @@ -17,7 +17,7 @@ const params12 = { }; // Log event when a promotion is displayed -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'view_promotion', params12); // Log event when a promotion is selected diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js index 28817cd3..ea589cb7 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js @@ -19,6 +19,6 @@ const params10 = { }; // Log event -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'purchase', params10); // [END analytics_ecommerce_purchase_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js index 48984886..f7d1f8f8 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js @@ -24,6 +24,6 @@ const refundedProduct = { params11.items.push(refundedProduct); // Log event -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'refund', params11); // [END analytics_ecommerce_refund_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js index 861c73ea..9bec3f7d 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js @@ -14,6 +14,6 @@ const params6 = { }; // Log event -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'remove_from_cart', params6); // [END analytics_ecommerce_remove_cart_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js index 537220f7..a4e7ec58 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js @@ -14,6 +14,6 @@ const params2 = { }; // Log event -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'select_item', params2); // [END analytics_ecommerce_select_item_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js index d4425db8..d2f2ccaa 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js @@ -16,6 +16,6 @@ const params8 = { }; // Log event -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'add_shipping_info', params8); // [END analytics_ecommerce_shipping_info_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js index 4bb85052..bfe02fd0 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js @@ -25,6 +25,6 @@ const params5 = { }; // Log event when the cart is viewed -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'view_cart', params5); // [END analytics_ecommerce_view_cart_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js index 1fd40596..ebd74763 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js @@ -14,6 +14,6 @@ const params3 = { }; // Log event -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'view_item', params3); // [END analytics_ecommerce_view_item_details_modular] \ No newline at end of file diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js index acc8bf08..c66f0d20 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js @@ -14,6 +14,6 @@ const params1 = { }; // Log event -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'view_item_list', params1); // [END analytics_ecommerce_view_item_list_modular] \ No newline at end of file diff --git a/snippets/analytics-next/index/analytics_initialize.js b/snippets/analytics-next/index/analytics_initialize.js index 8d491090..4fb42cb3 100644 --- a/snippets/analytics-next/index/analytics_initialize.js +++ b/snippets/analytics-next/index/analytics_initialize.js @@ -6,5 +6,5 @@ // [START analytics_initialize_modular] import { getAnalytics } from "firebase/analytics"; -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); // [END analytics_initialize_modular] \ No newline at end of file diff --git a/snippets/analytics-next/index/analytics_log_event.js b/snippets/analytics-next/index/analytics_log_event.js index d4122c71..c5537b5b 100644 --- a/snippets/analytics-next/index/analytics_log_event.js +++ b/snippets/analytics-next/index/analytics_log_event.js @@ -6,6 +6,6 @@ // [START analytics_log_event_modular] import { getAnalytics, logEvent } from "firebase/analytics"; -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'notification_received'); // [END analytics_log_event_modular] \ No newline at end of file diff --git a/snippets/analytics-next/index/analytics_log_event_custom_params.js b/snippets/analytics-next/index/analytics_log_event_custom_params.js index 65de3fb4..122d94d1 100644 --- a/snippets/analytics-next/index/analytics_log_event_custom_params.js +++ b/snippets/analytics-next/index/analytics_log_event_custom_params.js @@ -6,6 +6,6 @@ // [START analytics_log_event_custom_params_modular] import { getAnalytics, logEvent } from "firebase/analytics"; -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'goal_completion', { name: 'lever_puzzle'}); // [END analytics_log_event_custom_params_modular] \ No newline at end of file diff --git a/snippets/analytics-next/index/analytics_log_event_params.js b/snippets/analytics-next/index/analytics_log_event_params.js index 12956c31..86831dbd 100644 --- a/snippets/analytics-next/index/analytics_log_event_params.js +++ b/snippets/analytics-next/index/analytics_log_event_params.js @@ -6,7 +6,7 @@ // [START analytics_log_event_params_modular] import { getAnalytics, logEvent } from "firebase/analytics"; -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); logEvent(analytics, 'select_content', { content_type: 'image', content_id: 'P12453', diff --git a/snippets/analytics-next/index/analytics_set_user_properties.js b/snippets/analytics-next/index/analytics_set_user_properties.js index ca660ab8..b064cdbf 100644 --- a/snippets/analytics-next/index/analytics_set_user_properties.js +++ b/snippets/analytics-next/index/analytics_set_user_properties.js @@ -6,6 +6,6 @@ // [START analytics_set_user_properties_modular] import { getAnalytics, setUserProperties } from "firebase/analytics"; -const analytics = getAnalytics(firebaseApp); +const analytics = getAnalytics(); setUserProperties(analytics, { favorite_food: 'apples' }); // [END analytics_set_user_properties_modular] \ No newline at end of file diff --git a/snippets/auth-next/anonymous/auth_anon_sign_in.js b/snippets/auth-next/anonymous/auth_anon_sign_in.js index 7195632f..b495ec28 100644 --- a/snippets/auth-next/anonymous/auth_anon_sign_in.js +++ b/snippets/auth-next/anonymous/auth_anon_sign_in.js @@ -6,7 +6,7 @@ // [START auth_anon_sign_in_modular] import { getAuth, signInAnonymously } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInAnonymously(auth) .then(() => { // Signed in.. diff --git a/snippets/auth-next/apple/auth_apple_link_facebook.js b/snippets/auth-next/apple/auth_apple_link_facebook.js index 431f2621..a9f116ad 100644 --- a/snippets/auth-next/apple/auth_apple_link_facebook.js +++ b/snippets/auth-next/apple/auth_apple_link_facebook.js @@ -6,7 +6,7 @@ // [START auth_apple_link_facebook_modular] import { getAuth, linkWithPopup, FacebookAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); const provider = new FacebookAuthProvider(); provider.addScope('user_birthday'); diff --git a/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js b/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js index 2023c2cf..5d1b9257 100644 --- a/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js +++ b/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js @@ -7,7 +7,7 @@ import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth"; // Result from Redirect auth flow. -const auth = getAuth(firebaseApp); +const auth = getAuth(); const provider = new OAuthProvider('apple.com'); reauthenticateWithPopup(auth.currentUser, provider) diff --git a/snippets/auth-next/apple/auth_apple_signin_nonce.js b/snippets/auth-next/apple/auth_apple_signin_nonce.js index 7f7dd884..36962b8f 100644 --- a/snippets/auth-next/apple/auth_apple_signin_nonce.js +++ b/snippets/auth-next/apple/auth_apple_signin_nonce.js @@ -6,7 +6,7 @@ // [START auth_apple_signin_nonce_modular] import { getAuth, signInWithCredential, OAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); // Build Firebase credential with the Apple ID token. const provider = new OAuthProvider('apple.com'); diff --git a/snippets/auth-next/apple/auth_apple_signin_popup.js b/snippets/auth-next/apple/auth_apple_signin_popup.js index 1c5cc27f..3fb9436c 100644 --- a/snippets/auth-next/apple/auth_apple_signin_popup.js +++ b/snippets/auth-next/apple/auth_apple_signin_popup.js @@ -6,7 +6,7 @@ // [START auth_apple_signin_popup_modular] import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // The signed-in user info. diff --git a/snippets/auth-next/apple/auth_apple_signin_redirect.js b/snippets/auth-next/apple/auth_apple_signin_redirect.js index e00445f0..9b97a683 100644 --- a/snippets/auth-next/apple/auth_apple_signin_redirect.js +++ b/snippets/auth-next/apple/auth_apple_signin_redirect.js @@ -6,6 +6,6 @@ // [START auth_apple_signin_redirect_modular] import { getAuth, signInWithRedirect } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithRedirect(auth, provider); // [END auth_apple_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/apple/auth_apple_signin_redirect_result.js b/snippets/auth-next/apple/auth_apple_signin_redirect_result.js index 8872d0f7..f0b2d64c 100644 --- a/snippets/auth-next/apple/auth_apple_signin_redirect_result.js +++ b/snippets/auth-next/apple/auth_apple_signin_redirect_result.js @@ -7,7 +7,7 @@ import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; // Result from Redirect auth flow. -const auth = getAuth(firebaseApp); +const auth = getAuth(); getRedirectResult(auth) .then((result) => { const credential = OAuthProvider.credentialFromResult(result); diff --git a/snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js b/snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js index 5a1ce6fe..88b579f9 100644 --- a/snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js +++ b/snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js @@ -6,7 +6,7 @@ // [START auth_set_persistence_none_modular] import { getAuth, setPersistence, signInWithRedirect, inMemoryPersistence, GoogleAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); setPersistence(auth, inMemoryPersistence) .then(() => { const provider = new GoogleAuthProvider(); diff --git a/snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js b/snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js index 26917559..6644370d 100644 --- a/snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js +++ b/snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js @@ -6,7 +6,7 @@ // [START auth_set_persistence_session_modular] import { getAuth, setPersistence, signInWithEmailAndPassword, browserSessionPersistence } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); setPersistence(auth, browserSessionPersistence) .then(() => { // Existing and future Auth states are now persisted in the current diff --git a/snippets/auth-next/cordova/auth_cordova_redirect_result.js b/snippets/auth-next/cordova/auth_cordova_redirect_result.js index d86e7672..f4794507 100644 --- a/snippets/auth-next/cordova/auth_cordova_redirect_result.js +++ b/snippets/auth-next/cordova/auth_cordova_redirect_result.js @@ -6,7 +6,7 @@ // [START auth_cordova_redirect_result_modular] import { getAuth, getRedirectResult, GoogleAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); getRedirectResult(auth) .then((result) => { const credential = GoogleAuthProvider.credentialFromResult(result); diff --git a/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js b/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js index bd7a0360..14084a12 100644 --- a/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js +++ b/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js @@ -6,7 +6,7 @@ // [START auth_cordova_sign_in_redirect_modular] import { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithRedirect(auth, new GoogleAuthProvider()) .then(() => { return getRedirectResult(auth); diff --git a/snippets/auth-next/custom/auth_sign_in_custom.js b/snippets/auth-next/custom/auth_sign_in_custom.js index 018c8b07..3500d6d9 100644 --- a/snippets/auth-next/custom/auth_sign_in_custom.js +++ b/snippets/auth-next/custom/auth_sign_in_custom.js @@ -6,7 +6,7 @@ // [START auth_sign_in_custom_modular] import { getAuth, signInWithCustomToken } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithCustomToken(auth, token) .then((userCredential) => { // Signed in diff --git a/snippets/auth-next/email-link-auth/auth_email_link_link.js b/snippets/auth-next/email-link-auth/auth_email_link_link.js index 8c0147ed..07abe3c8 100644 --- a/snippets/auth-next/email-link-auth/auth_email_link_link.js +++ b/snippets/auth-next/email-link-auth/auth_email_link_link.js @@ -11,7 +11,7 @@ const credential = EmailAuthProvider.credentialWithLink( email, window.location.href); // Link the credential to the current user. -const auth = getAuth(firebaseApp); +const auth = getAuth(); linkWithCredential(auth.currentUser, credential) .then((usercred) => { // The provider is now successfully linked. diff --git a/snippets/auth-next/email-link-auth/auth_email_link_reauth.js b/snippets/auth-next/email-link-auth/auth_email_link_reauth.js index e72b1c24..f6c57144 100644 --- a/snippets/auth-next/email-link-auth/auth_email_link_reauth.js +++ b/snippets/auth-next/email-link-auth/auth_email_link_reauth.js @@ -11,7 +11,7 @@ const credential = EmailAuthProvider.credentialWithLink( email, window.location.href); // Re-authenticate the user with this credential. -const auth = getAuth(firebaseApp); +const auth = getAuth(); reauthenticateWithCredential(auth.currentUser, credential) .then((usercred) => { // The user is now successfully re-authenticated and can execute sensitive diff --git a/snippets/auth-next/email-link-auth/auth_email_link_send.js b/snippets/auth-next/email-link-auth/auth_email_link_send.js index 6fe2c15e..8a3065c8 100644 --- a/snippets/auth-next/email-link-auth/auth_email_link_send.js +++ b/snippets/auth-next/email-link-auth/auth_email_link_send.js @@ -6,7 +6,7 @@ // [START auth_email_link_send_modular] import { getAuth, sendSignInLinkToEmail } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); sendSignInLinkToEmail(auth, email, actionCodeSettings) .then(() => { // The link was successfully sent. Inform the user. diff --git a/snippets/auth-next/email-link-auth/email_link_complete.js b/snippets/auth-next/email-link-auth/email_link_complete.js index af6b28ef..b0da2093 100644 --- a/snippets/auth-next/email-link-auth/email_link_complete.js +++ b/snippets/auth-next/email-link-auth/email_link_complete.js @@ -7,7 +7,7 @@ import { getAuth, isSignInWithEmailLink, signInWithEmailLink } from "firebase/auth"; // Confirm the link is a sign-in with email link. -const auth = getAuth(firebaseApp); +const auth = getAuth(); if (isSignInWithEmailLink(auth, window.location.href)) { // Additional state parameters can also be passed via URL. // This can be used to continue the user's intended action before triggering diff --git a/snippets/auth-next/email-link-auth/email_link_diferentiate.js b/snippets/auth-next/email-link-auth/email_link_diferentiate.js index 53bc1f32..cbbe0e57 100644 --- a/snippets/auth-next/email-link-auth/email_link_diferentiate.js +++ b/snippets/auth-next/email-link-auth/email_link_diferentiate.js @@ -9,7 +9,7 @@ import { getAuth, fetchSignInMethodsForEmail, EmailAuthProvider} from "firebase/ // After asking the user for their email. const email = window.prompt('Please provide your email'); -const auth = getAuth(firebaseApp); +const auth = getAuth(); fetchSignInMethodsForEmail(auth, email) .then((signInMethods) => { // This returns the same array as fetchProvidersForEmail but for email diff --git a/snippets/auth-next/email/auth_send_email_verification.js b/snippets/auth-next/email/auth_send_email_verification.js index a5e310c4..ef0c64b8 100644 --- a/snippets/auth-next/email/auth_send_email_verification.js +++ b/snippets/auth-next/email/auth_send_email_verification.js @@ -6,7 +6,7 @@ // [START auth_send_email_verification_modular] import { getAuth, sendEmailVerification } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); sendEmailVerification(auth.currentUser) .then(() => { // Email verification sent! diff --git a/snippets/auth-next/email/auth_send_password_reset.js b/snippets/auth-next/email/auth_send_password_reset.js index 86458fa1..1b195344 100644 --- a/snippets/auth-next/email/auth_send_password_reset.js +++ b/snippets/auth-next/email/auth_send_password_reset.js @@ -6,7 +6,7 @@ // [START auth_send_password_reset_modular] import { getAuth, sendPasswordResetEmail } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); sendPasswordResetEmail(auth, email) .then(() => { // Password reset email sent! diff --git a/snippets/auth-next/email/auth_signin_password.js b/snippets/auth-next/email/auth_signin_password.js index 43817787..2652af74 100644 --- a/snippets/auth-next/email/auth_signin_password.js +++ b/snippets/auth-next/email/auth_signin_password.js @@ -6,7 +6,7 @@ // [START auth_signin_password_modular] import { getAuth, signInWithEmailAndPassword } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithEmailAndPassword(auth, email, password) .then((userCredential) => { // Signed in diff --git a/snippets/auth-next/email/auth_signup_password.js b/snippets/auth-next/email/auth_signup_password.js index 3a20884c..679bfbb0 100644 --- a/snippets/auth-next/email/auth_signup_password.js +++ b/snippets/auth-next/email/auth_signup_password.js @@ -6,7 +6,7 @@ // [START auth_signup_password_modular] import { getAuth, createUserWithEmailAndPassword } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); createUserWithEmailAndPassword(auth, email, password) .then((userCredential) => { // Signed in diff --git a/snippets/auth-next/emulator-suite/auth_emulator_connect.js b/snippets/auth-next/emulator-suite/auth_emulator_connect.js index e2b805ff..99f222ff 100644 --- a/snippets/auth-next/emulator-suite/auth_emulator_connect.js +++ b/snippets/auth-next/emulator-suite/auth_emulator_connect.js @@ -6,6 +6,6 @@ // [START auth_emulator_connect_modular] import { getAuth, useAuthEmulator } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); useAuthEmulator(auth, "http://localhost:9099"); // [END auth_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/auth-next/facebook/auth_facebook_callback.js b/snippets/auth-next/facebook/auth_facebook_callback.js index 489cabf9..144928d8 100644 --- a/snippets/auth-next/facebook/auth_facebook_callback.js +++ b/snippets/auth-next/facebook/auth_facebook_callback.js @@ -5,7 +5,7 @@ // [START auth_facebook_callback_modular] import { getAuth, onAuthStateChanged, signInWithCredential, signOut, FacebookAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); function checkLoginState(response) { if (response.authResponse) { diff --git a/snippets/auth-next/facebook/auth_facebook_signin_credential.js b/snippets/auth-next/facebook/auth_facebook_signin_credential.js index a5d8e551..84ce9612 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_credential.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_credential.js @@ -7,7 +7,7 @@ import { getAuth, signInWithCredential, FacebookAuthProvider } from "firebase/auth"; // Sign in with the credential from the Facebook user. -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithCredential(auth, credential) .then((result) => { // Signed in diff --git a/snippets/auth-next/facebook/auth_facebook_signin_popup.js b/snippets/auth-next/facebook/auth_facebook_signin_popup.js index 65cc1fd1..164948a2 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_popup.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_popup.js @@ -6,7 +6,7 @@ // [START auth_facebook_signin_popup_modular] import { getAuth, signInWithPopup, FacebookAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // The signed-in user info. diff --git a/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js b/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js index a70191dc..9c2d5e30 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js @@ -6,7 +6,7 @@ // [START auth_facebook_signin_redirect_result_modular] import { getAuth, getRedirectResult, FacebookAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); getRedirectResult(auth) .then((result) => { // This gives you a Facebook Access Token. You can use it to access the Facebook API. diff --git a/snippets/auth-next/github/auth_github_signin_popup.js b/snippets/auth-next/github/auth_github_signin_popup.js index b5ac46a2..5b7a78b1 100644 --- a/snippets/auth-next/github/auth_github_signin_popup.js +++ b/snippets/auth-next/github/auth_github_signin_popup.js @@ -6,7 +6,7 @@ // [START auth_github_signin_popup_modular] import { getAuth, signInWithPopup, GithubAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // This gives you a GitHub Access Token. You can use it to access the GitHub API. diff --git a/snippets/auth-next/github/auth_github_signin_redirect_result.js b/snippets/auth-next/github/auth_github_signin_redirect_result.js index 423440fa..6884ed36 100644 --- a/snippets/auth-next/github/auth_github_signin_redirect_result.js +++ b/snippets/auth-next/github/auth_github_signin_redirect_result.js @@ -6,7 +6,7 @@ // [START auth_github_signin_redirect_result_modular] import { getAuth, getRedirectResult, GithubAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); getRedirectResult(auth) .then((result) => { const credential = GithubAuthProvider.credentialFromResult(result); diff --git a/snippets/auth-next/google-signin/auth_google_build_signin.js b/snippets/auth-next/google-signin/auth_google_build_signin.js index a462cb9e..b6f4bbb9 100644 --- a/snippets/auth-next/google-signin/auth_google_build_signin.js +++ b/snippets/auth-next/google-signin/auth_google_build_signin.js @@ -10,7 +10,7 @@ import { getAuth, signInWithCredential, GoogleAuthProvider } from "firebase/auth const credential = GoogleAuthProvider.credential(id_token); // Sign in with credential from the Google user. -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithCredential(auth, credential).catch((error) => { // Handle Errors here. const errorCode = error.code; diff --git a/snippets/auth-next/google-signin/auth_google_callback.js b/snippets/auth-next/google-signin/auth_google_callback.js index c79fc89f..2c23aa69 100644 --- a/snippets/auth-next/google-signin/auth_google_callback.js +++ b/snippets/auth-next/google-signin/auth_google_callback.js @@ -5,7 +5,7 @@ // [START auth_google_callback_modular] import { getAuth, onAuthStateChanged, signInWithCredential, GoogleAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); function onSignIn(googleUser) { console.log('Google Auth Response', googleUser); diff --git a/snippets/auth-next/google-signin/auth_google_signin_popup.js b/snippets/auth-next/google-signin/auth_google_signin_popup.js index b5763bf8..f74b800d 100644 --- a/snippets/auth-next/google-signin/auth_google_signin_popup.js +++ b/snippets/auth-next/google-signin/auth_google_signin_popup.js @@ -6,7 +6,7 @@ // [START auth_google_signin_popup_modular] import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // This gives you a Google Access Token. You can use it to access the Google API. diff --git a/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js b/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js index 410eae3f..2e91c4c6 100644 --- a/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js +++ b/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js @@ -6,7 +6,7 @@ // [START auth_google_signin_redirect_result_modular] import { getAuth, getRedirectResult, GoogleAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); getRedirectResult(auth) .then((result) => { // This gives you a Google Access Token. You can use it to access Google APIs. diff --git a/snippets/auth-next/index/auth_set_language_code.js b/snippets/auth-next/index/auth_set_language_code.js index de11d4ce..6d4126f9 100644 --- a/snippets/auth-next/index/auth_set_language_code.js +++ b/snippets/auth-next/index/auth_set_language_code.js @@ -6,7 +6,7 @@ // [START auth_set_language_code_modular] import { getAuth } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); auth.languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. // firebase.auth().useDeviceLanguage(); diff --git a/snippets/auth-next/index/auth_sign_out.js b/snippets/auth-next/index/auth_sign_out.js index 9387b791..7360528c 100644 --- a/snippets/auth-next/index/auth_sign_out.js +++ b/snippets/auth-next/index/auth_sign_out.js @@ -6,7 +6,7 @@ // [START auth_sign_out_modular] import { getAuth, signOut } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signOut(auth).then(() => { // Sign-out successful. }).catch((error) => { diff --git a/snippets/auth-next/index/auth_signin_credential.js b/snippets/auth-next/index/auth_signin_credential.js index 6885e033..eccad4e6 100644 --- a/snippets/auth-next/index/auth_signin_credential.js +++ b/snippets/auth-next/index/auth_signin_credential.js @@ -7,7 +7,7 @@ import { getAuth, signInWithCredential } from "firebase/auth"; // Sign in with the credential from the user. -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithCredential(auth, credential) .then((result) => { // Signed in diff --git a/snippets/auth-next/index/auth_signin_redirect.js b/snippets/auth-next/index/auth_signin_redirect.js index 9062ac87..f5187cb3 100644 --- a/snippets/auth-next/index/auth_signin_redirect.js +++ b/snippets/auth-next/index/auth_signin_redirect.js @@ -6,6 +6,6 @@ // [START auth_signin_redirect_modular] import { getAuth, signInWithRedirect } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithRedirect(auth, provider); // [END auth_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/index/auth_state_listener.js b/snippets/auth-next/index/auth_state_listener.js index 04f58e21..4764642b 100644 --- a/snippets/auth-next/index/auth_state_listener.js +++ b/snippets/auth-next/index/auth_state_listener.js @@ -6,7 +6,7 @@ // [START auth_state_listener_modular] import { getAuth, onAuthStateChanged } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); onAuthStateChanged(auth, (user) => { if (user) { // User is signed in, see docs for a list of available properties diff --git a/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js b/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js index fdffb99e..fb3cc1a8 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js +++ b/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js @@ -6,7 +6,7 @@ // [START auth_anonymous_link_modular] import { getAuth, linkWithCredential } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); linkWithCredential(auth.currentUser, credential) .then((usercred) => { const user = usercred.user; diff --git a/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js b/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js index b7ff7374..b531cbc6 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js +++ b/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js @@ -7,7 +7,7 @@ import { getAuth, linkWithPopup, GoogleAuthProvider } from "firebase/auth"; const provider = new GoogleAuthProvider(); -const auth = getAuth(firebaseApp); +const auth = getAuth(); linkWithPopup(auth.currentUser, provider).then((result) => { // Accounts successfully linked. const credential = GoogleAuthProvider.credentialFromResult(result); diff --git a/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js b/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js index 4df66560..fc06ec47 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js +++ b/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js @@ -7,7 +7,7 @@ import { getAuth, linkWithRedirect, GoogleAuthProvider } from "firebase/auth"; const provider = new GoogleAuthProvider(); -const auth = getAuth(firebaseApp); +const auth = getAuth(); linkWithRedirect(auth.currentUser, provider) .then(/* ... */) .catch(/* ... */); diff --git a/snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js b/snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js index 1f7205f2..2525d20a 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js +++ b/snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js @@ -10,7 +10,7 @@ import { getAuth, signInWithCredential, linkWithCredential, OAuthProvider } from const repo = new MyUserDataRepo(); // Get reference to the currently signed-in user -const auth = getAuth(firebaseApp); +const auth = getAuth(); const prevUser = auth.currentUser; // Get the data which you will want to merge. This should be done now diff --git a/snippets/auth-next/link-multiple-accounts/auth_simple_link.js b/snippets/auth-next/link-multiple-accounts/auth_simple_link.js index 4aef5f6d..ca360976 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_simple_link.js +++ b/snippets/auth-next/link-multiple-accounts/auth_simple_link.js @@ -6,7 +6,7 @@ // [START auth_simple_link_modular] import { getAuth, linkWithCredential } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); linkWithCredential(auth.currentUser, credential) .then((usercred) => { const user = usercred.user; diff --git a/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js b/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js index 0140810a..7818cb06 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js +++ b/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js @@ -6,7 +6,7 @@ // [START auth_unlink_provider_modular] import { getAuth, unlink } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); unlink(auth.currentUser, providerId).then(() => { // Auth provider unlinked from account // ... diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js b/snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js index 67a8ba9a..8e4da503 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js @@ -7,7 +7,7 @@ import { getAuth, linkWithPopup, OAuthProvider } from "firebase/auth"; const provider = new OAuthProvider('microsoft.com'); -const auth = getAuth(firebaseApp); +const auth = getAuth(); linkWithPopup(auth.currentUser, provider) .then((result) => { diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js b/snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js index a15c3759..b257ec88 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js @@ -7,7 +7,7 @@ import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth"; const provider = new OAuthProvider('microsoft.com'); -const auth = getAuth(firebaseApp); +const auth = getAuth(); reauthenticateWithPopup(auth.currentUser, provider) .then((result) => { // User is re-authenticated with fresh tokens minted and diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js b/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js index 93c34d0a..2b1fffa9 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js @@ -6,7 +6,7 @@ // [START auth_msft_signin_popup_modular] import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // User is signed in. diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js index 7edec614..7e04a832 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js @@ -6,6 +6,6 @@ // [START auth_msft_signin_redirect_modular] import { getAuth, signInWithRedirect } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithRedirect(auth, provider); // [END auth_msft_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js index 2d624588..3992a4d1 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js @@ -6,7 +6,7 @@ // [START auth_msft_signin_redirect_result_modular] import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); getRedirectResult(auth) .then((result) => { // User is signed in. diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js index 2be4c94b..2ee43e7c 100644 --- a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js @@ -6,7 +6,7 @@ // [START auth_phone_recaptcha_verifier_invisible_modular] import { getAuth, RecaptchaVerifier } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); window.recaptchaVerifier = new RecaptchaVerifier('sign-in-button', { 'size': 'invisible', 'callback': (response) => { diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js index e36af4f5..5a318bce 100644 --- a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js @@ -6,6 +6,6 @@ // [START auth_phone_recaptcha_verifier_simple_modular] import { getAuth, RecaptchaVerifier } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', {}, auth); // [END auth_phone_recaptcha_verifier_simple_modular] \ No newline at end of file diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js index a3f4e28c..4b987ee7 100644 --- a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js @@ -6,7 +6,7 @@ // [START auth_phone_recaptcha_verifier_visible_modular] import { getAuth, RecaptchaVerifier } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', { 'size': 'normal', 'callback': (response) => { diff --git a/snippets/auth-next/phone-auth/auth_phone_signin.js b/snippets/auth-next/phone-auth/auth_phone_signin.js index 1c9ecb69..a7a3f0af 100644 --- a/snippets/auth-next/phone-auth/auth_phone_signin.js +++ b/snippets/auth-next/phone-auth/auth_phone_signin.js @@ -9,7 +9,7 @@ import { getAuth, signInWithPhoneNumber } from "firebase/auth"; const phoneNumber = getPhoneNumberFromUserInput(); const appVerifier = window.recaptchaVerifier; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithPhoneNumber(auth, phoneNumber, appVerifier) .then((confirmationResult) => { // SMS sent. Prompt user to type the code from the message, then sign the diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js b/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js index fbed7d6b..e3a61d07 100644 --- a/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js +++ b/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js @@ -6,7 +6,7 @@ // [START auth_svc_get_idtoken_modular] import { getAuth, getIdToken } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); getIdToken(auth.currentUser) .then((idToken) => { // idToken can be passed back to server. diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js b/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js index 14db554d..a7d6e30b 100644 --- a/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js +++ b/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js @@ -7,7 +7,7 @@ import { getAuth, signInWithEmailAndPassword } from "firebase/auth"; // Sign in screen. -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithEmailAndPassword(auth, email, password) .then((result) => { // Redirect to profile page after sign-in. The service worker will detect diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js b/snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js index c927fc4f..a3bb5c2a 100644 --- a/snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js +++ b/snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js @@ -15,7 +15,7 @@ initializeApp(config); * @return {!Promise} The promise that resolves with an ID token if * available. Otherwise, the promise resolves with null. */ -const auth = getAuth(firebaseApp); +const auth = getAuth(); const getIdTokenPromise = () => { return new Promise((resolve, reject) => { const unsubscribe = onAuthStateChanged(auth, (user) => { diff --git a/snippets/auth-next/twitter/auth_twitter_signin_popup.js b/snippets/auth-next/twitter/auth_twitter_signin_popup.js index d500a504..be2b7f57 100644 --- a/snippets/auth-next/twitter/auth_twitter_signin_popup.js +++ b/snippets/auth-next/twitter/auth_twitter_signin_popup.js @@ -6,7 +6,7 @@ // [START auth_twitter_signin_popup_modular] import { getAuth, signInWithPopup, TwitterAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // This gives you a the Twitter OAuth 1.0 Access Token and Secret. diff --git a/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js b/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js index 5d781644..cfecf9cc 100644 --- a/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js +++ b/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js @@ -6,7 +6,7 @@ // [START auth_twitter_signin_redirect_result_modular] import { getAuth, getRedirectResult, TwitterAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); getRedirectResult(auth) .then((result) => { // This gives you a the Twitter OAuth 1.0 Access Token and Secret. diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js index fbdaaeb1..8f672f6b 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js @@ -7,7 +7,7 @@ import { getAuth, linkWithPopup, OAuthProvider } from "firebase/auth"; const provider = new OAuthProvider('yahoo.com'); -const auth = getAuth(firebaseApp); +const auth = getAuth(); linkWithPopup(auth.currentUser, provider) .then((result) => { // Yahoo credential is linked to the current user. diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js index d14b58e3..b35e162d 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js @@ -7,7 +7,7 @@ import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth"; const provider = new OAuthProvider('yahoo.com'); -const auth = getAuth(firebaseApp); +const auth = getAuth(); reauthenticateWithPopup(auth.currentUser, provider) .then((result) => { // User is re-authenticated with fresh tokens minted and diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js index cad34a24..8c8c2713 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js @@ -6,7 +6,7 @@ // [START auth_yahoo_signin_popup_modular] import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithPopup(auth, provider) .then((result) => { // IdP data available in result.additionalUserInfo.profile diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js index 98ae3029..5acb5687 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js @@ -6,6 +6,6 @@ // [START auth_yahoo_signin_redirect_modular] import { getAuth, signInWithRedirect } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); signInWithRedirect(auth, provider); // [END auth_yahoo_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js index 11be5523..73f69951 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js @@ -6,7 +6,7 @@ // [START auth_yahoo_signin_redirect_result_modular] import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; -const auth = getAuth(firebaseApp); +const auth = getAuth(); getRedirectResult(auth) .then((result) => { // IdP data available in result.additionalUserInfo.profile diff --git a/snippets/database-next/emulator-suite/rtdb_emulator_connect.js b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js index b666d9b1..0015f451 100644 --- a/snippets/database-next/emulator-suite/rtdb_emulator_connect.js +++ b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js @@ -6,7 +6,7 @@ // [START rtdb_emulator_connect_modular] import { getDatabase, useDatabaseEmulator } from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); if (location.hostname === "localhost") { // Point to the RTDB emulator running on localhost. useDatabaseEmulator(db, "localhost", 9000); diff --git a/snippets/database-next/emulator-suite/rtdb_emulator_flush.js b/snippets/database-next/emulator-suite/rtdb_emulator_flush.js index 5f0e3f5c..0476a256 100644 --- a/snippets/database-next/emulator-suite/rtdb_emulator_flush.js +++ b/snippets/database-next/emulator-suite/rtdb_emulator_flush.js @@ -7,6 +7,6 @@ import { getDatabase, ref, set } from "firebase/database"; // With a database Reference, write null to clear the database. -const db = getDatabase(firebaseApp); +const db = getDatabase(); set(ref(db), null); // [END rtdb_emulator_flush_modular] \ No newline at end of file diff --git a/snippets/database-next/index/rtdb_get_reference.js b/snippets/database-next/index/rtdb_get_reference.js index 2e2f31c7..fe16c855 100644 --- a/snippets/database-next/index/rtdb_get_reference.js +++ b/snippets/database-next/index/rtdb_get_reference.js @@ -6,5 +6,5 @@ // [START rtdb_get_reference_modular] import { getDatabase } from "firebase/database"; -const database = getDatabase(firebaseApp); +const database = getDatabase(); // [END rtdb_get_reference_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_listen_children.js b/snippets/database-next/lists-of-data/rtdb_social_listen_children.js index a527edeb..644c0334 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_listen_children.js +++ b/snippets/database-next/lists-of-data/rtdb_social_listen_children.js @@ -6,7 +6,7 @@ // [START rtdb_social_listen_children_modular] import { getDatabase, ref, onChildAdded, onChildChanged, onChildRemoved } from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); const commentsRef = ref(db, 'post-comments/' + postId); onChildAdded(commentsRef, (data) => { addCommentElement(postElement, data.key, data.val().text, data.val().author); diff --git a/snippets/database-next/lists-of-data/rtdb_social_listen_value.js b/snippets/database-next/lists-of-data/rtdb_social_listen_value.js index 7250cc86..938308ad 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_listen_value.js +++ b/snippets/database-next/lists-of-data/rtdb_social_listen_value.js @@ -6,7 +6,7 @@ // [START rtdb_social_listen_value_modular] import { getDatabase, ref, onValue } from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); const dbRef = ref(db, '/a/b/c'); onValue(dbRef, (snapshot) => { diff --git a/snippets/database-next/lists-of-data/rtdb_social_most_starred.js b/snippets/database-next/lists-of-data/rtdb_social_most_starred.js index 96354b52..5c364682 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_most_starred.js +++ b/snippets/database-next/lists-of-data/rtdb_social_most_starred.js @@ -7,8 +7,8 @@ import { getDatabase, ref, query, orderByChild } from "firebase/database"; import { getAuth } from "firebase/auth"; -const db = getDatabase(firebaseApp); -const auth = getAuth(firebaseApp); +const db = getDatabase(); +const auth = getAuth(); const myUserId = auth.currentUser.uid; const topUserPostsRef = query(ref(db, 'user-posts/' + myUserId), orderByChild('starCount')); diff --git a/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js b/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js index 3d661562..784df41e 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js +++ b/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js @@ -6,6 +6,6 @@ // [START rtdb_social_most_viewed_modular] import { getDatabase, ref, query, orderByChild } from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); const mostViewedPosts = query(ref(db, 'posts'), orderByChild('metrics/views')); // [END rtdb_social_most_viewed_modular] \ No newline at end of file diff --git a/snippets/database-next/lists-of-data/rtdb_social_push.js b/snippets/database-next/lists-of-data/rtdb_social_push.js index 313ff67c..c62c0a0a 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_push.js +++ b/snippets/database-next/lists-of-data/rtdb_social_push.js @@ -7,7 +7,7 @@ import { getDatabase, ref, push, set } from "firebase/database"; // Create a new post reference with an auto-generated id -const db = getDatabase(firebaseApp); +const db = getDatabase(); const postListRef = ref(db, 'posts'); const newPostRef = push(postListRef); set(newPostRef, { diff --git a/snippets/database-next/lists-of-data/rtdb_social_recent.js b/snippets/database-next/lists-of-data/rtdb_social_recent.js index a946817f..0f26c486 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_recent.js +++ b/snippets/database-next/lists-of-data/rtdb_social_recent.js @@ -6,6 +6,6 @@ // [START rtdb_social_recent_modular] import { getDatabase, ref, query, limitToLast } from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); const recentPostsRef = query(ref(db, 'posts'), limitToLast(100)); // [END rtdb_social_recent_modular] \ No newline at end of file diff --git a/snippets/database-next/offline/rtdb_detect_connection_state.js b/snippets/database-next/offline/rtdb_detect_connection_state.js index b2bedd44..e37375d2 100644 --- a/snippets/database-next/offline/rtdb_detect_connection_state.js +++ b/snippets/database-next/offline/rtdb_detect_connection_state.js @@ -6,7 +6,7 @@ // [START rtdb_detect_connection_state_modular] import { getDatabase, ref, onValue } from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); const connectedRef = ref(db, ".info/connected"); onValue(connectedRef, (snap) => { if (snap.val() === true) { diff --git a/snippets/database-next/offline/rtdb_estimate_clock_skew.js b/snippets/database-next/offline/rtdb_estimate_clock_skew.js index 0d7fea48..9e4b6f5d 100644 --- a/snippets/database-next/offline/rtdb_estimate_clock_skew.js +++ b/snippets/database-next/offline/rtdb_estimate_clock_skew.js @@ -6,7 +6,7 @@ // [START rtdb_estimate_clock_skew_modular] import { getDatabase, ref, onValue } from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); const offsetRef = ref(db, ".info/serverTimeOffset"); onValue(offsetRef, (snap) => { const offset = snap.val(); diff --git a/snippets/database-next/offline/rtdb_ondisconnect_simple.js b/snippets/database-next/offline/rtdb_ondisconnect_simple.js index 838ab744..da1fdf4f 100644 --- a/snippets/database-next/offline/rtdb_ondisconnect_simple.js +++ b/snippets/database-next/offline/rtdb_ondisconnect_simple.js @@ -6,7 +6,7 @@ // [START rtdb_ondisconnect_simple_modular] import { getDatabase, ref, onDisconnect } from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); const presenceRef = ref(db, "disconnectmessage"); // Write a string when this client loses connection onDisconnect(presenceRef).set("I disconnected!"); diff --git a/snippets/database-next/offline/rtdb_sample_presence_app.js b/snippets/database-next/offline/rtdb_sample_presence_app.js index e093238e..504f396f 100644 --- a/snippets/database-next/offline/rtdb_sample_presence_app.js +++ b/snippets/database-next/offline/rtdb_sample_presence_app.js @@ -8,7 +8,7 @@ import { getDatabase, ref, onValue, push, onDisconnect, set, serverTimestamp } f // Since I can connect from multiple devices or browser tabs, we store each connection instance separately // any time that connectionsRef's value is null (i.e. has no children) I am offline -const db = getDatabase(firebaseApp); +const db = getDatabase(); const myConnectionsRef = ref(db, 'users/joe/connections'); // stores the timestamp of my last disconnect (the last time I was seen online) diff --git a/snippets/database-next/offline/rtdb_set_server_timestamp.js b/snippets/database-next/offline/rtdb_set_server_timestamp.js index 14850121..4a1a219b 100644 --- a/snippets/database-next/offline/rtdb_set_server_timestamp.js +++ b/snippets/database-next/offline/rtdb_set_server_timestamp.js @@ -6,7 +6,7 @@ // [START rtdb_set_server_timestamp_modular] import { getDatabase, ref, onDisconnect, serverTimestamp } from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); const userLastOnlineRef = ref(db, "users/joe/lastOnline"); onDisconnect(userLastOnlineRef).set(serverTimestamp()); // [END rtdb_set_server_timestamp_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_read_once_get.js b/snippets/database-next/read-and-write/rtdb_read_once_get.js index 13799f3a..ec618da0 100644 --- a/snippets/database-next/read-and-write/rtdb_read_once_get.js +++ b/snippets/database-next/read-and-write/rtdb_read_once_get.js @@ -6,7 +6,7 @@ // [START rtdb_read_once_get_modular] import { getDatabase, ref, child, get } from "firebase/database"; -const dbRef = ref(getDatabase(firebaseApp)); +const dbRef = ref(getDatabase()); get(child(dbRef, `users/${userId}`)).then((snapshot) => { if (snapshot.exists()) { console.log(snapshot.val()); diff --git a/snippets/database-next/read-and-write/rtdb_social_completion_callback.js b/snippets/database-next/read-and-write/rtdb_social_completion_callback.js index cb22a488..483dd962 100644 --- a/snippets/database-next/read-and-write/rtdb_social_completion_callback.js +++ b/snippets/database-next/read-and-write/rtdb_social_completion_callback.js @@ -6,7 +6,7 @@ // [START rtdb_social_completion_callback_modular] import { getDatabase, ref, set } from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); set(ref(db, 'users/' + userId), { username: name, email: email, diff --git a/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js b/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js index 3a7c7e85..3f7f498b 100644 --- a/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js +++ b/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js @@ -6,7 +6,7 @@ // [START rtdb_social_listen_star_count_modular] import { getDatabase, ref, onValue} from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); const starCountRef = ref(db, 'posts/' + postId + '/starCount'); onValue(starCountRef, (snapshot) => { const data = snapshot.val(); diff --git a/snippets/database-next/read-and-write/rtdb_social_single_value_read.js b/snippets/database-next/read-and-write/rtdb_social_single_value_read.js index 5e68d8c1..276bdfd3 100644 --- a/snippets/database-next/read-and-write/rtdb_social_single_value_read.js +++ b/snippets/database-next/read-and-write/rtdb_social_single_value_read.js @@ -7,8 +7,8 @@ import { getDatabase, ref, onValue } from "firebase/database"; import { getAuth } from "firebase/auth"; -const db = getDatabase(firebaseApp); -const auth = getAuth(firebaseApp); +const db = getDatabase(); +const auth = getAuth(); const userId = auth.currentUser.uid; return onValue(ref(db, '/users/' + userId), (snapshot) => { diff --git a/snippets/database-next/read-and-write/rtdb_social_star_transaction.js b/snippets/database-next/read-and-write/rtdb_social_star_transaction.js index 9f0679a8..af817f0c 100644 --- a/snippets/database-next/read-and-write/rtdb_social_star_transaction.js +++ b/snippets/database-next/read-and-write/rtdb_social_star_transaction.js @@ -7,7 +7,7 @@ import { getDatabase, ref, runTransaction } from "firebase/database"; function toggleStar(uid) { - const db = getDatabase(firebaseApp); + const db = getDatabase(); const postRef = ref(db, '/posts/foo-bar-123'); runTransaction(postRef, (post) => { diff --git a/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js b/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js index d51a23eb..a87824e9 100644 --- a/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js +++ b/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js @@ -5,7 +5,7 @@ // [START rtdb_social_write_fan_out_modular] function writeNewPost(uid, username, picture, title, body) { - const db = getDatabase(firebaseApp); + const db = getDatabase(); // A post entry. const postData = { diff --git a/snippets/database-next/read-and-write/rtdb_write_new_user.js b/snippets/database-next/read-and-write/rtdb_write_new_user.js index 85f0ad83..85ecc9f4 100644 --- a/snippets/database-next/read-and-write/rtdb_write_new_user.js +++ b/snippets/database-next/read-and-write/rtdb_write_new_user.js @@ -4,10 +4,10 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_write_new_user_modular] -import { getDatabase, ref, set} from "firebase/database"; +import { getDatabase, ref, set } from "firebase/database"; function writeUserData(userId, name, email, imageUrl) { - const db = getDatabase(firebaseApp); + const db = getDatabase(); set(ref(db, 'users/' + userId), { username: name, email: email, diff --git a/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js b/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js index 41dffc81..b6e0dacb 100644 --- a/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js +++ b/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js @@ -6,7 +6,7 @@ // [START rtdb_write_new_user_completion_modular] import { getDatabase, ref, set } from "firebase/database"; -const db = getDatabase(firebaseApp); +const db = getDatabase(); set(ref(db, 'users/' + userId), { username: name, email: email, diff --git a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js index f0984d8b..140f6a09 100644 --- a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js +++ b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js @@ -7,6 +7,6 @@ import { getFirestore, useFirestoreEmulator } from "firebase/firestore"; // firebaseApps previously initialized using initializeApp() -const db = getFirestore(firebaseApp); +const db = getFirestore(); useFirestoreEmulator(db, 'localhost', 8080); // [END fs_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/functions-next/callable/fb_functions_call_add_message.js b/snippets/functions-next/callable/fb_functions_call_add_message.js index c2e1b34f..12d4d242 100644 --- a/snippets/functions-next/callable/fb_functions_call_add_message.js +++ b/snippets/functions-next/callable/fb_functions_call_add_message.js @@ -6,7 +6,7 @@ // [START fb_functions_call_add_message_modular] import { getFunctions, httpsCallable } from "firebase/functions"; -const functions = getFunctions(firebaseApp); +const functions = getFunctions(); const addMessage = httpsCallable(functions, 'addMessage'); addMessage({ text: messageText }) .then((result) => { diff --git a/snippets/functions-next/callable/fb_functions_call_add_message_error.js b/snippets/functions-next/callable/fb_functions_call_add_message_error.js index e5186ea9..3a34c845 100644 --- a/snippets/functions-next/callable/fb_functions_call_add_message_error.js +++ b/snippets/functions-next/callable/fb_functions_call_add_message_error.js @@ -6,7 +6,7 @@ // [START fb_functions_call_add_message_error_modular] import { getFunctions, httpsCallable } from "firebase/functions"; -const functions = getFunctions(firebaseApp); +const functions = getFunctions(); const addMessage = httpsCallable(functions, 'addMessage'); addMessage({ text: messageText }) .then((result) => { diff --git a/snippets/messaging-next/index/messaging_delete_token.js b/snippets/messaging-next/index/messaging_delete_token.js index c6e1bf9e..f8d6ef63 100644 --- a/snippets/messaging-next/index/messaging_delete_token.js +++ b/snippets/messaging-next/index/messaging_delete_token.js @@ -6,7 +6,7 @@ // [START messaging_delete_token_modular] import { getMessaging, deleteToken } from "firebase/messaging"; -const messaging = getMessaging(firebaseApp); +const messaging = getMessaging(); deleteToken(messaging).then(() => { console.log('Token deleted.'); // ... diff --git a/snippets/messaging-next/index/messaging_get_messaging_object.js b/snippets/messaging-next/index/messaging_get_messaging_object.js index 5e75a7a5..5dc88c68 100644 --- a/snippets/messaging-next/index/messaging_get_messaging_object.js +++ b/snippets/messaging-next/index/messaging_get_messaging_object.js @@ -6,5 +6,5 @@ // [START messaging_get_messaging_object_modular] import { getMessaging } from "firebase/messaging"; -const messaging = getMessaging(firebaseApp); +const messaging = getMessaging(); // [END messaging_get_messaging_object_modular] \ No newline at end of file diff --git a/snippets/messaging-next/index/messaging_get_token.js b/snippets/messaging-next/index/messaging_get_token.js index 01773b6d..f1f4b3aa 100644 --- a/snippets/messaging-next/index/messaging_get_token.js +++ b/snippets/messaging-next/index/messaging_get_token.js @@ -8,7 +8,7 @@ import { getMessaging, getToken } from "firebase/messaging"; // Get registration token. Initially this makes a network call, once retrieved // subsequent calls to getToken will return from cache. -const messaging = getMessaging(firebaseApp); +const messaging = getMessaging(); getToken(messaging, { vapidKey: '' }).then((currentToken) => { if (currentToken) { // Send the token to your server and update the UI if necessary diff --git a/snippets/messaging-next/index/messaging_receive_message.js b/snippets/messaging-next/index/messaging_receive_message.js index c95d1be4..94c3864d 100644 --- a/snippets/messaging-next/index/messaging_receive_message.js +++ b/snippets/messaging-next/index/messaging_receive_message.js @@ -10,7 +10,7 @@ // `messaging.onBackgroundMessage` handler. import { getMessaging, onMessage } from "firebase/messaging"; -const messaging = getMessaging(firebaseApp); +const messaging = getMessaging(); onMessage(messaging, (payload) => { console.log('Message received. ', payload); // ... diff --git a/snippets/perf-next/index/perf_get_instance.js b/snippets/perf-next/index/perf_get_instance.js index c17d5103..cbee11e6 100644 --- a/snippets/perf-next/index/perf_get_instance.js +++ b/snippets/perf-next/index/perf_get_instance.js @@ -5,5 +5,5 @@ // [START perf_get_instance_modular] import { getPerformance } from "firebase/performance"; -const perf = getPerformance(firebaseApp); +const perf = getPerformance(); // [END perf_get_instance_modular] \ No newline at end of file diff --git a/snippets/remoteconfig-next/index/rc_get_instance.js b/snippets/remoteconfig-next/index/rc_get_instance.js index e20bd5a9..7d59bf9d 100644 --- a/snippets/remoteconfig-next/index/rc_get_instance.js +++ b/snippets/remoteconfig-next/index/rc_get_instance.js @@ -6,5 +6,5 @@ // [START rc_get_instance_modular] import { getRemoteConfig } from "firebase/remote-config"; -const remoteConfig = getRemoteConfig(firebaseApp); +const remoteConfig = getRemoteConfig(); // [END rc_get_instance_modular] \ No newline at end of file diff --git a/snippets/storage-next/create-reference/storage_create_ref.js b/snippets/storage-next/create-reference/storage_create_ref.js index f69cc959..eb27bacb 100644 --- a/snippets/storage-next/create-reference/storage_create_ref.js +++ b/snippets/storage-next/create-reference/storage_create_ref.js @@ -7,7 +7,7 @@ import { getStorage, ref } from "firebase/storage"; // Get a reference to the storage service, which is used to create references in your storage bucket -const storage = getStorage(firebaseApp); +const storage = getStorage(); // Create a storage reference from our storage service const storageRef = ref(storage); diff --git a/snippets/storage-next/create-reference/storage_create_ref_child.js b/snippets/storage-next/create-reference/storage_create_ref_child.js index ded271e0..53b6834c 100644 --- a/snippets/storage-next/create-reference/storage_create_ref_child.js +++ b/snippets/storage-next/create-reference/storage_create_ref_child.js @@ -6,7 +6,7 @@ // [START storage_create_ref_child_modular] import { getStorage, ref } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); // Create a child reference const imagesRef = ref(storage, 'images'); diff --git a/snippets/storage-next/create-reference/storage_navigate_ref.js b/snippets/storage-next/create-reference/storage_navigate_ref.js index 3cdc6b6d..00a9e53f 100644 --- a/snippets/storage-next/create-reference/storage_navigate_ref.js +++ b/snippets/storage-next/create-reference/storage_navigate_ref.js @@ -6,7 +6,7 @@ // [START storage_navigate_ref_modular] import { getStorage, ref } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); const spaceRef = ref(storage, 'images/space.jpg'); // Parent allows us to move to the parent of a reference diff --git a/snippets/storage-next/create-reference/storage_navigate_ref_chain.js b/snippets/storage-next/create-reference/storage_navigate_ref_chain.js index 93607b72..e0f2a056 100644 --- a/snippets/storage-next/create-reference/storage_navigate_ref_chain.js +++ b/snippets/storage-next/create-reference/storage_navigate_ref_chain.js @@ -6,7 +6,7 @@ // [START storage_navigate_ref_chain_modular] import { getStorage, ref } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); const spaceRef = ref(storage, 'images/space.jpg'); // References can be chained together multiple times diff --git a/snippets/storage-next/create-reference/storage_ref_full_example.js b/snippets/storage-next/create-reference/storage_ref_full_example.js index 0869f09c..3c9f94c6 100644 --- a/snippets/storage-next/create-reference/storage_ref_full_example.js +++ b/snippets/storage-next/create-reference/storage_ref_full_example.js @@ -6,7 +6,7 @@ // [START storage_ref_full_example_modular] import { getStorage, ref } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); // Points to the root reference const storageRef = ref(storage); diff --git a/snippets/storage-next/create-reference/storage_ref_properties.js b/snippets/storage-next/create-reference/storage_ref_properties.js index 4707b931..494817ea 100644 --- a/snippets/storage-next/create-reference/storage_ref_properties.js +++ b/snippets/storage-next/create-reference/storage_ref_properties.js @@ -6,7 +6,7 @@ // [START storage_ref_properties_modular] import { getStorage, ref } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); const spaceRef = ref(storage, 'images/space.jpg'); // Reference's path is: 'images/space.jpg' diff --git a/snippets/storage-next/delete-files/storage_delete_file.js b/snippets/storage-next/delete-files/storage_delete_file.js index be582722..86520968 100644 --- a/snippets/storage-next/delete-files/storage_delete_file.js +++ b/snippets/storage-next/delete-files/storage_delete_file.js @@ -6,7 +6,7 @@ // [START storage_delete_file_modular] import { getStorage, ref, deleteObject } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); // Create a reference to the file to delete const desertRef = ref(storage, 'images/desert.jpg'); diff --git a/snippets/storage-next/download-files/storage_download_create_ref.js b/snippets/storage-next/download-files/storage_download_create_ref.js index 5a17307d..bf12aaa9 100644 --- a/snippets/storage-next/download-files/storage_download_create_ref.js +++ b/snippets/storage-next/download-files/storage_download_create_ref.js @@ -7,7 +7,7 @@ import { getStorage, ref } from "firebase/storage"; // Create a reference with an initial file path and name -const storage = getStorage(firebaseApp); +const storage = getStorage(); const pathReference = ref(storage, 'images/stars.jpg'); // Create a reference from a Google Cloud Storage URI diff --git a/snippets/storage-next/download-files/storage_download_full_example.js b/snippets/storage-next/download-files/storage_download_full_example.js index 126ce2ea..4b66880e 100644 --- a/snippets/storage-next/download-files/storage_download_full_example.js +++ b/snippets/storage-next/download-files/storage_download_full_example.js @@ -7,7 +7,7 @@ import { getStorage, ref, getDownloadURL } from "firebase/storage"; // Create a reference to the file we want to download -const storage = getStorage(firebaseApp); +const storage = getStorage(); const starsRef = ref(storage, 'images/stars.jpg'); // Get the download URL diff --git a/snippets/storage-next/download-files/storage_download_via_url.js b/snippets/storage-next/download-files/storage_download_via_url.js index 50be6f65..0e45cada 100644 --- a/snippets/storage-next/download-files/storage_download_via_url.js +++ b/snippets/storage-next/download-files/storage_download_via_url.js @@ -6,7 +6,7 @@ // [START storage_download_via_url_modular] import { getStorage, ref, getDownloadURL } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); getDownloadURL(ref(storage, 'images/stars.jpg')) .then((url) => { // `url` is the download URL for 'images/stars.jpg' diff --git a/snippets/storage-next/file-metadata/storage_delete_metadata.js b/snippets/storage-next/file-metadata/storage_delete_metadata.js index 927e4be8..c6b2ece3 100644 --- a/snippets/storage-next/file-metadata/storage_delete_metadata.js +++ b/snippets/storage-next/file-metadata/storage_delete_metadata.js @@ -6,7 +6,7 @@ // [START storage_delete_metadata_modular] import { getStorage, ref, updateMetadata } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); const forestRef = ref(storage, 'images/forest.jpg'); // Create file metadata with property to delete diff --git a/snippets/storage-next/file-metadata/storage_get_metadata.js b/snippets/storage-next/file-metadata/storage_get_metadata.js index 8bc462f1..e77444db 100644 --- a/snippets/storage-next/file-metadata/storage_get_metadata.js +++ b/snippets/storage-next/file-metadata/storage_get_metadata.js @@ -7,7 +7,7 @@ import { getStorage, ref, getMetadata } from "firebase/storage"; // Create a reference to the file whose metadata we want to retrieve -const storage = getStorage(firebaseApp); +const storage = getStorage(); const forestRef = ref(storage, 'images/forest.jpg'); // Get metadata properties diff --git a/snippets/storage-next/file-metadata/storage_update_metadata.js b/snippets/storage-next/file-metadata/storage_update_metadata.js index 97cacc4b..fd9d6183 100644 --- a/snippets/storage-next/file-metadata/storage_update_metadata.js +++ b/snippets/storage-next/file-metadata/storage_update_metadata.js @@ -7,7 +7,7 @@ import { getStorage, ref, updateMetadata } from "firebase/storage"; // Create a reference to the file whose metadata we want to change -const storage = getStorage(firebaseApp); +const storage = getStorage(); const forestRef = ref(storage, 'images/forest.jpg'); // Create file metadata to update diff --git a/snippets/storage-next/index/storage_multiple_buckets.js b/snippets/storage-next/index/storage_multiple_buckets.js index 83c3770e..1022299b 100644 --- a/snippets/storage-next/index/storage_multiple_buckets.js +++ b/snippets/storage-next/index/storage_multiple_buckets.js @@ -4,8 +4,10 @@ // To make edits to the snippets in this file, please edit the source // [START storage_multiple_buckets_modular] +import { getApp } from "firebase/app"; import { getStorage } from "firebase/storage"; // Get a non-default Storage bucket +const firebaseApp = getApp(); const storage = getStorage(firebaseApp, "gs://my-custom-bucket"); // [END storage_multiple_buckets_modular] \ No newline at end of file diff --git a/snippets/storage-next/index/storage_on_complete.js b/snippets/storage-next/index/storage_on_complete.js index c0c615ff..aa3edca8 100644 --- a/snippets/storage-next/index/storage_on_complete.js +++ b/snippets/storage-next/index/storage_on_complete.js @@ -6,7 +6,7 @@ // [START storage_on_complete_modular] import { getStorage, ref, uploadBytesResumable, getDownloadURL } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); const imageRef = ref(storage, 'images/' + file.name); uploadBytesResumable(imageRef, file, metadata) .then((snapshot) => { diff --git a/snippets/storage-next/list-files/storage_list_all.js b/snippets/storage-next/list-files/storage_list_all.js index 9f794ca4..1adf935a 100644 --- a/snippets/storage-next/list-files/storage_list_all.js +++ b/snippets/storage-next/list-files/storage_list_all.js @@ -6,7 +6,7 @@ // [START storage_list_all_modular] import { getStorage, ref, listAll } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); // Create a reference under which you want to list const listRef = ref(storage, 'files/uid'); diff --git a/snippets/storage-next/list-files/storage_list_paginate.js b/snippets/storage-next/list-files/storage_list_paginate.js index 4415ccdc..d04cd1d3 100644 --- a/snippets/storage-next/list-files/storage_list_paginate.js +++ b/snippets/storage-next/list-files/storage_list_paginate.js @@ -8,7 +8,7 @@ import { getStorage, ref, list } from "firebase/storage"; async function pageTokenExample(){ // Create a reference under which you want to list - const storage = getStorage(firebaseApp); + const storage = getStorage(); const listRef = ref(storage, 'files/uid'); // Fetch the first page of 100. diff --git a/snippets/storage-next/upload-files/storage_manage_uploads.js b/snippets/storage-next/upload-files/storage_manage_uploads.js index 476503bb..2623e8a1 100644 --- a/snippets/storage-next/upload-files/storage_manage_uploads.js +++ b/snippets/storage-next/upload-files/storage_manage_uploads.js @@ -6,7 +6,7 @@ // [START storage_manage_uploads_modular] import { getStorage, ref, uploadBytesResumable } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); const storageRef = ref(storage, 'images/mountains.jpg'); // Upload the file and metadata diff --git a/snippets/storage-next/upload-files/storage_monitor_upload.js b/snippets/storage-next/upload-files/storage_monitor_upload.js index f6d81935..101f509a 100644 --- a/snippets/storage-next/upload-files/storage_monitor_upload.js +++ b/snippets/storage-next/upload-files/storage_monitor_upload.js @@ -6,7 +6,7 @@ // [START storage_monitor_upload_modular] import { getStorage, ref, uploadBytesResumable, getDownloadURL } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); const storageRef = ref(storage, 'images/rivers.jpg'); const uploadTask = uploadBytesResumable(storageRef, file); diff --git a/snippets/storage-next/upload-files/storage_upload_blob.js b/snippets/storage-next/upload-files/storage_upload_blob.js index 11970dea..c33593cb 100644 --- a/snippets/storage-next/upload-files/storage_upload_blob.js +++ b/snippets/storage-next/upload-files/storage_upload_blob.js @@ -6,7 +6,7 @@ // [START storage_upload_blob_modular] import { getStorage, ref, uploadBytes } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); const storageRef = ref(storage, 'some-child'); // 'file' comes from the Blob or File API diff --git a/snippets/storage-next/upload-files/storage_upload_bytes.js b/snippets/storage-next/upload-files/storage_upload_bytes.js index aa906060..ebf12e66 100644 --- a/snippets/storage-next/upload-files/storage_upload_bytes.js +++ b/snippets/storage-next/upload-files/storage_upload_bytes.js @@ -6,7 +6,7 @@ // [START storage_upload_bytes_modular] import { getStorage, ref, uploadBytes } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); const storageRef = ref(storage, 'some-child'); const bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21]); diff --git a/snippets/storage-next/upload-files/storage_upload_handle_error.js b/snippets/storage-next/upload-files/storage_upload_handle_error.js index 3baa5758..434fc230 100644 --- a/snippets/storage-next/upload-files/storage_upload_handle_error.js +++ b/snippets/storage-next/upload-files/storage_upload_handle_error.js @@ -6,7 +6,7 @@ // [START storage_upload_handle_error_modular] import { getStorage, ref, uploadBytesResumable, getDownloadURL } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); // Create the file metadata /** @type {any} */ diff --git a/snippets/storage-next/upload-files/storage_upload_metadata.js b/snippets/storage-next/upload-files/storage_upload_metadata.js index 6632cfb6..1ac39783 100644 --- a/snippets/storage-next/upload-files/storage_upload_metadata.js +++ b/snippets/storage-next/upload-files/storage_upload_metadata.js @@ -6,7 +6,7 @@ // [START storage_upload_metadata_modular] import { getStorage, ref, uploadBytes } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); const storageRef = ref(storage, 'images/mountains.jpg'); // Create file metadata including the content type diff --git a/snippets/storage-next/upload-files/storage_upload_ref.js b/snippets/storage-next/upload-files/storage_upload_ref.js index 820b2632..e776120d 100644 --- a/snippets/storage-next/upload-files/storage_upload_ref.js +++ b/snippets/storage-next/upload-files/storage_upload_ref.js @@ -7,7 +7,7 @@ import { getStorage, ref } from "firebase/storage"; // Create a root reference -const storage = getStorage(firebaseApp); +const storage = getStorage(); // Create a reference to 'mountains.jpg' const mountainsRef = ref(storage, 'mountains.jpg'); diff --git a/snippets/storage-next/upload-files/storage_upload_string.js b/snippets/storage-next/upload-files/storage_upload_string.js index 80b8aaa3..ce0d4736 100644 --- a/snippets/storage-next/upload-files/storage_upload_string.js +++ b/snippets/storage-next/upload-files/storage_upload_string.js @@ -6,7 +6,7 @@ // [START storage_upload_string_modular] import { getStorage, ref, uploadString } from "firebase/storage"; -const storage = getStorage(firebaseApp); +const storage = getStorage(); const storageRef = ref(storage, 'some-child'); // Raw string is the default if no format is provided diff --git a/storage-next/create-reference.js b/storage-next/create-reference.js index eae1ff4f..47a6e227 100644 --- a/storage-next/create-reference.js +++ b/storage-next/create-reference.js @@ -1,20 +1,12 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function createRef() { // [START storage_create_ref] const { getStorage, ref } = require("firebase/storage"); // Get a reference to the storage service, which is used to create references in your storage bucket - const storage = getStorage(firebaseApp); + const storage = getStorage(); // Create a storage reference from our storage service const storageRef = ref(storage); @@ -25,7 +17,7 @@ function createRefChild() { // [START storage_create_ref_child] const { getStorage, ref } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); // Create a child reference const imagesRef = ref(storage, 'images'); @@ -42,7 +34,7 @@ function navigateRef() { // [START storage_navigate_ref] const { getStorage, ref } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); const spaceRef = ref(storage, 'images/space.jpg'); // Parent allows us to move to the parent of a reference @@ -59,7 +51,7 @@ function navigateRefChain() { // [START storage_navigate_ref_chain] const { getStorage, ref } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); const spaceRef = ref(storage, 'images/space.jpg'); // References can be chained together multiple times @@ -75,7 +67,7 @@ function refProperties() { // [START storage_ref_properties] const { getStorage, ref } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); const spaceRef = ref(storage, 'images/space.jpg'); // Reference's path is: 'images/space.jpg' @@ -95,7 +87,7 @@ function refFullExample() { // [START storage_ref_full_example] const { getStorage, ref } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); // Points to the root reference const storageRef = ref(storage); diff --git a/storage-next/delete-files.js b/storage-next/delete-files.js index d5e640b5..767a26f2 100644 --- a/storage-next/delete-files.js +++ b/storage-next/delete-files.js @@ -1,19 +1,11 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function deleteFile() { // [START storage_delete_file] const { getStorage, ref, deleteObject } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); // Create a reference to the file to delete const desertRef = ref(storage, 'images/desert.jpg'); diff --git a/storage-next/download-files.js b/storage-next/download-files.js index 5cfec855..6e94e63a 100644 --- a/storage-next/download-files.js +++ b/storage-next/download-files.js @@ -1,20 +1,12 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function downloadCreateRef() { // [START storage_download_create_ref] const { getStorage, ref } = require("firebase/storage"); // Create a reference with an initial file path and name - const storage = getStorage(firebaseApp); + const storage = getStorage(); const pathReference = ref(storage, 'images/stars.jpg'); // Create a reference from a Google Cloud Storage URI @@ -30,7 +22,7 @@ function downloadViaUrl() { // [START storage_download_via_url] const { getStorage, ref, getDownloadURL } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); getDownloadURL(ref(storage, 'images/stars.jpg')) .then((url) => { // `url` is the download URL for 'images/stars.jpg' @@ -59,7 +51,7 @@ function downloadFullExample() { const { getStorage, ref, getDownloadURL } = require("firebase/storage"); // Create a reference to the file we want to download - const storage = getStorage(firebaseApp); + const storage = getStorage(); const starsRef = ref(storage, 'images/stars.jpg'); // Get the download URL diff --git a/storage-next/file-metadata.js b/storage-next/file-metadata.js index 13624cc6..c45827cd 100644 --- a/storage-next/file-metadata.js +++ b/storage-next/file-metadata.js @@ -1,20 +1,12 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function getMetadata() { // [START storage_get_metadata] const { getStorage, ref, getMetadata } = require("firebase/storage"); // Create a reference to the file whose metadata we want to retrieve - const storage = getStorage(firebaseApp); + const storage = getStorage(); const forestRef = ref(storage, 'images/forest.jpg'); // Get metadata properties @@ -33,7 +25,7 @@ function updateMetadata() { const { getStorage, ref, updateMetadata } = require("firebase/storage"); // Create a reference to the file whose metadata we want to change - const storage = getStorage(firebaseApp); + const storage = getStorage(); const forestRef = ref(storage, 'images/forest.jpg'); // Create file metadata to update @@ -56,7 +48,7 @@ function deleteMetadata() { // [START storage_delete_metadata] const { getStorage, ref, updateMetadata } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); const forestRef = ref(storage, 'images/forest.jpg'); // Create file metadata with property to delete diff --git a/storage-next/index.js b/storage-next/index.js index 1b18b957..15b07e5f 100644 --- a/storage-next/index.js +++ b/storage-next/index.js @@ -1,14 +1,6 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function initialize() { // [START storage_initialize] const { initializeApp } = require("firebase/app"); @@ -31,9 +23,11 @@ function initialize() { function multipleBuckets() { // [START storage_multiple_buckets] + const { getApp } = require("firebase/app"); const { getStorage } = require("firebase/storage"); // Get a non-default Storage bucket + const firebaseApp = getApp(); const storage = getStorage(firebaseApp, "gs://my-custom-bucket"); // [END storage_multiple_buckets] } @@ -73,7 +67,7 @@ function storageOnComplete(file) { // [START storage_on_complete] const { getStorage, ref, uploadBytesResumable, getDownloadURL } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); const imageRef = ref(storage, 'images/' + file.name); uploadBytesResumable(imageRef, file, metadata) .then((snapshot) => { diff --git a/storage-next/list-files.js b/storage-next/list-files.js index 4d3f05cc..493972d2 100644 --- a/storage-next/list-files.js +++ b/storage-next/list-files.js @@ -1,19 +1,11 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function listAll() { // [START storage_list_all] const { getStorage, ref, listAll } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); // Create a reference under which you want to list const listRef = ref(storage, 'files/uid'); @@ -40,7 +32,7 @@ function listPaginate() { async function pageTokenExample(){ // Create a reference under which you want to list - const storage = getStorage(firebaseApp); + const storage = getStorage(); const listRef = ref(storage, 'files/uid'); // Fetch the first page of 100. diff --git a/storage-next/upload-files.js b/storage-next/upload-files.js index 1ff5d4a8..98b93225 100644 --- a/storage-next/upload-files.js +++ b/storage-next/upload-files.js @@ -1,20 +1,12 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -import { initializeApp } from "firebase/app"; - -const firebaseApp = initializeApp({ - apiKey: '### FIREBASE API KEY ###', - appId: '### FIREBASE APP ID ###', - projectId: '### FIREBASE PROJECT ID ###' -}); - function uploadRef() { // [START storage_upload_ref] const { getStorage, ref } = require("firebase/storage"); // Create a root reference - const storage = getStorage(firebaseApp); + const storage = getStorage(); // Create a reference to 'mountains.jpg' const mountainsRef = ref(storage, 'mountains.jpg'); @@ -35,7 +27,7 @@ function uploadBlob(file) { // [START storage_upload_blob] const { getStorage, ref, uploadBytes } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); const storageRef = ref(storage, 'some-child'); // 'file' comes from the Blob or File API @@ -49,7 +41,7 @@ function uploadBytes() { // [START storage_upload_bytes] const { getStorage, ref, uploadBytes } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); const storageRef = ref(storage, 'some-child'); const bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21]); @@ -63,7 +55,7 @@ function uploadString() { // [START storage_upload_string] const { getStorage, ref, uploadString } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); const storageRef = ref(storage, 'some-child'); // Raw string is the default if no format is provided @@ -99,7 +91,7 @@ function uploadMetadata(file) { // [START storage_upload_metadata] const { getStorage, ref, uploadBytes } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); const storageRef = ref(storage, 'images/mountains.jpg'); // Create file metadata including the content type @@ -120,7 +112,7 @@ function manageUploads(file) { // [START storage_manage_uploads] const { getStorage, ref, uploadBytesResumable } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); const storageRef = ref(storage, 'images/mountains.jpg'); // Upload the file and metadata @@ -144,7 +136,7 @@ function monitorUpload(file) { // [START storage_monitor_upload] const { getStorage, ref, uploadBytesResumable, getDownloadURL } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); const storageRef = ref(storage, 'images/rivers.jpg'); const uploadTask = uploadBytesResumable(storageRef, file); @@ -189,7 +181,7 @@ function uploadHandleError(file) { // [START storage_upload_handle_error] const { getStorage, ref, uploadBytesResumable, getDownloadURL } = require("firebase/storage"); - const storage = getStorage(firebaseApp); + const storage = getStorage(); // Create the file metadata /** @type {any} */ From 08446878a9fe9d09028e08cc17e529802c60f00e Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 9 Apr 2021 05:55:21 -0700 Subject: [PATCH 120/235] Auto-update dependencies. (#134) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index c74ad8de..a9f82e88 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 9392cc13..ff88e29f 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.3.2/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.3.2/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.3.3/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.3.3/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From d27cf934bf0fafbaa69463cb6df3993fadf237e0 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 9 Apr 2021 09:41:14 -0400 Subject: [PATCH 121/235] Simplify Firestore references (#136) --- firestore-next/test.firestore.js | 132 +++++++++--------- firestore-next/test.solution-aggregation.js | 6 +- firestore-next/test.solution-counters.js | 6 +- .../test-firestore/add_rating_transaction.js | 2 +- .../test-firestore/cities_document_set.js | 4 +- .../test-firestore/data_types.js | 4 +- .../test-firestore/delete_document.js | 4 +- .../test-firestore/doc_reference.js | 4 +- .../fs_collection_group_query_data_setup.js | 20 +-- .../test-firestore/get_custom_object.js | 4 +- .../test-firestore/get_document.js | 4 +- .../test-firestore/get_document_options.js | 4 +- .../test-firestore/listen_document.js | 4 +- .../test-firestore/listen_document_local.js | 4 +- .../test-firestore/listen_with_metadata.js | 4 +- .../server_timestamp_resolution_options.js | 4 +- .../test-firestore/set_custom_object.js | 4 +- .../test-firestore/set_document.js | 4 +- .../test-firestore/set_with_merge.js | 4 +- .../test-firestore/subcollection_reference.js | 4 +- .../test-firestore/transaction_promise.js | 4 +- .../test-firestore/update_delete_field.js | 4 +- .../test-firestore/update_document.js | 4 +- .../test-firestore/update_document_array.js | 4 +- .../update_document_increment.js | 4 +- .../test-firestore/update_document_nested.js | 4 +- .../update_with_server_timestamp.js | 4 +- .../test-firestore/write_batch.js | 8 +- .../get_collection_ratings.js | 4 +- .../test-solution-counters/create_counter.js | 4 +- .../increment_counter.js | 2 +- 31 files changed, 136 insertions(+), 136 deletions(-) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 15bc159e..2a452e80 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -204,9 +204,9 @@ describe("firestore", () => { it("should reference a specific document", () => { // [START doc_reference] - const { collection, doc } = require("firebase/firestore"); + const { doc } = require("firebase/firestore"); - const alovelaceDocumentRef = doc(collection(db, 'users'), 'alovelace'); + const alovelaceDocumentRef = doc(db, 'users', 'alovelace'); // [END doc_reference] }); @@ -228,18 +228,18 @@ describe("firestore", () => { it("should reference a document in a subcollection", () => { // [START subcollection_reference] - const { doc, collection } = require("firebase/firestore"); + const { doc } = require("firebase/firestore"); - const messageRef = doc(collection(doc(collection(db, "rooms"), "roomA"), "messages"), "message1"); + const messageRef = doc(db, "rooms", "roomA", "messages", "message1"); // [END subcollection_reference] }); it("should set a document", async () => { // [START set_document] - const { doc, collection, setDoc } = require("firebase/firestore"); + const { doc, setDoc } = require("firebase/firestore"); // Add a new document in collection "cities" - await setDoc(doc(collection(db, "cities"), "LA"), { + await setDoc(doc(db, "cities", "LA"), { name: "Los Angeles", state: "CA", country: "USA" @@ -249,19 +249,19 @@ describe("firestore", () => { it("should set document with a custom object converter", async () => { // [START set_custom_object] - const { doc, collection, setDoc } = require("firebase/firestore"); + const { doc, setDoc } = require("firebase/firestore"); // Set with cityConverter - const ref = doc(collection(db, "cities"), "LA").withConverter(cityConverter); + const ref = doc(db, "cities", "LA").withConverter(cityConverter); await setDoc(ref, new City("Los Angeles", "CA", "USA")); // [END set_custom_object] }); it("should get document with a custom object converter", async () => { // [START get_custom_object] - const { doc, collection, getDoc} = require("firebase/firestore"); + const { doc, getDoc} = require("firebase/firestore"); - const ref = doc(collection(db, "cities"), "LA").withConverter(cityConverter); + const ref = doc(db, "cities", "LA").withConverter(cityConverter); const docSnap = await getDoc(ref); if (docSnap.exists()) { // Convert to City object @@ -276,21 +276,21 @@ describe("firestore", () => { it("should support batch writes", async () => { // [START write_batch] - const { writeBatch, doc, collection } = require("firebase/firestore"); + const { writeBatch, doc } = require("firebase/firestore"); // Get a new write batch const batch = writeBatch(db); // Set the value of 'NYC' - const nycRef = doc(collection(db, "cities"), "NYC"); + const nycRef = doc(db, "cities", "NYC"); batch.set(nycRef, {name: "New York City"}); // Update the population of 'SF' - const sfRef = doc(collection(db, "cities"), "SF"); + const sfRef = doc(db, "cities", "SF"); batch.update(sfRef, {"population": 1000000}); // Delete the city 'LA' - const laRef = doc(collection(db, "cities"), "LA"); + const laRef = doc(db, "cities", "LA"); batch.delete(laRef); // Commit the batch @@ -300,7 +300,7 @@ describe("firestore", () => { it("should set a document with every datatype #UNVERIFIED", async () => { // [START data_types] - const { doc, collection, setDoc, Timestamp } = require("firebase/firestore"); + const { doc, setDoc, Timestamp } = require("firebase/firestore"); const docData = { stringExample: "Hello world!", @@ -316,25 +316,25 @@ describe("firestore", () => { } } }; - await setDoc(doc(collection(db, "data"), "one"), docData); + await setDoc(doc(db, "data", "one"), docData); // [END data_types] }); it("should allow set with merge", async () => { // [START set_with_merge] - const { doc, collection, setDoc } = require("firebase/firestore"); + const { doc, setDoc } = require("firebase/firestore"); - const cityRef = doc(collection(db, 'cities'), 'BJ'); + const cityRef = doc(db, 'cities', 'BJ'); setDoc(cityRef, { capital: true }, { merge: true }); // [END set_with_merge] }); it("should update a document's nested fields #UNVERIFIED", async () => { // [START update_document_nested] - const { doc, collection, setDoc, updateDoc } = require("firebase/firestore"); + const { doc, setDoc, updateDoc } = require("firebase/firestore"); // Create an initial document to update. - const frankDocRef = doc(collection(db, "users"), "frank"); + const frankDocRef = doc(db, "users", "frank"); await setDoc(frankDocRef, { name: "Frank", favorites: { food: "Pizza", color: "Blue", subject: "recess" }, @@ -431,9 +431,9 @@ describe("firestore", () => { const data = {}; // [START cities_document_set] - const { collection, doc, setDoc } = require("firebase/firestore"); + const { doc, setDoc } = require("firebase/firestore"); - await setDoc(doc(collection(db, "cities"), "new-city-id"), data); + await setDoc(doc(db, "cities", "new-city-id"), data); // [END cities_document_set] }); @@ -466,9 +466,9 @@ describe("firestore", () => { it("should update a document", async () => { const data = {}; // [START update_document] - const { collection, doc, updateDoc } = require("firebase/firestore"); + const { doc, updateDoc } = require("firebase/firestore"); - const washingtonRef = doc(collection(db, "cities"), "DC"); + const washingtonRef = doc(db, "cities", "DC"); // Set the "capital" field of the city 'DC' await updateDoc(washingtonRef, { @@ -479,9 +479,9 @@ describe("firestore", () => { it("should update an array field in a document", async () => { // [START update_document_array] - const { collection, doc, updateDoc, arrayUnion, arrayRemove } = require("firebase/firestore"); + const { doc, updateDoc, arrayUnion, arrayRemove } = require("firebase/firestore"); - const washingtonRef = doc(collection(db, "cities"), "DC"); + const washingtonRef = doc(db, "cities", "DC"); // Atomically add a new region to the "regions" array field. await updateDoc(washingtonRef, { @@ -497,9 +497,9 @@ describe("firestore", () => { it("should update a document using numeric transforms", async () => { // [START update_document_increment] - const { collection, doc, updateDoc, increment } = require("firebase/firestore"); + const { doc, updateDoc, increment } = require("firebase/firestore"); - const washingtonRef = doc(collection(db, "cities"), "DC"); + const washingtonRef = doc(db, "cities", "DC"); // Atomically increment the population of the city by 50. await updateDoc(washingtonRef, { @@ -510,16 +510,16 @@ describe("firestore", () => { it("should delete a document", async () => { // [START delete_document] - const { collection, doc, deleteDoc } = require("firebase/firestore"); + const { doc, deleteDoc } = require("firebase/firestore"); - await deleteDoc(doc(collection(db, "cities"), "DC")); + await deleteDoc(doc(db, "cities", "DC")); // [END delete_document] }); it("should handle transactions", async () => { - const { collection, doc, setDoc } = require("firebase/firestore"); + const { doc, setDoc } = require("firebase/firestore"); - const sfDocRef = doc(collection(db, "cities"), "SF"); + const sfDocRef = doc(db, "cities", "SF"); await setDoc(sfDocRef, { population: 0 }); // [START transaction] @@ -544,10 +544,10 @@ describe("firestore", () => { it("should handle transaction which bubble out data", async () => { // [START transaction_promise] - const { collection, doc, runTransaction } = require("firebase/firestore"); + const { doc, runTransaction } = require("firebase/firestore"); // Create a reference to the SF doc. - const sfDocRef = doc(collection(db, "cities"), "SF"); + const sfDocRef = doc(db, "cities", "SF"); try { const newPopulation = await runTransaction(db, async (transaction) => { @@ -574,9 +574,9 @@ describe("firestore", () => { it("should get a single document", async () => { // [START get_document] - const { collection, doc, getDoc } = require("firebase/firestore"); + const { doc, getDoc } = require("firebase/firestore"); - const docRef = doc(collection(db, "cities"), "SF"); + const docRef = doc(db, "cities", "SF"); const docSnap = await getDoc(docRef); if (docSnap.exists()) { @@ -590,9 +590,9 @@ describe("firestore", () => { it("should get a document with options", async () => { // [START get_document_options] - const { collection, doc, getDocFromCache } = require("firebase/firestore"); + const { doc, getDocFromCache } = require("firebase/firestore"); - const docRef = doc(collection(db, "cities"), "SF"); + const docRef = doc(db, "cities", "SF"); // Get a document, forcing the SDK to fetch from the offline cache. try { @@ -609,9 +609,9 @@ describe("firestore", () => { it("should listen on a single document", (done) => { // [START listen_document] - const { collection, doc, onSnapshot } = require("firebase/firestore"); + const { doc, onSnapshot } = require("firebase/firestore"); - const unsub = onSnapshot(doc(collection(db, "cities"), "SF"), (doc) => { + const unsub = onSnapshot(doc(db, "cities", "SF"), (doc) => { console.log("Current data: ", doc.data()); }); // [END listen_document] @@ -624,9 +624,9 @@ describe("firestore", () => { it("should listen on a single document with metadata", (done) => { // [START listen_document_local] - const { collection, doc, onSnapshot } = require("firebase/firestore"); + const { doc, onSnapshot } = require("firebase/firestore"); - const unsub = onSnapshot(doc(collection(db, "cities"), "SF"), (doc) => { + const unsub = onSnapshot(doc(db, "cities", "SF"), (doc) => { const source = doc.metadata.hasPendingWrites ? "Local" : "Server"; console.log(source, " data: ", doc.data()); }); @@ -640,10 +640,10 @@ describe("firestore", () => { it("should listen on a single document with options #UNVERIFIED", (done) => { // [START listen_with_metadata] - const { collection, doc, onSnapshot } = require("firebase/firestore"); + const { doc, onSnapshot } = require("firebase/firestore"); const unsub = onSnapshot( - doc(collection(db, "cities"), "SF"), + doc(db, "cities", "SF"), { includeMetadataChanges: true }, (doc) => { // ... @@ -761,9 +761,9 @@ describe("firestore", () => { it("should update a document with server timestamp", async () => { async function update() { // [START update_with_server_timestamp] - const { collection, updateDoc, serverTimestamp } = require("firebase/firestore"); + const { updateDoc, serverTimestamp } = require("firebase/firestore"); - const docRef = doc(collection(db, 'objects'), 'some-id'); + const docRef = doc(db, 'objects', 'some-id'); // Update the timestamp field with the value from the server const updateTimestamp = await updateDoc(docRef, { @@ -774,21 +774,21 @@ describe("firestore", () => { return updateTimestamp; } - const { collection, doc, setDoc } = require("firebase/firestore"); + const { doc, setDoc } = require("firebase/firestore"); - await setDoc(doc(collection(db, 'objects'), 'some-id'), {}); + await setDoc(doc(db, 'objects', 'some-id'), {}); await update(); console.log('Document updated with server timestamp'); }); it("should use options to control server timestamp resolution", async () => { // [START server_timestamp_resolution_options] - const { collection, doc, updateDoc, serverTimestamp, onSnapshot } = require("firebase/firestore"); + const { doc, updateDoc, serverTimestamp, onSnapshot } = require("firebase/firestore"); // Perform an update followed by an immediate read without // waiting for the update to complete. Due to the snapshot // options we will get two results: one with an estimate // timestamp and one with the resolved server timestamp. - const docRef = doc(collection(db, 'objects'), 'some-id'); + const docRef = doc(db, 'objects', 'some-id'); updateDoc(docRef, { timestamp: serverTimestamp() }); @@ -808,9 +808,9 @@ describe("firestore", () => { it("should delete a document field", async () => { async function update() { // [START update_delete_field] - const { doc, collection, updateDoc, deleteField } = require("firebase/firestore"); + const { doc, updateDoc, deleteField } = require("firebase/firestore"); - const cityRef = doc(collection(db, 'cities'), 'BJ'); + const cityRef = doc(db, 'cities', 'BJ'); // Remove the 'capital' field from the document await updateDoc(cityRef, { @@ -819,9 +819,9 @@ describe("firestore", () => { // [END update_delete_field] } - const { doc, collection, setDoc } = require("firebase/firestore"); + const { doc, setDoc } = require("firebase/firestore"); - await setDoc(doc(collection(db,'cities'), 'BJ'), { capital: true }); + await setDoc(doc(db, 'cities', 'BJ'), { capital: true }); await update(); }); @@ -1099,43 +1099,43 @@ describe("firestore", () => { const citiesRef = collection(db, 'cities'); await Promise.all([ - setDoc(doc(collection(doc(citiesRef, 'SF'), 'landmarks')), { + setDoc(doc(citiesRef, 'SF', 'landmarks'), { name: 'Golden Gate Bridge', type: 'bridge' }), - setDoc(doc(collection(doc(citiesRef, 'SF'), 'landmarks')), { + setDoc(doc(citiesRef, 'SF', 'landmarks'), { name: 'Legion of Honor', type: 'museum' }), - setDoc(doc(collection(doc(citiesRef, 'LA'), 'landmarks')), { + setDoc(doc(citiesRef, 'LA', 'landmarks'), { name: 'Griffith Park', type: 'park' }), - setDoc(doc(collection(doc(citiesRef, 'LA'), 'landmarks')), { + setDoc(doc(citiesRef, 'LA', 'landmarks'), { name: 'The Getty', type: 'museum' }), - setDoc(doc(collection(doc(citiesRef, 'DC'), 'landmarks')), { + setDoc(doc(citiesRef, 'DC', 'landmarks'), { name: 'Lincoln Memorial', type: 'memorial' }), - setDoc(doc(collection(doc(citiesRef, 'DC'), 'landmarks')), { + setDoc(doc(citiesRef, 'DC', 'landmarks'), { name: 'National Air and Space Museum', type: 'museum' }), - setDoc(doc(collection(doc(citiesRef, 'TOK'), 'landmarks')), { + setDoc(doc(citiesRef, 'TOK', 'landmarks'), { name: 'Ueno Park', type: 'park' }), - setDoc(doc(collection(doc(citiesRef, 'TOK'), 'landmarks')), { + setDoc(doc(citiesRef, 'TOK', 'landmarks'), { name: 'National Museum of Nature and Science', type: 'museum' }), - setDoc(doc(collection(doc(citiesRef, 'BJ'), 'landmarks')), { + setDoc(doc(citiesRef, 'BJ', 'landmarks'), { name: 'Jingshan Park', type: 'park' }), - setDoc(doc(collection(doc(citiesRef, 'BJ'), 'landmarks')), { + setDoc(doc(citiesRef, 'BJ', 'landmarks'), { name: 'Beijing Ancient Observatory', type: 'museum' }) @@ -1161,7 +1161,7 @@ describe("firestore", () => { describe("solution-aggregation", () => { it("should update a restaurant in a transaction #UNVERIFIED", async () => { // [START add_rating_transaction] - const { collection, doc, runTransaction} = require("firebase/firestore"); + const { collection, doc, runTransaction } = require("firebase/firestore"); async function addRating(restaurantRef, rating) { // Create a reference for a new rating, for use inside the transaction @@ -1193,7 +1193,7 @@ describe("firestore", () => { // Create document and add a rating const { setDoc } = require("firebase/firestore"); - const ref = doc(collection(db, 'restaurants'), ('arinell-pizza')); + const ref = doc(db, 'restaurants', 'arinell-pizza'); await setDoc(ref, { name: 'Arinell Pizza', avgRating: 4.63, diff --git a/firestore-next/test.solution-aggregation.js b/firestore-next/test.solution-aggregation.js index 82e1d602..c0a825b5 100644 --- a/firestore-next/test.solution-aggregation.js +++ b/firestore-next/test.solution-aggregation.js @@ -27,15 +27,15 @@ describe("firestore-solution-arrays", () => { const app = initializeApp(config, "solution-arrays"); db = getFirestore(app); - await setDoc(doc(collection(db, "restaurants"), "arinell-pizza"), arinellDoc); + await setDoc(doc(db, "restaurants", "arinell-pizza"), arinellDoc); }); describe("solution-arrays", () => { it("should get a collection of ratings", async () => { // [START get_collection_ratings] - const { collection, doc, getDocs } = require("firebase/firestore"); + const { collection, getDocs } = require("firebase/firestore"); - const ratingsRef = collection(doc(collection(db, "restaurants"), "arinell-pizza"), "ratings"); + const ratingsRef = collection(db, "restaurants", "arinell-pizza", "ratings"); const ratingsDocs = await getDocs(ratingsRef); // [END get_collection_ratings] }); diff --git a/firestore-next/test.solution-counters.js b/firestore-next/test.solution-counters.js index a76cfc24..2e00e8d9 100644 --- a/firestore-next/test.solution-counters.js +++ b/firestore-next/test.solution-counters.js @@ -8,7 +8,7 @@ let db; // [START create_counter] function createCounter(ref, num_shards) { - const { collection, doc, writeBatch } = require("firebase/firestore"); + const { doc, writeBatch } = require("firebase/firestore"); const batch = writeBatch(db); @@ -17,7 +17,7 @@ function createCounter(ref, num_shards) { // Initialize each shard with count=0 for (let i = 0; i < num_shards; i++) { - const shardRef = doc(collection(ref, 'shards'), i.toString()); + const shardRef = doc(ref, 'shards', i.toString()); batch.set(shardRef, { count: 0 }); } @@ -32,7 +32,7 @@ function incrementCounter(db, ref, num_shards) { // Select a shard of the counter at random const shardId = Math.floor(Math.random() * num_shards).toString(); - const shardRef = doc(collection(ref, 'shards'), shardId); + const shardRef = doc(ref, 'shards', shardId); // Update count return updateDoc(shardRef, "count", increment(1)); diff --git a/snippets/firestore-next/test-firestore/add_rating_transaction.js b/snippets/firestore-next/test-firestore/add_rating_transaction.js index 248f5e54..e5c279a9 100644 --- a/snippets/firestore-next/test-firestore/add_rating_transaction.js +++ b/snippets/firestore-next/test-firestore/add_rating_transaction.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START add_rating_transaction_modular] -import { collection, doc, runTransaction} from "firebase/firestore"; +import { collection, doc, runTransaction } from "firebase/firestore"; async function addRating(restaurantRef, rating) { // Create a reference for a new rating, for use inside the transaction diff --git a/snippets/firestore-next/test-firestore/cities_document_set.js b/snippets/firestore-next/test-firestore/cities_document_set.js index edebdc0c..793c4a8e 100644 --- a/snippets/firestore-next/test-firestore/cities_document_set.js +++ b/snippets/firestore-next/test-firestore/cities_document_set.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START cities_document_set_modular] -import { collection, doc, setDoc } from "firebase/firestore"; +import { doc, setDoc } from "firebase/firestore"; -await setDoc(doc(collection(db, "cities"), "new-city-id"), data); +await setDoc(doc(db, "cities", "new-city-id"), data); // [END cities_document_set_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/data_types.js b/snippets/firestore-next/test-firestore/data_types.js index faace529..9aa46b2b 100644 --- a/snippets/firestore-next/test-firestore/data_types.js +++ b/snippets/firestore-next/test-firestore/data_types.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START data_types_modular] -import { doc, collection, setDoc, Timestamp } from "firebase/firestore"; +import { doc, setDoc, Timestamp } from "firebase/firestore"; const docData = { stringExample: "Hello world!", @@ -20,5 +20,5 @@ const docData = { } } }; -await setDoc(doc(collection(db, "data"), "one"), docData); +await setDoc(doc(db, "data", "one"), docData); // [END data_types_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/delete_document.js b/snippets/firestore-next/test-firestore/delete_document.js index 27c0bec9..0933d311 100644 --- a/snippets/firestore-next/test-firestore/delete_document.js +++ b/snippets/firestore-next/test-firestore/delete_document.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START delete_document_modular] -import { collection, doc, deleteDoc } from "firebase/firestore"; +import { doc, deleteDoc } from "firebase/firestore"; -await deleteDoc(doc(collection(db, "cities"), "DC")); +await deleteDoc(doc(db, "cities", "DC")); // [END delete_document_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/doc_reference.js b/snippets/firestore-next/test-firestore/doc_reference.js index 4f3fc134..10b96445 100644 --- a/snippets/firestore-next/test-firestore/doc_reference.js +++ b/snippets/firestore-next/test-firestore/doc_reference.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START doc_reference_modular] -import { collection, doc } from "firebase/firestore"; +import { doc } from "firebase/firestore"; -const alovelaceDocumentRef = doc(collection(db, 'users'), 'alovelace'); +const alovelaceDocumentRef = doc(db, 'users', 'alovelace'); // [END doc_reference_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js b/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js index ab8964f1..a4e07952 100644 --- a/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js +++ b/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js @@ -9,43 +9,43 @@ import { collection, doc, setDoc } from "firebase/firestore"; const citiesRef = collection(db, 'cities'); await Promise.all([ - setDoc(doc(collection(doc(citiesRef, 'SF'), 'landmarks')), { + setDoc(doc(citiesRef, 'SF', 'landmarks'), { name: 'Golden Gate Bridge', type: 'bridge' }), - setDoc(doc(collection(doc(citiesRef, 'SF'), 'landmarks')), { + setDoc(doc(citiesRef, 'SF', 'landmarks'), { name: 'Legion of Honor', type: 'museum' }), - setDoc(doc(collection(doc(citiesRef, 'LA'), 'landmarks')), { + setDoc(doc(citiesRef, 'LA', 'landmarks'), { name: 'Griffith Park', type: 'park' }), - setDoc(doc(collection(doc(citiesRef, 'LA'), 'landmarks')), { + setDoc(doc(citiesRef, 'LA', 'landmarks'), { name: 'The Getty', type: 'museum' }), - setDoc(doc(collection(doc(citiesRef, 'DC'), 'landmarks')), { + setDoc(doc(citiesRef, 'DC', 'landmarks'), { name: 'Lincoln Memorial', type: 'memorial' }), - setDoc(doc(collection(doc(citiesRef, 'DC'), 'landmarks')), { + setDoc(doc(citiesRef, 'DC', 'landmarks'), { name: 'National Air and Space Museum', type: 'museum' }), - setDoc(doc(collection(doc(citiesRef, 'TOK'), 'landmarks')), { + setDoc(doc(citiesRef, 'TOK', 'landmarks'), { name: 'Ueno Park', type: 'park' }), - setDoc(doc(collection(doc(citiesRef, 'TOK'), 'landmarks')), { + setDoc(doc(citiesRef, 'TOK', 'landmarks'), { name: 'National Museum of Nature and Science', type: 'museum' }), - setDoc(doc(collection(doc(citiesRef, 'BJ'), 'landmarks')), { + setDoc(doc(citiesRef, 'BJ', 'landmarks'), { name: 'Jingshan Park', type: 'park' }), - setDoc(doc(collection(doc(citiesRef, 'BJ'), 'landmarks')), { + setDoc(doc(citiesRef, 'BJ', 'landmarks'), { name: 'Beijing Ancient Observatory', type: 'museum' }) diff --git a/snippets/firestore-next/test-firestore/get_custom_object.js b/snippets/firestore-next/test-firestore/get_custom_object.js index 92b27330..3e39eafa 100644 --- a/snippets/firestore-next/test-firestore/get_custom_object.js +++ b/snippets/firestore-next/test-firestore/get_custom_object.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START get_custom_object_modular] -import { doc, collection, getDoc} from "firebase/firestore"; +import { doc, getDoc} from "firebase/firestore"; -const ref = doc(collection(db, "cities"), "LA").withConverter(cityConverter); +const ref = doc(db, "cities", "LA").withConverter(cityConverter); const docSnap = await getDoc(ref); if (docSnap.exists()) { // Convert to City object diff --git a/snippets/firestore-next/test-firestore/get_document.js b/snippets/firestore-next/test-firestore/get_document.js index 79886025..1ca4787d 100644 --- a/snippets/firestore-next/test-firestore/get_document.js +++ b/snippets/firestore-next/test-firestore/get_document.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START get_document_modular] -import { collection, doc, getDoc } from "firebase/firestore"; +import { doc, getDoc } from "firebase/firestore"; -const docRef = doc(collection(db, "cities"), "SF"); +const docRef = doc(db, "cities", "SF"); const docSnap = await getDoc(docRef); if (docSnap.exists()) { diff --git a/snippets/firestore-next/test-firestore/get_document_options.js b/snippets/firestore-next/test-firestore/get_document_options.js index ecaf4b55..8b161b27 100644 --- a/snippets/firestore-next/test-firestore/get_document_options.js +++ b/snippets/firestore-next/test-firestore/get_document_options.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START get_document_options_modular] -import { collection, doc, getDocFromCache } from "firebase/firestore"; +import { doc, getDocFromCache } from "firebase/firestore"; -const docRef = doc(collection(db, "cities"), "SF"); +const docRef = doc(db, "cities", "SF"); // Get a document, forcing the SDK to fetch from the offline cache. try { diff --git a/snippets/firestore-next/test-firestore/listen_document.js b/snippets/firestore-next/test-firestore/listen_document.js index 54affb09..9b6507fc 100644 --- a/snippets/firestore-next/test-firestore/listen_document.js +++ b/snippets/firestore-next/test-firestore/listen_document.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START listen_document_modular] -import { collection, doc, onSnapshot } from "firebase/firestore"; +import { doc, onSnapshot } from "firebase/firestore"; -const unsub = onSnapshot(doc(collection(db, "cities"), "SF"), (doc) => { +const unsub = onSnapshot(doc(db, "cities", "SF"), (doc) => { console.log("Current data: ", doc.data()); }); // [END listen_document_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/listen_document_local.js b/snippets/firestore-next/test-firestore/listen_document_local.js index 63a70475..08041a3f 100644 --- a/snippets/firestore-next/test-firestore/listen_document_local.js +++ b/snippets/firestore-next/test-firestore/listen_document_local.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START listen_document_local_modular] -import { collection, doc, onSnapshot } from "firebase/firestore"; +import { doc, onSnapshot } from "firebase/firestore"; -const unsub = onSnapshot(doc(collection(db, "cities"), "SF"), (doc) => { +const unsub = onSnapshot(doc(db, "cities", "SF"), (doc) => { const source = doc.metadata.hasPendingWrites ? "Local" : "Server"; console.log(source, " data: ", doc.data()); }); diff --git a/snippets/firestore-next/test-firestore/listen_with_metadata.js b/snippets/firestore-next/test-firestore/listen_with_metadata.js index c40746b9..42848f62 100644 --- a/snippets/firestore-next/test-firestore/listen_with_metadata.js +++ b/snippets/firestore-next/test-firestore/listen_with_metadata.js @@ -4,10 +4,10 @@ // To make edits to the snippets in this file, please edit the source // [START listen_with_metadata_modular] -import { collection, doc, onSnapshot } from "firebase/firestore"; +import { doc, onSnapshot } from "firebase/firestore"; const unsub = onSnapshot( - doc(collection(db, "cities"), "SF"), + doc(db, "cities", "SF"), { includeMetadataChanges: true }, (doc) => { // ... diff --git a/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js b/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js index f59048e2..9fab8f77 100644 --- a/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js +++ b/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js @@ -4,12 +4,12 @@ // To make edits to the snippets in this file, please edit the source // [START server_timestamp_resolution_options_modular] -import { collection, doc, updateDoc, serverTimestamp, onSnapshot } from "firebase/firestore"; +import { doc, updateDoc, serverTimestamp, onSnapshot } from "firebase/firestore"; // Perform an update followed by an immediate read without // waiting for the update to complete. Due to the snapshot // options we will get two results: one with an estimate // timestamp and one with the resolved server timestamp. -const docRef = doc(collection(db, 'objects'), 'some-id'); +const docRef = doc(db, 'objects', 'some-id'); updateDoc(docRef, { timestamp: serverTimestamp() }); diff --git a/snippets/firestore-next/test-firestore/set_custom_object.js b/snippets/firestore-next/test-firestore/set_custom_object.js index a71d06ef..54febc9f 100644 --- a/snippets/firestore-next/test-firestore/set_custom_object.js +++ b/snippets/firestore-next/test-firestore/set_custom_object.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START set_custom_object_modular] -import { doc, collection, setDoc } from "firebase/firestore"; +import { doc, setDoc } from "firebase/firestore"; // Set with cityConverter -const ref = doc(collection(db, "cities"), "LA").withConverter(cityConverter); +const ref = doc(db, "cities", "LA").withConverter(cityConverter); await setDoc(ref, new City("Los Angeles", "CA", "USA")); // [END set_custom_object_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/set_document.js b/snippets/firestore-next/test-firestore/set_document.js index d3c246ad..94a562af 100644 --- a/snippets/firestore-next/test-firestore/set_document.js +++ b/snippets/firestore-next/test-firestore/set_document.js @@ -4,10 +4,10 @@ // To make edits to the snippets in this file, please edit the source // [START set_document_modular] -import { doc, collection, setDoc } from "firebase/firestore"; +import { doc, setDoc } from "firebase/firestore"; // Add a new document in collection "cities" -await setDoc(doc(collection(db, "cities"), "LA"), { +await setDoc(doc(db, "cities", "LA"), { name: "Los Angeles", state: "CA", country: "USA" diff --git a/snippets/firestore-next/test-firestore/set_with_merge.js b/snippets/firestore-next/test-firestore/set_with_merge.js index e3981920..ca0fd3b6 100644 --- a/snippets/firestore-next/test-firestore/set_with_merge.js +++ b/snippets/firestore-next/test-firestore/set_with_merge.js @@ -4,8 +4,8 @@ // To make edits to the snippets in this file, please edit the source // [START set_with_merge_modular] -import { doc, collection, setDoc } from "firebase/firestore"; +import { doc, setDoc } from "firebase/firestore"; -const cityRef = doc(collection(db, 'cities'), 'BJ'); +const cityRef = doc(db, 'cities', 'BJ'); setDoc(cityRef, { capital: true }, { merge: true }); // [END set_with_merge_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/subcollection_reference.js b/snippets/firestore-next/test-firestore/subcollection_reference.js index 56019331..7b42af67 100644 --- a/snippets/firestore-next/test-firestore/subcollection_reference.js +++ b/snippets/firestore-next/test-firestore/subcollection_reference.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START subcollection_reference_modular] -import { doc, collection } from "firebase/firestore"; +import { doc } from "firebase/firestore"; -const messageRef = doc(collection(doc(collection(db, "rooms"), "roomA"), "messages"), "message1"); +const messageRef = doc(db, "rooms", "roomA", "messages", "message1"); // [END subcollection_reference_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/transaction_promise.js b/snippets/firestore-next/test-firestore/transaction_promise.js index ef5ca4c7..cda47859 100644 --- a/snippets/firestore-next/test-firestore/transaction_promise.js +++ b/snippets/firestore-next/test-firestore/transaction_promise.js @@ -4,10 +4,10 @@ // To make edits to the snippets in this file, please edit the source // [START transaction_promise_modular] -import { collection, doc, runTransaction } from "firebase/firestore"; +import { doc, runTransaction } from "firebase/firestore"; // Create a reference to the SF doc. -const sfDocRef = doc(collection(db, "cities"), "SF"); +const sfDocRef = doc(db, "cities", "SF"); try { const newPopulation = await runTransaction(db, async (transaction) => { diff --git a/snippets/firestore-next/test-firestore/update_delete_field.js b/snippets/firestore-next/test-firestore/update_delete_field.js index b5477302..7bff4444 100644 --- a/snippets/firestore-next/test-firestore/update_delete_field.js +++ b/snippets/firestore-next/test-firestore/update_delete_field.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START update_delete_field_modular] -import { doc, collection, updateDoc, deleteField } from "firebase/firestore"; +import { doc, updateDoc, deleteField } from "firebase/firestore"; -const cityRef = doc(collection(db, 'cities'), 'BJ'); +const cityRef = doc(db, 'cities', 'BJ'); // Remove the 'capital' field from the document await updateDoc(cityRef, { diff --git a/snippets/firestore-next/test-firestore/update_document.js b/snippets/firestore-next/test-firestore/update_document.js index 02c21f35..23488474 100644 --- a/snippets/firestore-next/test-firestore/update_document.js +++ b/snippets/firestore-next/test-firestore/update_document.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START update_document_modular] -import { collection, doc, updateDoc } from "firebase/firestore"; +import { doc, updateDoc } from "firebase/firestore"; -const washingtonRef = doc(collection(db, "cities"), "DC"); +const washingtonRef = doc(db, "cities", "DC"); // Set the "capital" field of the city 'DC' await updateDoc(washingtonRef, { diff --git a/snippets/firestore-next/test-firestore/update_document_array.js b/snippets/firestore-next/test-firestore/update_document_array.js index e2c07145..463e857d 100644 --- a/snippets/firestore-next/test-firestore/update_document_array.js +++ b/snippets/firestore-next/test-firestore/update_document_array.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START update_document_array_modular] -import { collection, doc, updateDoc, arrayUnion, arrayRemove } from "firebase/firestore"; +import { doc, updateDoc, arrayUnion, arrayRemove } from "firebase/firestore"; -const washingtonRef = doc(collection(db, "cities"), "DC"); +const washingtonRef = doc(db, "cities", "DC"); // Atomically add a new region to the "regions" array field. await updateDoc(washingtonRef, { diff --git a/snippets/firestore-next/test-firestore/update_document_increment.js b/snippets/firestore-next/test-firestore/update_document_increment.js index 5ad2bb6a..30258a6c 100644 --- a/snippets/firestore-next/test-firestore/update_document_increment.js +++ b/snippets/firestore-next/test-firestore/update_document_increment.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START update_document_increment_modular] -import { collection, doc, updateDoc, increment } from "firebase/firestore"; +import { doc, updateDoc, increment } from "firebase/firestore"; -const washingtonRef = doc(collection(db, "cities"), "DC"); +const washingtonRef = doc(db, "cities", "DC"); // Atomically increment the population of the city by 50. await updateDoc(washingtonRef, { diff --git a/snippets/firestore-next/test-firestore/update_document_nested.js b/snippets/firestore-next/test-firestore/update_document_nested.js index a1412018..d3c12533 100644 --- a/snippets/firestore-next/test-firestore/update_document_nested.js +++ b/snippets/firestore-next/test-firestore/update_document_nested.js @@ -4,10 +4,10 @@ // To make edits to the snippets in this file, please edit the source // [START update_document_nested_modular] -import { doc, collection, setDoc, updateDoc } from "firebase/firestore"; +import { doc, setDoc, updateDoc } from "firebase/firestore"; // Create an initial document to update. -const frankDocRef = doc(collection(db, "users"), "frank"); +const frankDocRef = doc(db, "users", "frank"); await setDoc(frankDocRef, { name: "Frank", favorites: { food: "Pizza", color: "Blue", subject: "recess" }, diff --git a/snippets/firestore-next/test-firestore/update_with_server_timestamp.js b/snippets/firestore-next/test-firestore/update_with_server_timestamp.js index 39cb4c94..e4e2f248 100644 --- a/snippets/firestore-next/test-firestore/update_with_server_timestamp.js +++ b/snippets/firestore-next/test-firestore/update_with_server_timestamp.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START update_with_server_timestamp_modular] -import { collection, updateDoc, serverTimestamp } from "firebase/firestore"; +import { updateDoc, serverTimestamp } from "firebase/firestore"; -const docRef = doc(collection(db, 'objects'), 'some-id'); +const docRef = doc(db, 'objects', 'some-id'); // Update the timestamp field with the value from the server const updateTimestamp = await updateDoc(docRef, { diff --git a/snippets/firestore-next/test-firestore/write_batch.js b/snippets/firestore-next/test-firestore/write_batch.js index 157d1bcf..42494f5a 100644 --- a/snippets/firestore-next/test-firestore/write_batch.js +++ b/snippets/firestore-next/test-firestore/write_batch.js @@ -4,21 +4,21 @@ // To make edits to the snippets in this file, please edit the source // [START write_batch_modular] -import { writeBatch, doc, collection } from "firebase/firestore"; +import { writeBatch, doc } from "firebase/firestore"; // Get a new write batch const batch = writeBatch(db); // Set the value of 'NYC' -const nycRef = doc(collection(db, "cities"), "NYC"); +const nycRef = doc(db, "cities", "NYC"); batch.set(nycRef, {name: "New York City"}); // Update the population of 'SF' -const sfRef = doc(collection(db, "cities"), "SF"); +const sfRef = doc(db, "cities", "SF"); batch.update(sfRef, {"population": 1000000}); // Delete the city 'LA' -const laRef = doc(collection(db, "cities"), "LA"); +const laRef = doc(db, "cities", "LA"); batch.delete(laRef); // Commit the batch diff --git a/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js b/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js index 7f820455..06b85efc 100644 --- a/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js +++ b/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js @@ -4,8 +4,8 @@ // To make edits to the snippets in this file, please edit the source // [START get_collection_ratings_modular] -import { collection, doc, getDocs } from "firebase/firestore"; +import { collection, getDocs } from "firebase/firestore"; -const ratingsRef = collection(doc(collection(db, "restaurants"), "arinell-pizza"), "ratings"); +const ratingsRef = collection(db, "restaurants", "arinell-pizza", "ratings"); const ratingsDocs = await getDocs(ratingsRef); // [END get_collection_ratings_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-solution-counters/create_counter.js b/snippets/firestore-next/test-solution-counters/create_counter.js index d69b00e6..738dd634 100644 --- a/snippets/firestore-next/test-solution-counters/create_counter.js +++ b/snippets/firestore-next/test-solution-counters/create_counter.js @@ -5,7 +5,7 @@ // [START create_counter_modular] function createCounter(ref, num_shards) { - import { collection, doc, writeBatch } from "firebase/firestore"; + import { doc, writeBatch } from "firebase/firestore"; const batch = writeBatch(db); @@ -14,7 +14,7 @@ function createCounter(ref, num_shards) { // Initialize each shard with count=0 for (let i = 0; i < num_shards; i++) { - const shardRef = doc(collection(ref, 'shards'), i.toString()); + const shardRef = doc(ref, 'shards', i.toString()); batch.set(shardRef, { count: 0 }); } diff --git a/snippets/firestore-next/test-solution-counters/increment_counter.js b/snippets/firestore-next/test-solution-counters/increment_counter.js index 278fea5f..37e94224 100644 --- a/snippets/firestore-next/test-solution-counters/increment_counter.js +++ b/snippets/firestore-next/test-solution-counters/increment_counter.js @@ -9,7 +9,7 @@ function incrementCounter(db, ref, num_shards) { // Select a shard of the counter at random const shardId = Math.floor(Math.random() * num_shards).toString(); - const shardRef = doc(collection(ref, 'shards'), shardId); + const shardRef = doc(ref, 'shards', shardId); // Update count return updateDoc(shardRef, "count", increment(1)); From 5e68f042a5531dd2f68528f3f52c3645ed442b43 Mon Sep 17 00:00:00 2001 From: Frank van Puffelen Date: Fri, 9 Apr 2021 14:42:33 -0700 Subject: [PATCH 122/235] Add RTDB increment snippet (#130) * Add RTDB increment snippets for both JS and vNext Add snippet showing how to do atomic increments with the `increment()` operator. --- .gitignore | 1 + database-next/read-and-write.js | 18 ++++++++++++++++++ database/read-and-write.js | 14 ++++++++++++++ .../rtdb_social_star_increment.js | 18 ++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 snippets/database-next/read-and-write/rtdb_social_star_increment.js diff --git a/.gitignore b/.gitignore index c3bf3b13..5759f295 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules tsconfig.json dist/ +.DS_Store diff --git a/database-next/read-and-write.js b/database-next/read-and-write.js index 717ddeae..2cbd5c5b 100644 --- a/database-next/read-and-write.js +++ b/database-next/read-and-write.js @@ -153,6 +153,24 @@ function toggleStar_wrapped() { // [END rtdb_social_star_transaction] } +/** + * @param {string} uid + * @param {string} key + */ +// [START rtdb_social_star_increment] +function addStar(uid, key) { + const { getDatabase, increment, ref, update } = require("firebase/database"); + const dbRef = ref(getDatabase()); + + const updates = {}; + updates[`posts/${key}/stars/${uid}`] = true; + updates[`posts/${key}/starCount`] = increment(1); + updates[`user-posts/${key}/stars/${uid}`] = true; + updates[`user-posts/${key}/starCount`] = increment(1); + update(dbRef, updates); +} +// [END rtdb_social_star_increment] + function readOnceWithGet(userId) { // [START rtdb_read_once_get] const { getDatabase, ref, child, get } = require("firebase/database"); diff --git a/database/read-and-write.js b/database/read-and-write.js index e14b741b..e5e5a629 100644 --- a/database/read-and-write.js +++ b/database/read-and-write.js @@ -124,6 +124,20 @@ function toggleStar(postRef, uid) { } // [END rtdb_social_star_transaction] +/** + * @param {string} uid + * @param {string} key + */ +// [START rtdb_social_star_increment] +function addStar(uid, key) { + const updates = {}; + updates[`posts/${key}/stars/${uid}`] = true; + updates[`posts/${key}/starCount`] = firebase.database.ServerValue.increment(1); + updates[`user-posts/${key}/stars/${uid}`] = true; + updates[`user-posts/${key}/starCount`] = firebase.database.ServerValue.increment(1); + firebase.database().ref().update(updates); +} + function readOnceWithGet(userId) { // [START rtdb_read_once_get] const dbRef = firebase.database().ref(); diff --git a/snippets/database-next/read-and-write/rtdb_social_star_increment.js b/snippets/database-next/read-and-write/rtdb_social_star_increment.js new file mode 100644 index 00000000..bb4f9d7e --- /dev/null +++ b/snippets/database-next/read-and-write/rtdb_social_star_increment.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./database-next/read-and-write.js +// +// To make edits to the snippets in this file, please edit the source + +// [START rtdb_social_star_increment_modular] +function addStar(uid, key) { + import { getDatabase, increment, ref, update } from "firebase/database"; + const dbRef = ref(getDatabase()); + + const updates = {}; + updates[`posts/${key}/stars/${uid}`] = true; + updates[`posts/${key}/starCount`] = increment(1); + updates[`user-posts/${key}/stars/${uid}`] = true; + updates[`user-posts/${key}/starCount`] = increment(1); + update(dbRef, updates); +} +// [END rtdb_social_star_increment_modular] \ No newline at end of file From 4b496235d2db433354ebb8084d59eba1263769a6 Mon Sep 17 00:00:00 2001 From: Frank van Puffelen Date: Fri, 9 Apr 2021 15:21:48 -0700 Subject: [PATCH 123/235] Add missing end region tag (#137) --- database/read-and-write.js | 1 + 1 file changed, 1 insertion(+) diff --git a/database/read-and-write.js b/database/read-and-write.js index e5e5a629..bcae4ccc 100644 --- a/database/read-and-write.js +++ b/database/read-and-write.js @@ -137,6 +137,7 @@ function addStar(uid, key) { updates[`user-posts/${key}/starCount`] = firebase.database.ServerValue.increment(1); firebase.database().ref().update(updates); } +// [END rtdb_social_star_increment] function readOnceWithGet(userId) { // [START rtdb_read_once_get] From 4b73641a1dd93c1497ff61956db8bac1e289b43e Mon Sep 17 00:00:00 2001 From: DPEBot Date: Tue, 13 Apr 2021 02:44:02 -0700 Subject: [PATCH 124/235] Auto-update dependencies. (#155) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 3883772f..2fd8cc65 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.3" + "firebase": "^8.4.1" } } diff --git a/auth/package.json b/auth/package.json index bb6f53ad..d463785b 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.3", + "firebase": "^8.4.1", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index 52076305..357a5df8 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.3" + "firebase": "^8.4.1" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 4e0c769f..d21f2634 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.3" + "firebase": "^8.4.1" } } diff --git a/firestore/package.json b/firestore/package.json index 788d5a65..90fd71c0 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.3", + "firebase": "^8.4.1", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 68327016..f3662dba 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.3" + "firebase": "^8.4.1" } } diff --git a/installations/package.json b/installations/package.json index 2c2ac3bf..b5ac2b99 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.3.3" + "firebase": "^8.4.1" } } diff --git a/messaging/package.json b/messaging/package.json index c53fa8c6..63d99b74 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.3" + "firebase": "^8.4.1" } } diff --git a/perf/package.json b/perf/package.json index 3fda34fd..6ad0b16c 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.3" + "firebase": "^8.4.1" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 45a411e2..aa994346 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.3" + "firebase": "^8.4.1" } } diff --git a/storage/package.json b/storage/package.json index b777b198..22df3b5e 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.3.3" + "firebase": "^8.4.1" } } From 79331943860993df782238996c05fd281b36e13a Mon Sep 17 00:00:00 2001 From: DPEBot Date: Tue, 13 Apr 2021 05:22:04 -0700 Subject: [PATCH 125/235] Auto-update dependencies. (#156) Brought to you by your friendly [Repository Gardener](https://github.com/GoogleCloudPlatform/repository-gardener). --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index a9f82e88..cbc68fa3 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index ff88e29f..6e9b8519 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.3.3/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.3.3/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 3bd946fa08177660f925a4215f20cf6c53678c07 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Wed, 14 Apr 2021 11:51:33 -0400 Subject: [PATCH 126/235] vNext beta release (#158) --- analytics-next/package.json | 2 +- auth-next/package.json | 2 +- database-next/package.json | 2 +- firebaseapp-next/package.json | 2 +- firestore-next/package.json | 2 +- functions-next/package.json | 2 +- messaging-next/package.json | 2 +- perf-next/package.json | 2 +- remoteconfig-next/package.json | 2 +- storage-next/package.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index 7b054b75..c2126ef1 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp" + "firebase": "9.0.0-beta.1" } } diff --git a/auth-next/package.json b/auth-next/package.json index 058a14c8..db0a71f4 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp" + "firebase": "9.0.0-beta.1" } } diff --git a/database-next/package.json b/database-next/package.json index 927237f7..df21d0a9 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp" + "firebase": "9.0.0-beta.1" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index a3f38088..01aad6d2 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp" + "firebase": "9.0.0-beta.1" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 8289e346..5f6c0a0d 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp", + "firebase": "9.0.0-beta.1", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/package.json b/functions-next/package.json index 85e91e5d..acb31ec3 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp" + "firebase": "9.0.0-beta.1" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index c787b7ed..0ce83ae1 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp" + "firebase": "9.0.0-beta.1" } } diff --git a/perf-next/package.json b/perf-next/package.json index 3a04b696..0069b847 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp" + "firebase": "9.0.0-beta.1" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index 8977d454..a64c6243 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp" + "firebase": "9.0.0-beta.1" } } diff --git a/storage-next/package.json b/storage-next/package.json index f21c67e0..9ec75d58 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "exp" + "firebase": "9.0.0-beta.1" } } From fd06c854d0efaa57cf05ad89a42f77bee9510eab Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 14 Apr 2021 17:00:49 +0100 Subject: [PATCH 127/235] Allow version range --- analytics-next/package.json | 2 +- auth-next/package.json | 2 +- database-next/package.json | 2 +- firebaseapp-next/package.json | 2 +- firestore-next/package.json | 2 +- functions-next/package.json | 2 +- messaging-next/package.json | 2 +- perf-next/package.json | 2 +- remoteconfig-next/package.json | 2 +- storage-next/package.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index c2126ef1..c680a4f2 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "9.0.0-beta.1" + "firebase": "^9.0.0-beta.1" } } diff --git a/auth-next/package.json b/auth-next/package.json index db0a71f4..19e3cdd9 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "9.0.0-beta.1" + "firebase": "^9.0.0-beta.1" } } diff --git a/database-next/package.json b/database-next/package.json index df21d0a9..22ed471f 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "9.0.0-beta.1" + "firebase": "^9.0.0-beta.1" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index 01aad6d2..0490b5e8 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "9.0.0-beta.1" + "firebase": "^9.0.0-beta.1" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 5f6c0a0d..929358a7 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "9.0.0-beta.1", + "firebase": "^9.0.0-beta.1", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/package.json b/functions-next/package.json index acb31ec3..c9ff1ffc 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "9.0.0-beta.1" + "firebase": "^9.0.0-beta.1" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index 0ce83ae1..37d5e35a 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "9.0.0-beta.1" + "firebase": "^9.0.0-beta.1" } } diff --git a/perf-next/package.json b/perf-next/package.json index 0069b847..8865057a 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "9.0.0-beta.1" + "firebase": "^9.0.0-beta.1" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index a64c6243..54cfa5d9 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "9.0.0-beta.1" + "firebase": "^9.0.0-beta.1" } } diff --git a/storage-next/package.json b/storage-next/package.json index 9ec75d58..7777f2d0 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "9.0.0-beta.1" + "firebase": "^9.0.0-beta.1" } } From f1cd58ac448666cb40365d0325b7d55ee8cad6e1 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 26 Apr 2021 02:36:17 -0700 Subject: [PATCH 128/235] Auto-update dependencies. (#161) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index cbc68fa3..27897373 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 6e9b8519..dc011678 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.4.2/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.4.2/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From fda5ec6e2c7c38eb68482d40c9059645368ae206 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 26 Apr 2021 02:42:54 -0700 Subject: [PATCH 129/235] Auto-update dependencies. (#160) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 2fd8cc65..8c1e355a 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.1" + "firebase": "^8.4.2" } } diff --git a/auth/package.json b/auth/package.json index d463785b..3feb38f5 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.4.1", + "firebase": "^8.4.2", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index 357a5df8..0613ac81 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.4.1" + "firebase": "^8.4.2" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index d21f2634..57f54180 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.1" + "firebase": "^8.4.2" } } diff --git a/firestore/package.json b/firestore/package.json index 90fd71c0..44f37d8d 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.1", + "firebase": "^8.4.2", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index f3662dba..8642b7b7 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.1" + "firebase": "^8.4.2" } } diff --git a/installations/package.json b/installations/package.json index b5ac2b99..7128e9ce 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.4.1" + "firebase": "^8.4.2" } } diff --git a/messaging/package.json b/messaging/package.json index 63d99b74..993f52f6 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.1" + "firebase": "^8.4.2" } } diff --git a/perf/package.json b/perf/package.json index 6ad0b16c..2ff32514 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.1" + "firebase": "^8.4.2" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index aa994346..1389599f 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.1" + "firebase": "^8.4.2" } } diff --git a/storage/package.json b/storage/package.json index 22df3b5e..88891d05 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.1" + "firebase": "^8.4.2" } } From 91ddc32aa71b0caf38e8a0ff61e1b1a4be97eb75 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 30 Apr 2021 02:57:28 -0700 Subject: [PATCH 130/235] Auto-update dependencies. (#163) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 8c1e355a..2176f57c 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.2" + "firebase": "^8.4.3" } } diff --git a/auth/package.json b/auth/package.json index 3feb38f5..8dbb99b8 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.4.2", + "firebase": "^8.4.3", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index 0613ac81..973143a7 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.4.2" + "firebase": "^8.4.3" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 57f54180..a72813ae 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.2" + "firebase": "^8.4.3" } } diff --git a/firestore/package.json b/firestore/package.json index 44f37d8d..9843abf3 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.2", + "firebase": "^8.4.3", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 8642b7b7..68d09b40 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.2" + "firebase": "^8.4.3" } } diff --git a/installations/package.json b/installations/package.json index 7128e9ce..bcc06b53 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.4.2" + "firebase": "^8.4.3" } } diff --git a/messaging/package.json b/messaging/package.json index 993f52f6..1582241b 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.2" + "firebase": "^8.4.3" } } diff --git a/perf/package.json b/perf/package.json index 2ff32514..4b320f8b 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.2" + "firebase": "^8.4.3" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 1389599f..cd829ee8 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.2" + "firebase": "^8.4.3" } } diff --git a/storage/package.json b/storage/package.json index 88891d05..db31280c 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.2" + "firebase": "^8.4.3" } } From 12f71f2a94a46bbfe2c1ebac33189ddfc53a764e Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 30 Apr 2021 06:08:36 -0700 Subject: [PATCH 131/235] Auto-update dependencies. (#164) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 27897373..990efa90 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index dc011678..227012bf 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.4.2/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.4.2/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.4.3/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.4.3/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 047d7a6317f833b9469f3bd881b3de80a428b5b9 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 6 May 2021 03:49:48 -0700 Subject: [PATCH 132/235] Auto-update dependencies. (#165) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 2176f57c..14fc1d13 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.3" + "firebase": "^8.5.0" } } diff --git a/auth/package.json b/auth/package.json index 8dbb99b8..2b11527a 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.4.3", + "firebase": "^8.5.0", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index 973143a7..4dd01dde 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.4.3" + "firebase": "^8.5.0" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index a72813ae..89d85aef 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.3" + "firebase": "^8.5.0" } } diff --git a/firestore/package.json b/firestore/package.json index 9843abf3..2ddfc562 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.3", + "firebase": "^8.5.0", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 68d09b40..8e32d6db 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.3" + "firebase": "^8.5.0" } } diff --git a/installations/package.json b/installations/package.json index bcc06b53..0df6ddbd 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.4.3" + "firebase": "^8.5.0" } } diff --git a/messaging/package.json b/messaging/package.json index 1582241b..81626c0e 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.3" + "firebase": "^8.5.0" } } diff --git a/perf/package.json b/perf/package.json index 4b320f8b..b3f57be0 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.3" + "firebase": "^8.5.0" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index cd829ee8..b3ef8837 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.3" + "firebase": "^8.5.0" } } diff --git a/storage/package.json b/storage/package.json index db31280c..913928c1 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.4.3" + "firebase": "^8.5.0" } } From 50abb592172c4de663301ac174d11f3a11c8235a Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 6 May 2021 06:04:57 -0700 Subject: [PATCH 133/235] Auto-update dependencies. (#166) * Auto-update dependencies. * Auto-update dependencies. --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 990efa90..13948c9e 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 227012bf..e881121d 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.4.3/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.4.3/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.5.0/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.5.0/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 8b919f5a49dd6b33dc61f8549933ff170ac05efc Mon Sep 17 00:00:00 2001 From: DPEBot Date: Wed, 12 May 2021 03:12:18 -0700 Subject: [PATCH 134/235] Auto-update dependencies. (#167) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 14fc1d13..1a8b60cc 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.5.0" + "firebase": "^8.6.0" } } diff --git a/auth/package.json b/auth/package.json index 2b11527a..6d6ba384 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.5.0", + "firebase": "^8.6.0", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index 4dd01dde..3882cb78 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.5.0" + "firebase": "^8.6.0" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 89d85aef..01ec70bb 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.5.0" + "firebase": "^8.6.0" } } diff --git a/firestore/package.json b/firestore/package.json index 2ddfc562..d5c943fb 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.5.0", + "firebase": "^8.6.0", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 8e32d6db..143e47bd 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.5.0" + "firebase": "^8.6.0" } } diff --git a/installations/package.json b/installations/package.json index 0df6ddbd..b125227a 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.5.0" + "firebase": "^8.6.0" } } diff --git a/messaging/package.json b/messaging/package.json index 81626c0e..ce2efdad 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.5.0" + "firebase": "^8.6.0" } } diff --git a/perf/package.json b/perf/package.json index b3f57be0..0ce74d47 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.5.0" + "firebase": "^8.6.0" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index b3ef8837..dd5fcfc7 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.5.0" + "firebase": "^8.6.0" } } diff --git a/storage/package.json b/storage/package.json index 913928c1..a3be871b 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.5.0" + "firebase": "^8.6.0" } } From 64e97a1fc4812052105c15f9ab2078c518526b69 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Wed, 12 May 2021 08:44:08 -0700 Subject: [PATCH 135/235] Auto-update dependencies. (#168) * Auto-update dependencies. * Auto-update dependencies. --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 13948c9e..16cc2cab 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index e881121d..f5dba578 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.5.0/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.5.0/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.0/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.0/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From c98e8a63eda12e1fc023f5c067c5acfa26b10c26 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 13 May 2021 02:35:13 -0700 Subject: [PATCH 136/235] Auto-update dependencies. (#169) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 1a8b60cc..89b8245e 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.0" + "firebase": "^8.6.1" } } diff --git a/auth/package.json b/auth/package.json index 6d6ba384..bbf42213 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.0", + "firebase": "^8.6.1", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index 3882cb78..e4ff534e 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.0" + "firebase": "^8.6.1" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 01ec70bb..2064ca60 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.0" + "firebase": "^8.6.1" } } diff --git a/firestore/package.json b/firestore/package.json index d5c943fb..091e3bb3 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.0", + "firebase": "^8.6.1", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 143e47bd..63bb4104 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.0" + "firebase": "^8.6.1" } } diff --git a/installations/package.json b/installations/package.json index b125227a..ebe93b9a 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.0" + "firebase": "^8.6.1" } } diff --git a/messaging/package.json b/messaging/package.json index ce2efdad..13b6147f 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.0" + "firebase": "^8.6.1" } } diff --git a/perf/package.json b/perf/package.json index 0ce74d47..14aa35d7 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.0" + "firebase": "^8.6.1" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index dd5fcfc7..8203d347 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.0" + "firebase": "^8.6.1" } } diff --git a/storage/package.json b/storage/package.json index a3be871b..47358cc6 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.0" + "firebase": "^8.6.1" } } From 435f622fea9cd723456684dc54e58266f46c052c Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 13 May 2021 06:13:20 -0700 Subject: [PATCH 137/235] Auto-update dependencies. (#170) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 16cc2cab..edb6dba7 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index f5dba578..ffe90bba 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.6.0/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.6.0/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 77de7288beb6819e2d1484d42e1d6cca23a04135 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 24 May 2021 04:20:37 -0700 Subject: [PATCH 138/235] Auto-update dependencies. (#173) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 89b8245e..24466723 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.1" + "firebase": "^8.6.2" } } diff --git a/auth/package.json b/auth/package.json index bbf42213..a290447c 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.1", + "firebase": "^8.6.2", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index e4ff534e..90c4cd48 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.1" + "firebase": "^8.6.2" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 2064ca60..8a383365 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.1" + "firebase": "^8.6.2" } } diff --git a/firestore/package.json b/firestore/package.json index 091e3bb3..cf9bca3d 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.1", + "firebase": "^8.6.2", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 63bb4104..fafc55ba 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.1" + "firebase": "^8.6.2" } } diff --git a/installations/package.json b/installations/package.json index ebe93b9a..a4c47386 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.1" + "firebase": "^8.6.2" } } diff --git a/messaging/package.json b/messaging/package.json index 13b6147f..ff48e4e3 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.1" + "firebase": "^8.6.2" } } diff --git a/perf/package.json b/perf/package.json index 14aa35d7..8dd71652 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.1" + "firebase": "^8.6.2" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 8203d347..d1407f79 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.1" + "firebase": "^8.6.2" } } diff --git a/storage/package.json b/storage/package.json index 47358cc6..5cf74105 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.1" + "firebase": "^8.6.2" } } From e6875d81359a71ea27bf3e269db457583f2a20f7 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 24 May 2021 04:32:25 -0700 Subject: [PATCH 139/235] Auto-update dependencies. (#174) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index edb6dba7..1d18be34 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index ffe90bba..be1080e5 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.2/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.2/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 0430462594667080adc6c14800695260186af02e Mon Sep 17 00:00:00 2001 From: DPEBot Date: Tue, 1 Jun 2021 02:37:40 -0700 Subject: [PATCH 140/235] Auto-update dependencies. (#175) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 24466723..24bab3c6 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.2" + "firebase": "^8.6.3" } } diff --git a/auth/package.json b/auth/package.json index a290447c..64ef6639 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.2", + "firebase": "^8.6.3", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index 90c4cd48..c8e18cc9 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.2" + "firebase": "^8.6.3" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 8a383365..d0a7aeb0 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.2" + "firebase": "^8.6.3" } } diff --git a/firestore/package.json b/firestore/package.json index cf9bca3d..5d6159cb 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.2", + "firebase": "^8.6.3", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index fafc55ba..335f1f64 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.2" + "firebase": "^8.6.3" } } diff --git a/installations/package.json b/installations/package.json index a4c47386..dc3cf92d 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.2" + "firebase": "^8.6.3" } } diff --git a/messaging/package.json b/messaging/package.json index ff48e4e3..26bb6a15 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.2" + "firebase": "^8.6.3" } } diff --git a/perf/package.json b/perf/package.json index 8dd71652..36a474ae 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.2" + "firebase": "^8.6.3" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index d1407f79..bc93566b 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.2" + "firebase": "^8.6.3" } } diff --git a/storage/package.json b/storage/package.json index 5cf74105..53a1828f 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.2" + "firebase": "^8.6.3" } } From ceaa80767e5b244fcb2f42dd4fe8889c9818d81a Mon Sep 17 00:00:00 2001 From: DPEBot Date: Tue, 1 Jun 2021 02:46:54 -0700 Subject: [PATCH 141/235] Auto-update dependencies. (#176) Co-authored-by: Sam Stern --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 1d18be34..6732a626 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index be1080e5..6216522a 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.6.2/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.6.2/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.3/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.3/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 7ce58263bec3424205c33f308e78d24400f322ad Mon Sep 17 00:00:00 2001 From: DPEBot Date: Tue, 8 Jun 2021 04:14:24 -0700 Subject: [PATCH 142/235] Auto-update dependencies. (#179) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 6732a626..38b866cc 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 6216522a..3a33e075 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.6.3/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.6.3/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.5/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.5/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 54afdf5549a8571a19e03f430e8fd86d5c944203 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Tue, 8 Jun 2021 04:20:02 -0700 Subject: [PATCH 143/235] Auto-update dependencies. (#177) Brought to you by your friendly [Repository Gardener](https://github.com/GoogleCloudPlatform/repository-gardener). --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 24bab3c6..b94f5885 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.3" + "firebase": "^8.6.5" } } diff --git a/auth/package.json b/auth/package.json index 64ef6639..d5183071 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.3", + "firebase": "^8.6.5", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index c8e18cc9..c247ac9e 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.3" + "firebase": "^8.6.5" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index d0a7aeb0..fc812865 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.3" + "firebase": "^8.6.5" } } diff --git a/firestore/package.json b/firestore/package.json index 5d6159cb..53ff7f4d 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.3", + "firebase": "^8.6.5", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 335f1f64..d7e245c3 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.3" + "firebase": "^8.6.5" } } diff --git a/installations/package.json b/installations/package.json index dc3cf92d..bd991ac5 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.3" + "firebase": "^8.6.5" } } diff --git a/messaging/package.json b/messaging/package.json index 26bb6a15..91cf4f7c 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.3" + "firebase": "^8.6.5" } } diff --git a/perf/package.json b/perf/package.json index 36a474ae..fa22f5f1 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.3" + "firebase": "^8.6.5" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index bc93566b..1c4d08d4 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.3" + "firebase": "^8.6.5" } } diff --git a/storage/package.json b/storage/package.json index 53a1828f..4173cb9a 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.3" + "firebase": "^8.6.5" } } From 4fadb8758d103fbf1bd3f994a78a77b5d2f723f7 Mon Sep 17 00:00:00 2001 From: Dharmaraj <63334359+DharmarajX24@users.noreply.github.com> Date: Thu, 10 Jun 2021 16:11:56 +0530 Subject: [PATCH 144/235] Added updateProfile and updateEmail for modular SDK (#178) --- .gitignore | 1 + auth-next/manage.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 auth-next/manage.js diff --git a/.gitignore b/.gitignore index 5759f295..9d79b150 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules tsconfig.json dist/ .DS_Store +.idea diff --git a/auth-next/manage.js b/auth-next/manage.js new file mode 100644 index 00000000..37f4c734 --- /dev/null +++ b/auth-next/manage.js @@ -0,0 +1,29 @@ +function updateUserProfile() { + // [START auth_update_user_profile] + const { getAuth, updateProfile } = require("firebase/auth"); + const auth = getAuth(); + updateProfile(auth.currentUser, { + displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg" + }).then(() => { + // Profile updated! + }).catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // .. + }); + // [END auth_update_user_profile] +} + +function updateUserEmail() { + // [START auth_update_user_email] + const { getAuth, updateEmail } = require("firebase/auth"); + const auth = getAuth(); + updateEmail(auth.currentUser, "user@example.com").then(() => { + // Email updated! + }).catch((error) => { + const errorCode = error.code; + const errorMessage = error.message; + // .. + }); + // [END auth_update_user_email] +} From 8185ab90e151ef75faf780e39759b22dcde6498e Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Thu, 10 Jun 2021 06:59:33 -0400 Subject: [PATCH 145/235] Auth manage snippets (#181) --- auth-next/manage.js | 91 ++++++++++++++----- auth/manage.js | 70 ++++++++++++++ .../auth-next/manage/auth_get_user_profile.js | 23 +++++ .../manage/auth_get_user_profile_provider.js | 21 +++++ .../manage/auth_update_user_email.js | 16 ++++ .../manage/auth_update_user_profile.js | 18 ++++ 6 files changed, 215 insertions(+), 24 deletions(-) create mode 100644 auth/manage.js create mode 100644 snippets/auth-next/manage/auth_get_user_profile.js create mode 100644 snippets/auth-next/manage/auth_get_user_profile_provider.js create mode 100644 snippets/auth-next/manage/auth_update_user_email.js create mode 100644 snippets/auth-next/manage/auth_update_user_profile.js diff --git a/auth-next/manage.js b/auth-next/manage.js index 37f4c734..442cfa0b 100644 --- a/auth-next/manage.js +++ b/auth-next/manage.js @@ -1,29 +1,72 @@ -function updateUserProfile() { - // [START auth_update_user_profile] - const { getAuth, updateProfile } = require("firebase/auth"); - const auth = getAuth(); - updateProfile(auth.currentUser, { - displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg" - }).then(() => { - // Profile updated! - }).catch((error) => { - const errorCode = error.code; - const errorMessage = error.message; - // .. +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +function getUserProfile() { + // [START auth_get_user_profile] + const { getAuth } = require("firebase/auth"); + + const auth = getAuth(); + const user = auth.currentUser; + if (user !== null) { + // The user object has basic properties such as display name, email, etc. + const displayName = user.displayName; + const email = user.email; + const photoURL = user.photoURL; + const emailVerified = user.emailVerified; + + // The user's ID, unique to the Firebase project. Do NOT use + // this value to authenticate with your backend server, if + // you have one. Use User.getToken() instead. + const uid = user.uid; + } + // [END auth_get_user_profile] +} + +function getUserProfileProvider() { + // [START auth_get_user_profile_provider] + const { getAuth } = require("firebase/auth"); + + const auth = getAuth(); + const user = auth.currentUser; + + if (user !== null) { + user.providerData.forEach((profile) => { + console.log("Sign-in provider: " + profile.providerId); + console.log(" Provider-specific UID: " + profile.uid); + console.log(" Name: " + profile.displayName); + console.log(" Email: " + profile.email); + console.log(" Photo URL: " + profile.photoURL); }); - // [END auth_update_user_profile] + } + // [END auth_get_user_profile_provider] +} + +function updateUserProfile() { + // [START auth_update_user_profile] + const { getAuth, updateProfile } = require("firebase/auth"); + const auth = getAuth(); + updateProfile(auth.currentUser, { + displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg" + }).then(() => { + // Profile updated! + // ... + }).catch((error) => { + // An error occurred + // ... + }); + // [END auth_update_user_profile] } function updateUserEmail() { - // [START auth_update_user_email] - const { getAuth, updateEmail } = require("firebase/auth"); - const auth = getAuth(); - updateEmail(auth.currentUser, "user@example.com").then(() => { - // Email updated! - }).catch((error) => { - const errorCode = error.code; - const errorMessage = error.message; - // .. - }); - // [END auth_update_user_email] + // [START auth_update_user_email] + const { getAuth, updateEmail } = require("firebase/auth"); + const auth = getAuth(); + updateEmail(auth.currentUser, "user@example.com").then(() => { + // Email updated! + // ... + }).catch((error) => { + // An error occurred + // ... + }); + // [END auth_update_user_email] } diff --git a/auth/manage.js b/auth/manage.js new file mode 100644 index 00000000..ed451c1b --- /dev/null +++ b/auth/manage.js @@ -0,0 +1,70 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +function getUserProfile() { + // [START auth_get_user_profile] + const user = firebase.auth().currentUser; + if (user !== null) { + // The user object has basic properties such as display name, email, etc. + const displayName = user.displayName; + const email = user.email; + const photoURL = user.photoURL; + const emailVerified = user.emailVerified; + + // The user's ID, unique to the Firebase project. Do NOT use + // this value to authenticate with your backend server, if + // you have one. Use User.getToken() instead. + const uid = user.uid; + } + // [END auth_get_user_profile] +} + +function getUserProfileProvider() { + // [START auth_get_user_profile_provider] + const user = firebase.auth().currentUser; + + if (user !== null) { + user.providerData.forEach((profile) => { + console.log("Sign-in provider: " + profile.providerId); + console.log(" Provider-specific UID: " + profile.uid); + console.log(" Name: " + profile.displayName); + console.log(" Email: " + profile.email); + console.log(" Photo URL: " + profile.photoURL); + }); + } + // [END auth_get_user_profile_provider] +} + +function updateUserProfile() { + // [START auth_update_user_profile] + const user = firebase.auth().currentUser; + + user.updateProfile({ + displayName: "Jane Q. User", + photoURL: "https://example.com/jane-q-user/profile.jpg" + }).then(() => { + // Update successful + // ... + }).catch((error) => { + // An error occurred + // ... + }); + // [END auth_update_user_profile] +} + +function updateUserEmail() { + // [START auth_update_user_email] + const user = firebase.auth().currentUser; + + user.updateEmail("user@example.com").then(() => { + // Update successful + // ... + }).catch((error) => { + // An error occurred + // ... + }); + // [END auth_update_user_email] +} diff --git a/snippets/auth-next/manage/auth_get_user_profile.js b/snippets/auth-next/manage/auth_get_user_profile.js new file mode 100644 index 00000000..106104e8 --- /dev/null +++ b/snippets/auth-next/manage/auth_get_user_profile.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/manage.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_get_user_profile_modular] +import { getAuth } from "firebase/auth"; + +const auth = getAuth(); +const user = auth.currentUser; +if (user !== null) { + // The user object has basic properties such as display name, email, etc. + const displayName = user.displayName; + const email = user.email; + const photoURL = user.photoURL; + const emailVerified = user.emailVerified; + + // The user's ID, unique to the Firebase project. Do NOT use + // this value to authenticate with your backend server, if + // you have one. Use User.getToken() instead. + const uid = user.uid; +} +// [END auth_get_user_profile_modular] \ No newline at end of file diff --git a/snippets/auth-next/manage/auth_get_user_profile_provider.js b/snippets/auth-next/manage/auth_get_user_profile_provider.js new file mode 100644 index 00000000..63e9654f --- /dev/null +++ b/snippets/auth-next/manage/auth_get_user_profile_provider.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/manage.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_get_user_profile_provider_modular] +import { getAuth } from "firebase/auth"; + +const auth = getAuth(); +const user = auth.currentUser; + +if (user !== null) { + user.providerData.forEach((profile) => { + console.log("Sign-in provider: " + profile.providerId); + console.log(" Provider-specific UID: " + profile.uid); + console.log(" Name: " + profile.displayName); + console.log(" Email: " + profile.email); + console.log(" Photo URL: " + profile.photoURL); + }); +} +// [END auth_get_user_profile_provider_modular] \ No newline at end of file diff --git a/snippets/auth-next/manage/auth_update_user_email.js b/snippets/auth-next/manage/auth_update_user_email.js new file mode 100644 index 00000000..8e313ece --- /dev/null +++ b/snippets/auth-next/manage/auth_update_user_email.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/manage.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_update_user_email_modular] +import { getAuth, updateEmail } from "firebase/auth"; +const auth = getAuth(); +updateEmail(auth.currentUser, "user@example.com").then(() => { + // Email updated! + // ... +}).catch((error) => { + // An error occurred + // ... +}); +// [END auth_update_user_email_modular] \ No newline at end of file diff --git a/snippets/auth-next/manage/auth_update_user_profile.js b/snippets/auth-next/manage/auth_update_user_profile.js new file mode 100644 index 00000000..9449474e --- /dev/null +++ b/snippets/auth-next/manage/auth_update_user_profile.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/manage.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_update_user_profile_modular] +import { getAuth, updateProfile } from "firebase/auth"; +const auth = getAuth(); +updateProfile(auth.currentUser, { + displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg" +}).then(() => { + // Profile updated! + // ... +}).catch((error) => { + // An error occurred + // ... +}); +// [END auth_update_user_profile_modular] \ No newline at end of file From 01c3aa926b72c3441aa8c9ea32d52ec3234d8215 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 10 Jun 2021 13:00:50 +0100 Subject: [PATCH 146/235] Current user snippets --- auth-next/index.js | 17 +++++++++++++++++ auth/index.js | 14 ++++++++++++++ snippets/auth-next/index/auth_current_user.js | 19 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 snippets/auth-next/index/auth_current_user.js diff --git a/auth-next/index.js b/auth-next/index.js index 9c8168b8..73d33219 100644 --- a/auth-next/index.js +++ b/auth-next/index.js @@ -63,6 +63,23 @@ function authStateListener() { // [END auth_state_listener] } +function currentUser() { + // [START auth_current_user] + const { getAuth } = require("firebase/auth"); + + const auth = getAuth(); + const user = auth.currentUser; + + if (user) { + // User is signed in, see docs for a list of available properties + // https://firebase.google.com/docs/reference/js/firebase.User + // ... + } else { + // No user is signed in. + } + // [END auth_current_user] +} + function setLanguageCode() { // [START auth_set_language_code] const { getAuth } = require("firebase/auth"); diff --git a/auth/index.js b/auth/index.js index cae8831b..6ea5d587 100644 --- a/auth/index.js +++ b/auth/index.js @@ -54,6 +54,20 @@ function authStateListener() { // [END auth_state_listener] } +function currentUser() { + // [START auth_current_user] + const user = firebase.auth().currentUser; + + if (user) { + // User is signed in, see docs for a list of available properties + // https://firebase.google.com/docs/reference/js/firebase.User + // ... + } else { + // No user is signed in. + } + // [END auth_current_user] +} + function setLanguageCode() { // [START auth_set_language_code] firebase.auth().languageCode = 'it'; diff --git a/snippets/auth-next/index/auth_current_user.js b/snippets/auth-next/index/auth_current_user.js new file mode 100644 index 00000000..474f66bf --- /dev/null +++ b/snippets/auth-next/index/auth_current_user.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_current_user_modular] +import { getAuth } from "firebase/auth"; + +const auth = getAuth(); +const user = auth.currentUser; + +if (user) { + // User is signed in, see docs for a list of available properties + // https://firebase.google.com/docs/reference/js/firebase.User + // ... +} else { + // No user is signed in. +} +// [END auth_current_user_modular] \ No newline at end of file From 2f9922a96c240407ffaaa9d10b014bbd32b2002d Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 10 Jun 2021 13:16:45 +0100 Subject: [PATCH 147/235] Rest of the manage snippets --- auth-next/manage.js | 96 +++++++++++++++++++ auth/manage.js | 81 ++++++++++++++++ snippets/auth-next/manage/auth_delete_user.js | 18 ++++ .../manage/auth_send_password_reset.js | 18 ++++ .../auth-next/manage/auth_update_password.js | 20 ++++ .../manage/send_email_verification.js | 18 ++++ 6 files changed, 251 insertions(+) create mode 100644 snippets/auth-next/manage/auth_delete_user.js create mode 100644 snippets/auth-next/manage/auth_send_password_reset.js create mode 100644 snippets/auth-next/manage/auth_update_password.js create mode 100644 snippets/auth-next/manage/send_email_verification.js diff --git a/auth-next/manage.js b/auth-next/manage.js index 442cfa0b..49b21301 100644 --- a/auth-next/manage.js +++ b/auth-next/manage.js @@ -70,3 +70,99 @@ function updateUserEmail() { }); // [END auth_update_user_email] } + +function sendEmailVerification() { + // [START send_email_verification] + const { getAuth, sendEmailVerification } = require("firebase/auth"); + + const auth = getAuth(); + const user = auth.currentUser; + + sendEmailVerification(user).then(() => { + // Email sent. + }).catch((error) => { + // An error ocurred + // ... + }); + // [END send_email_verification] +} + +function updatePassword() { + function getASecureRandomPassword() { + return "correcthorsebatterystaple"; + } + + // [START auth_update_password] + const { getAuth, updatePassword } = require("firebase/auth"); + + const auth = getAuth(); + + const user = auth.currentUser; + const newPassword = getASecureRandomPassword(); + + updatePassword(user, newPassword).then(() => { + // Update successful. + }).catch((error) => { + // An error ocurred + // ... + }); + // [END auth_update_password] +} + +function sendPasswordReset() { + // [START auth_send_password_reset] + const { getAuth, sendPasswordResetEmail } = require("firebase/auth"); + + const auth = getAuth(); + const emailAddress = "user@example.com"; + + sendPasswordResetEmail(auth, emailAddress).then(() => { + // Email sent. + }).catch((error) => { + // An error ocurred + // ... + }); + // [END auth_send_password_reset] +} + +function deleteUser() { + // [START auth_delete_user] + const { getAuth, deleteUser } = require("firebase/auth"); + + const auth = getAuth(); + const user = auth.currentUser; + + deleteUser(user).then(() => { + // User deleted. + }).catch((error) => { + // An error ocurred + // ... + }); + // [END auth_delete_user] +} + +function reauthenticateWithCredential() { + /** + * @returns {object} + */ + function promptForCredentials() { + return {}; + } + + // [START auth_reauth_with-credential] + const { getAuth, reauthenticateWithCredential } = require("firebase/auth"); + + const auth = getAuth(); + const user = auth.currentUser; + + // TODO(you): prompt the user to re-provide their sign-in credentials + const credential = promptForCredentials(); + + reauthenticateWithCredential(user, credential).then(() => { + // User re-authenticated. + }).catch((error) => { + // An error ocurred + // ... + }); + // [END auth_reauth_with-credential] +} diff --git a/auth/manage.js b/auth/manage.js index ed451c1b..71d6cd45 100644 --- a/auth/manage.js +++ b/auth/manage.js @@ -68,3 +68,84 @@ function updateUserEmail() { }); // [END auth_update_user_email] } + +function sendEmailVerification() { + // [START send_email_verification] + const user = firebase.auth().currentUser; + + user.sendEmailVerification().then(() => { + // Email sent. + }).catch((error) => { + // An error ocurred + // ... + }); + // [END send_email_verification] +} + +function updatePassword() { + function getASecureRandomPassword() { + return "correcthorsebatterystaple"; + } + + // [START auth_update_password] + const user = firebase.auth().currentUser; + const newPassword = getASecureRandomPassword(); + + user.updatePassword(newPassword).then(() => { + // Update successful. + }).catch((error) => { + // An error ocurred + // ... + }); + // [END auth_update_password] +} + +function sendPasswordReset() { + // [START auth_send_password_reset] + const auth = firebase.auth(); + const emailAddress = "user@example.com"; + + auth.sendPasswordResetEmail(emailAddress).then(() => { + // Email sent. + }).catch((error) => { + // An error ocurred + // ... + }); + // [END auth_send_password_reset] +} + +function deleteUser() { + // [START auth_delete_user] + const user = firebase.auth().currentUser; + + user.delete().then(() => { + // User deleted. + }).catch((error) => { + // An error ocurred + // ... + }); + // [END auth_delete_user] +} + +function reauthenticateWithCredential() { + /** + * @returns {object} + */ + function promptForCredentials() { + return {}; + } + + // [START auth_reauth_with-credential] + const user = firebase.auth().currentUser; + + // TODO(you): prompt the user to re-provide their sign-in credentials + const credential = promptForCredentials(); + + user.reauthenticateWithCredential(credential).then(() => { + // User re-authenticated. + }).catch((error) => { + // An error ocurred + // ... + }); + // [END auth_reauth_with-credential] +} diff --git a/snippets/auth-next/manage/auth_delete_user.js b/snippets/auth-next/manage/auth_delete_user.js new file mode 100644 index 00000000..8d725aa4 --- /dev/null +++ b/snippets/auth-next/manage/auth_delete_user.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/manage.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_delete_user_modular] +import { getAuth, deleteUser } from "firebase/auth"; + +const auth = getAuth(); +const user = auth.currentUser; + +deleteUser(user).then(() => { + // User deleted. +}).catch((error) => { + // An error ocurred + // ... +}); +// [END auth_delete_user_modular] \ No newline at end of file diff --git a/snippets/auth-next/manage/auth_send_password_reset.js b/snippets/auth-next/manage/auth_send_password_reset.js new file mode 100644 index 00000000..fa6118bb --- /dev/null +++ b/snippets/auth-next/manage/auth_send_password_reset.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/manage.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_send_password_reset_modular] +import { getAuth, sendPasswordResetEmail } from "firebase/auth"; + +const auth = getAuth(); +const emailAddress = "user@example.com"; + +sendPasswordResetEmail(auth, emailAddress).then(() => { + // Email sent. +}).catch((error) => { + // An error ocurred + // ... +}); +// [END auth_send_password_reset_modular] \ No newline at end of file diff --git a/snippets/auth-next/manage/auth_update_password.js b/snippets/auth-next/manage/auth_update_password.js new file mode 100644 index 00000000..69543928 --- /dev/null +++ b/snippets/auth-next/manage/auth_update_password.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/manage.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_update_password_modular] +import { getAuth, updatePassword } from "firebase/auth"; + +const auth = getAuth(); + +const user = auth.currentUser; +const newPassword = getASecureRandomPassword(); + +updatePassword(user, newPassword).then(() => { + // Update successful. +}).catch((error) => { + // An error ocurred + // ... +}); +// [END auth_update_password_modular] \ No newline at end of file diff --git a/snippets/auth-next/manage/send_email_verification.js b/snippets/auth-next/manage/send_email_verification.js new file mode 100644 index 00000000..82b0dcf9 --- /dev/null +++ b/snippets/auth-next/manage/send_email_verification.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/manage.js +// +// To make edits to the snippets in this file, please edit the source + +// [START send_email_verification_modular] +import { getAuth, sendEmailVerification } from "firebase/auth"; + +const auth = getAuth(); +const user = auth.currentUser; + +sendEmailVerification(user).then(() => { + // Email sent. +}).catch((error) => { + // An error ocurred + // ... +}); +// [END send_email_verification_modular] \ No newline at end of file From 6fee4dc019264742d992e45293fe73cf714a5018 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 10 Jun 2021 13:32:51 +0100 Subject: [PATCH 148/235] Fix one tag --- auth-next/manage.js | 4 ++-- auth/manage.js | 4 ++-- .../manage/auth_reauth_with_credential.js | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 snippets/auth-next/manage/auth_reauth_with_credential.js diff --git a/auth-next/manage.js b/auth-next/manage.js index 49b21301..bf603ccc 100644 --- a/auth-next/manage.js +++ b/auth-next/manage.js @@ -149,7 +149,7 @@ function reauthenticateWithCredential() { return {}; } - // [START auth_reauth_with-credential] + // [START auth_reauth_with_credential] const { getAuth, reauthenticateWithCredential } = require("firebase/auth"); const auth = getAuth(); @@ -164,5 +164,5 @@ function reauthenticateWithCredential() { // An error ocurred // ... }); - // [END auth_reauth_with-credential] + // [END auth_reauth_with_credential] } diff --git a/auth/manage.js b/auth/manage.js index 71d6cd45..7163ef00 100644 --- a/auth/manage.js +++ b/auth/manage.js @@ -135,7 +135,7 @@ function reauthenticateWithCredential() { return {}; } - // [START auth_reauth_with-credential] + // [START auth_reauth_with_credential] const user = firebase.auth().currentUser; // TODO(you): prompt the user to re-provide their sign-in credentials @@ -147,5 +147,5 @@ function reauthenticateWithCredential() { // An error ocurred // ... }); - // [END auth_reauth_with-credential] + // [END auth_reauth_with_credential] } diff --git a/snippets/auth-next/manage/auth_reauth_with_credential.js b/snippets/auth-next/manage/auth_reauth_with_credential.js new file mode 100644 index 00000000..0b02de6c --- /dev/null +++ b/snippets/auth-next/manage/auth_reauth_with_credential.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/manage.js +// +// To make edits to the snippets in this file, please edit the source + +// [START auth_reauth_with_credential_modular] +import { getAuth, reauthenticateWithCredential } from "firebase/auth"; + +const auth = getAuth(); +const user = auth.currentUser; + +// TODO(you): prompt the user to re-provide their sign-in credentials +const credential = promptForCredentials(); + +reauthenticateWithCredential(user, credential).then(() => { + // User re-authenticated. +}).catch((error) => { + // An error ocurred + // ... +}); +// [END auth_reauth_with_credential_modular] \ No newline at end of file From d78b4d2f955b586d9ec0e125c3adfcc7742ed80a Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 11 Jun 2021 02:26:09 -0700 Subject: [PATCH 149/235] Auto-update dependencies. (#182) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index b94f5885..cc5fc126 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.5" + "firebase": "^8.6.7" } } diff --git a/auth/package.json b/auth/package.json index d5183071..c049b151 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.5", + "firebase": "^8.6.7", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index c247ac9e..e5c6e37c 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.5" + "firebase": "^8.6.7" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index fc812865..e7ab4fc6 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.5" + "firebase": "^8.6.7" } } diff --git a/firestore/package.json b/firestore/package.json index 53ff7f4d..1c3c4360 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.5", + "firebase": "^8.6.7", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index d7e245c3..1119e0dc 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.5" + "firebase": "^8.6.7" } } diff --git a/installations/package.json b/installations/package.json index bd991ac5..f7f4edee 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.5" + "firebase": "^8.6.7" } } diff --git a/messaging/package.json b/messaging/package.json index 91cf4f7c..db8faba3 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.5" + "firebase": "^8.6.7" } } diff --git a/perf/package.json b/perf/package.json index fa22f5f1..5e300b1f 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.5" + "firebase": "^8.6.7" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 1c4d08d4..fc4287df 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.5" + "firebase": "^8.6.7" } } diff --git a/storage/package.json b/storage/package.json index 4173cb9a..d52a0fc9 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.5" + "firebase": "^8.6.7" } } From fccb4eb27619856d85f1fe5fd320bb23b7c1f31f Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 11 Jun 2021 05:32:01 -0700 Subject: [PATCH 150/235] Auto-update dependencies. (#183) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 38b866cc..43629560 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 3a33e075..83cdfa98 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.6.5/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.6.5/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.7/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.7/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From f38981820e0c0ac9f3cc57f425e34f76c629d2aa Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 11 Jun 2021 08:47:17 -0400 Subject: [PATCH 151/235] SDK v9.0.0-beta.3 (#184) --- analytics-next/package.json | 2 +- auth-next/package.json | 2 +- database-next/package.json | 2 +- firebaseapp-next/package.json | 2 +- firestore-next/package.json | 2 +- functions-next/package.json | 2 +- messaging-next/package.json | 2 +- perf-next/package.json | 2 +- remoteconfig-next/package.json | 2 +- storage-next/package.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index c680a4f2..fc41c09e 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.1" + "firebase": "^9.0.0-beta.3" } } diff --git a/auth-next/package.json b/auth-next/package.json index 19e3cdd9..628a59ca 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.1" + "firebase": "^9.0.0-beta.3" } } diff --git a/database-next/package.json b/database-next/package.json index 22ed471f..b97354bb 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.1" + "firebase": "^9.0.0-beta.3" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index 0490b5e8..660b3a4a 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.1" + "firebase": "^9.0.0-beta.3" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 929358a7..503db5bd 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.1", + "firebase": "^9.0.0-beta.3", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/package.json b/functions-next/package.json index c9ff1ffc..a9de34b8 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.1" + "firebase": "^9.0.0-beta.3" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index 37d5e35a..785a3025 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.1" + "firebase": "^9.0.0-beta.3" } } diff --git a/perf-next/package.json b/perf-next/package.json index 8865057a..f57ee6fe 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.1" + "firebase": "^9.0.0-beta.3" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index 54cfa5d9..5295c660 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.1" + "firebase": "^9.0.0-beta.3" } } diff --git a/storage-next/package.json b/storage-next/package.json index 7777f2d0..00ccd216 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.1" + "firebase": "^9.0.0-beta.3" } } From 6d42e4114a857c53f5c3fb49555d32b73521dccc Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 11 Jun 2021 09:11:48 -0400 Subject: [PATCH 152/235] Move to pnpm (#185) --- .github/workflows/test.yml | 6 ++--- .gitignore | 1 + analytics-next/ecommerce.js | 24 ++++++++--------- firestore-next/test.solution-arrays.js | 4 +-- firestore-next/test.solution-counters.js | 4 +-- lerna.json | 27 ------------------- package.json | 7 ++--- .../ecommerce/analytics_ecommerce_add_cart.js | 2 +- .../ecommerce/analytics_ecommerce_checkout.js | 2 +- .../analytics_ecommerce_payment_info.js | 2 +- .../analytics_ecommerce_promotions.js | 2 +- .../ecommerce/analytics_ecommerce_purchase.js | 2 +- .../ecommerce/analytics_ecommerce_refund.js | 2 +- .../analytics_ecommerce_remove_cart.js | 2 +- .../analytics_ecommerce_select_item.js | 2 +- .../analytics_ecommerce_shipping_info.js | 2 +- .../analytics_ecommerce_view_cart.js | 2 +- .../analytics_ecommerce_view_item_details.js | 2 +- .../analytics_ecommerce_view_item_list.js | 2 +- .../query_in_category_timestamp.js | 2 +- .../query_in_category_timestamp_invalid.js | 2 +- .../test-solution-counters/get_count.js | 2 +- .../increment_counter.js | 2 +- 23 files changed, 40 insertions(+), 65 deletions(-) delete mode 100644 lerna.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b619cd36..dbfa11d6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: node-version: - - 10.x + - 12.x steps: - uses: actions/checkout@v1 - uses: actions/setup-node@v1 @@ -29,13 +29,13 @@ jobs: - name: Install dependencies run: | npm install - npm run lerna-bootstrap + npm run bootstrap - name: Lint snippets run: npm run lint - name: Compile snippets - run: npm run lerna-compile + run: npm run compile - name: Check generated snippets run: | diff --git a/.gitignore b/.gitignore index 9d79b150..435f90ea 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ tsconfig.json dist/ .DS_Store .idea +pnpm-lock.yaml diff --git a/analytics-next/ecommerce.js b/analytics-next/ecommerce.js index c4c7807c..081aad48 100644 --- a/analytics-next/ecommerce.js +++ b/analytics-next/ecommerce.js @@ -35,7 +35,7 @@ const item_socks = { function ecommerceViewItemList() { // [START analytics_ecommerce_view_item_list] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Prepare ecommerce params const params1 = { @@ -52,7 +52,7 @@ function ecommerceViewItemList() { function ecommerceSelectItem() { // [START analytics_ecommerce_select_item] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Prepare ecommerce event params const params2 = { @@ -69,7 +69,7 @@ function ecommerceSelectItem() { function ecommerceViewItemDetails() { // [START analytics_ecommerce_view_item_details] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Prepare ecommerce event params const params3 = { @@ -86,7 +86,7 @@ function ecommerceViewItemDetails() { function ecommerceAddCart() { // [START analytics_ecommerce_add_cart] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Specify order quantity const item_jeggings_quantity = { @@ -112,7 +112,7 @@ function ecommerceAddCart() { function ecommerceViewCart() { // [START analytics_ecommerce_view_cart] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Specify order quantity const item_jeggings_quantity = { @@ -140,7 +140,7 @@ function ecommerceViewCart() { function ecommerceRemoveCart() { // [START analytics_ecommerce_remove_cart] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Prepare ecommerce params const params6 = { @@ -157,7 +157,7 @@ function ecommerceRemoveCart() { function ecommerceCheckout() { // [START analytics_ecommerce_checkout] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Prepare ecommerce params const params7 = { @@ -175,7 +175,7 @@ function ecommerceCheckout() { function ecommerceShippingInfo() { // [START analytics_ecommerce_shipping_info] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Prepare ecommerce params const params8 = { @@ -194,7 +194,7 @@ function ecommerceShippingInfo() { function ecommercePaymentInfo() { // [START analytics_ecommerce_payment_info] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Prepare ecommerce params const params9 = { @@ -213,7 +213,7 @@ function ecommercePaymentInfo() { function ecommercePurchase() { // [START analytics_ecommerce_purchase] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Prepare ecommerce bundle const params10 = { @@ -235,7 +235,7 @@ function ecommercePurchase() { function ecommerceRefund() { // [START analytics_ecommerce_refund] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Prepare ecommerce params const params11 = { @@ -262,7 +262,7 @@ function ecommerceRefund() { function ecommercePromotions() { // [START analytics_ecommerce_promotions] - const { getAnalytics, logEvent } = require("@firebase/analytics"); + const { getAnalytics, logEvent } = require("firebase/analytics"); // Prepare ecommerce params const params12 = { diff --git a/firestore-next/test.solution-arrays.js b/firestore-next/test.solution-arrays.js index 7986ef6f..3ca186ac 100644 --- a/firestore-next/test.solution-arrays.js +++ b/firestore-next/test.solution-arrays.js @@ -78,7 +78,7 @@ describe("firestore-solution-arrays", () => { it("should query in a category by timestamp", () => { function queryOne() { // [START query_in_category_timestamp_invalid] - const { collection, query, where, orderBy, FirebaseFirestore } = require("@firebase/firestore"); + const { collection, query, where, orderBy, FirebaseFirestore } = require("firebase/firestore"); const q = query(collection(db, "posts"), where("categories.cats", "==", true), @@ -89,7 +89,7 @@ describe("firestore-solution-arrays", () => { function queryTwo() { // [START query_in_category_timestamp] - const { collection, query, where, orderBy } = require("@firebase/firestore"); + const { collection, query, where, orderBy } = require("firebase/firestore"); const q = query(collection(db, "posts"), where("categories.cats", ">", 0), diff --git a/firestore-next/test.solution-counters.js b/firestore-next/test.solution-counters.js index 2e00e8d9..ec671731 100644 --- a/firestore-next/test.solution-counters.js +++ b/firestore-next/test.solution-counters.js @@ -28,7 +28,7 @@ function createCounter(ref, num_shards) { // [START increment_counter] function incrementCounter(db, ref, num_shards) { - const { collection, doc, updateDoc, increment, FirebaseFirestore } = require("@firebase/firestore"); + const { doc, updateDoc, increment } = require("firebase/firestore"); // Select a shard of the counter at random const shardId = Math.floor(Math.random() * num_shards).toString(); @@ -41,7 +41,7 @@ function incrementCounter(db, ref, num_shards) { // [START get_count] async function getCount(ref) { - const { collection, getDocs } = require("@firebase/firestore"); + const { collection, getDocs } = require("firebase/firestore"); // Sum the count of each shard in the subcollection const snapshot = await getDocs(collection(ref, 'shards')); diff --git a/lerna.json b/lerna.json deleted file mode 100644 index a14444a4..00000000 --- a/lerna.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "lerna": "2.8.0", - "packages": [ - "analytics", - "analytics-next", - "auth", - "auth-next", - "database", - "database-next", - "firebaseapp", - "firebaseapp-next", - "firestore", - "firestore-next", - "functions", - "functions-next", - "installations", - "messaging", - "messaging-next", - "perf", - "perf-next", - "remoteconfig", - "remoteconfig-next", - "storage", - "storage-next" - ], - "version": "1.0.0" -} diff --git a/package.json b/package.json index 6eb29b72..e7621ce2 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,14 @@ "snippets": "rimraf snippets && ts-node scripts/separate-snippets.ts", "lint": "git ls-files | grep -v 'snippets/' | grep '.js$' | xargs npx eslint", "format": "npm run lint -- --fix", - "lerna-bootstrap": "lerna bootstrap --no-ci", - "lerna-compile": "lerna run compile" + "bootstrap": "pnpm recursive install", + "compile": "pnpm recursive run compile --workspace-concurrency=4" }, "license": "Apache-2.0", "devDependencies": { + "@types/node": "^15.12.2", "eslint": "^7.16.0", - "lerna": "^3.22.1", + "pnpm": "^6.7.4", "rimraf": "^3.0.2", "ts-node": "^9.0.0", "typescript": "^3.8.3" diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js index 0fc501d9..8d7f87cf 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_add_cart_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Specify order quantity const item_jeggings_quantity = { diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js index 0e369459..85611fb1 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_checkout_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Prepare ecommerce params const params7 = { diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js index 17ea80d1..db328513 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_payment_info_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Prepare ecommerce params const params9 = { diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js index a099a1ac..666241ee 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_promotions_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Prepare ecommerce params const params12 = { diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js index ea589cb7..a5ba8c62 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_purchase_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Prepare ecommerce bundle const params10 = { diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js index f7d1f8f8..fab84487 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_refund_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Prepare ecommerce params const params11 = { diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js index 9bec3f7d..aa841d8f 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_remove_cart_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Prepare ecommerce params const params6 = { diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js index a4e7ec58..74f3c8c2 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_select_item_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Prepare ecommerce event params const params2 = { diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js index d2f2ccaa..09cd0f05 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_shipping_info_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Prepare ecommerce params const params8 = { diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js index bfe02fd0..89ab04ec 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_view_cart_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Specify order quantity const item_jeggings_quantity = { diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js index ebd74763..920e2c18 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_view_item_details_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Prepare ecommerce event params const params3 = { diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js index c66f0d20..13eb197c 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START analytics_ecommerce_view_item_list_modular] -import { getAnalytics, logEvent } from "@firebase/analytics"; +import { getAnalytics, logEvent } from "firebase/analytics"; // Prepare ecommerce params const params1 = { diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js index 88477e12..31336fac 100644 --- a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js +++ b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START query_in_category_timestamp_modular] -import { collection, query, where, orderBy } from "@firebase/firestore"; +import { collection, query, where, orderBy } from "firebase/firestore"; const q = query(collection(db, "posts"), where("categories.cats", ">", 0), diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js index 65a84c9f..29c0a18c 100644 --- a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js +++ b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START query_in_category_timestamp_invalid_modular] -import { collection, query, where, orderBy, FirebaseFirestore } from "@firebase/firestore"; +import { collection, query, where, orderBy, FirebaseFirestore } from "firebase/firestore"; const q = query(collection(db, "posts"), where("categories.cats", "==", true), diff --git a/snippets/firestore-next/test-solution-counters/get_count.js b/snippets/firestore-next/test-solution-counters/get_count.js index 614173c9..2fc01217 100644 --- a/snippets/firestore-next/test-solution-counters/get_count.js +++ b/snippets/firestore-next/test-solution-counters/get_count.js @@ -5,7 +5,7 @@ // [START get_count_modular] async function getCount(ref) { - import { collection, getDocs } from "@firebase/firestore"; + import { collection, getDocs } from "firebase/firestore"; // Sum the count of each shard in the subcollection const snapshot = await getDocs(collection(ref, 'shards')); diff --git a/snippets/firestore-next/test-solution-counters/increment_counter.js b/snippets/firestore-next/test-solution-counters/increment_counter.js index 37e94224..c74ec711 100644 --- a/snippets/firestore-next/test-solution-counters/increment_counter.js +++ b/snippets/firestore-next/test-solution-counters/increment_counter.js @@ -5,7 +5,7 @@ // [START increment_counter_modular] function incrementCounter(db, ref, num_shards) { - import { collection, doc, updateDoc, increment, FirebaseFirestore } from "@firebase/firestore"; + import { doc, updateDoc, increment } from "firebase/firestore"; // Select a shard of the counter at random const shardId = Math.floor(Math.random() * num_shards).toString(); From 9d474d90b35260924574c0db5e3dc4f38e9e7dd1 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Thu, 17 Jun 2021 05:37:02 -0400 Subject: [PATCH 153/235] Clarify some query snippets See: https://github.com/firebase/snippets-web/issues/186 --- firestore/test.firestore.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index 988a3c97..bccf10cd 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -856,9 +856,9 @@ describe("firestore", () => { it("should handle other wheres", () => { var citiesRef = db.collection("cities"); // [START example_filters] - citiesRef.where("state", "==", "CA"); - citiesRef.where("population", "<", 100000); - citiesRef.where("name", ">=", "San Francisco"); + const nameQuery = citiesRef.where("state", "==", "CA"); + const populationQuery = citiesRef.where("population", "<", 100000); + const nameQuery = citiesRef.where("name", ">=", "San Francisco"); // [END example_filters] // [START simple_query_not_equal] @@ -900,16 +900,16 @@ describe("firestore", () => { it("should handle compound queries", () => { var citiesRef = db.collection("cities"); // [START chain_filters] - citiesRef.where("state", "==", "CO").where("name", "==", "Denver"); - citiesRef.where("state", "==", "CA").where("population", "<", 1000000); + const q1 = citiesRef.where("state", "==", "CO").where("name", "==", "Denver"); + const q2 = citiesRef.where("state", "==", "CA").where("population", "<", 1000000); // [END chain_filters] }); it("should handle range filters on one field", () => { var citiesRef = db.collection("cities"); // [START valid_range_filters] - citiesRef.where("state", ">=", "CA").where("state", "<=", "IN"); - citiesRef.where("state", "==", "CA").where("population", ">", 1000000); + const q1 = citiesRef.where("state", ">=", "CA").where("state", "<=", "IN"); + const q2 = citiesRef.where("state", "==", "CA").where("population", ">", 1000000); // [END valid_range_filters] }); From cc780b4d760548050b37263a092c7b6fb85ab97d Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Thu, 17 Jun 2021 05:38:46 -0400 Subject: [PATCH 154/235] Clarify some query snippets See: https://github.com/firebase/snippets-web/issues/186 --- firestore-next/test.firestore.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 2a452e80..29983b26 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -851,13 +851,13 @@ describe("firestore", () => { const citiesRef = collection(db, "cities"); // [START example_filters] - const q1 = query(citiesRef, where("state", "==", "CA")); - const q2 = query(citiesRef, where("population", "<", 100000)); - const q3 = query(citiesRef, where("name", ">=", "San Francisco")); + const stateQuery = query(citiesRef, where("state", "==", "CA")); + const populationQuery = query(citiesRef, where("population", "<", 100000)); + const nameQuery = query(citiesRef, where("name", ">=", "San Francisco")); // [END example_filters] // [START simple_query_not_equal] - const q4 = query(citiesRef, where("capital", "!=", false)); + const notCapitalQuery = query(citiesRef, where("capital", "!=", false)); // [END simple_query_not_equal] }); From 97c3d88ffa57794babb50af2a2db26aa5465feae Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Thu, 17 Jun 2021 05:43:31 -0400 Subject: [PATCH 155/235] Update test.firestore.js --- firestore/test.firestore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index bccf10cd..2aadf8d5 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -856,7 +856,7 @@ describe("firestore", () => { it("should handle other wheres", () => { var citiesRef = db.collection("cities"); // [START example_filters] - const nameQuery = citiesRef.where("state", "==", "CA"); + const stateQuery = citiesRef.where("state", "==", "CA"); const populationQuery = citiesRef.where("population", "<", 100000); const nameQuery = citiesRef.where("name", ">=", "San Francisco"); // [END example_filters] From edd04c7201285d863794c21a5a50201c02a9aa55 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 17 Jun 2021 10:48:40 +0100 Subject: [PATCH 156/235] Regenerate snippets --- snippets/firestore-next/test-firestore/example_filters.js | 6 +++--- .../firestore-next/test-firestore/simple_query_not_equal.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/snippets/firestore-next/test-firestore/example_filters.js b/snippets/firestore-next/test-firestore/example_filters.js index ccadb811..b5f58a5c 100644 --- a/snippets/firestore-next/test-firestore/example_filters.js +++ b/snippets/firestore-next/test-firestore/example_filters.js @@ -4,7 +4,7 @@ // To make edits to the snippets in this file, please edit the source // [START example_filters_modular] -const q1 = query(citiesRef, where("state", "==", "CA")); -const q2 = query(citiesRef, where("population", "<", 100000)); -const q3 = query(citiesRef, where("name", ">=", "San Francisco")); +const stateQuery = query(citiesRef, where("state", "==", "CA")); +const populationQuery = query(citiesRef, where("population", "<", 100000)); +const nameQuery = query(citiesRef, where("name", ">=", "San Francisco")); // [END example_filters_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/simple_query_not_equal.js b/snippets/firestore-next/test-firestore/simple_query_not_equal.js index 0ddb5643..a9ca2690 100644 --- a/snippets/firestore-next/test-firestore/simple_query_not_equal.js +++ b/snippets/firestore-next/test-firestore/simple_query_not_equal.js @@ -4,5 +4,5 @@ // To make edits to the snippets in this file, please edit the source // [START simple_query_not_equal_modular] -const q4 = query(citiesRef, where("capital", "!=", false)); +const notCapitalQuery = query(citiesRef, where("capital", "!=", false)); // [END simple_query_not_equal_modular] \ No newline at end of file From edb656bdbd8549323bbb590c8d1aa250ee3874f3 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 18 Jun 2021 02:46:38 -0700 Subject: [PATCH 157/235] Auto-update dependencies. (#187) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index cc5fc126..6860d83d 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.7" + "firebase": "^8.6.8" } } diff --git a/auth/package.json b/auth/package.json index c049b151..c2417cc1 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.7", + "firebase": "^8.6.8", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index e5c6e37c..c9019f5a 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.7" + "firebase": "^8.6.8" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index e7ab4fc6..477a93b1 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.7" + "firebase": "^8.6.8" } } diff --git a/firestore/package.json b/firestore/package.json index 1c3c4360..c8c44a65 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.7", + "firebase": "^8.6.8", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 1119e0dc..98a666fe 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.7" + "firebase": "^8.6.8" } } diff --git a/installations/package.json b/installations/package.json index f7f4edee..cfeb425a 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.7" + "firebase": "^8.6.8" } } diff --git a/messaging/package.json b/messaging/package.json index db8faba3..79655ec6 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.7" + "firebase": "^8.6.8" } } diff --git a/perf/package.json b/perf/package.json index 5e300b1f..98bf1569 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.7" + "firebase": "^8.6.8" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index fc4287df..fbe56615 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.7" + "firebase": "^8.6.8" } } diff --git a/storage/package.json b/storage/package.json index d52a0fc9..c2e6acd7 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.7" + "firebase": "^8.6.8" } } From 15e1160b5a0eef0198df0d6c6dd16d349cc9ee1b Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 18 Jun 2021 07:25:12 -0700 Subject: [PATCH 158/235] Auto-update dependencies. (#188) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 43629560..8326796b 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 83cdfa98..d3568384 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.6.7/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.6.7/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.8/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.6.8/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 26569c25020d706a2f5a3b9bc2d306c29a7e5bfc Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 21 Jun 2021 11:30:18 -0400 Subject: [PATCH 159/235] Version 9.0.0-beta.5 (#190) --- analytics-next/package.json | 2 +- auth-next/package.json | 2 +- database-next/package.json | 2 +- firebaseapp-next/package.json | 2 +- firestore-next/package.json | 2 +- functions-next/package.json | 2 +- messaging-next/package.json | 2 +- perf-next/package.json | 2 +- remoteconfig-next/package.json | 2 +- storage-next/package.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index fc41c09e..7619d871 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.3" + "firebase": "^9.0.0-beta.5" } } diff --git a/auth-next/package.json b/auth-next/package.json index 628a59ca..50a848dd 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.3" + "firebase": "^9.0.0-beta.5" } } diff --git a/database-next/package.json b/database-next/package.json index b97354bb..8ca518b1 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.3" + "firebase": "^9.0.0-beta.5" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index 660b3a4a..3dbdc53c 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.3" + "firebase": "^9.0.0-beta.5" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 503db5bd..5e80fc86 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.3", + "firebase": "^9.0.0-beta.5", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/package.json b/functions-next/package.json index a9de34b8..3b9ba918 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.3" + "firebase": "^9.0.0-beta.5" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index 785a3025..9f079581 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.3" + "firebase": "^9.0.0-beta.5" } } diff --git a/perf-next/package.json b/perf-next/package.json index f57ee6fe..715ad2c2 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.3" + "firebase": "^9.0.0-beta.5" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index 5295c660..a006de29 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.3" + "firebase": "^9.0.0-beta.5" } } diff --git a/storage-next/package.json b/storage-next/package.json index 00ccd216..a9fa5b59 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.3" + "firebase": "^9.0.0-beta.5" } } From f277c5669a45428236a9a480b736be55a6eb74ab Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 2 Jul 2021 09:18:58 +0000 Subject: [PATCH 160/235] Auto-update dependencies. (#193) --- analytics/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 6860d83d..606ce181 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.8" + "firebase": "^8.7.0" } } diff --git a/auth/package.json b/auth/package.json index c2417cc1..4f1aac94 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.8", + "firebase": "^8.7.0", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index c9019f5a..300c2819 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.8" + "firebase": "^8.7.0" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 477a93b1..94770adf 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.8" + "firebase": "^8.7.0" } } diff --git a/firestore/package.json b/firestore/package.json index c8c44a65..f7f5cad1 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.8", + "firebase": "^8.7.0", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 98a666fe..38d4e438 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.8" + "firebase": "^8.7.0" } } diff --git a/installations/package.json b/installations/package.json index cfeb425a..0cf430e2 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.6.8" + "firebase": "^8.7.0" } } diff --git a/messaging/package.json b/messaging/package.json index 79655ec6..508df566 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.8" + "firebase": "^8.7.0" } } diff --git a/perf/package.json b/perf/package.json index 98bf1569..6e2069e1 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.8" + "firebase": "^8.7.0" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index fbe56615..97d84e71 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.8" + "firebase": "^8.7.0" } } diff --git a/storage/package.json b/storage/package.json index c2e6acd7..c24bbbc9 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.6.8" + "firebase": "^8.7.0" } } From 6f8eef6a604d236cda3db955ad3f8790eae7bd85 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 2 Jul 2021 11:41:48 +0100 Subject: [PATCH 161/235] Version 9.0.0-beta.6 (#194) --- analytics-next/package.json | 2 +- auth-next/package.json | 2 +- database-next/package.json | 2 +- firebaseapp-next/package.json | 2 +- firestore-next/package.json | 2 +- functions-next/package.json | 2 +- messaging-next/package.json | 2 +- perf-next/package.json | 2 +- remoteconfig-next/package.json | 2 +- storage-next/package.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index 7619d871..8a016e7f 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.5" + "firebase": "^9.0.0-beta.6" } } diff --git a/auth-next/package.json b/auth-next/package.json index 50a848dd..0faf9c39 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.5" + "firebase": "^9.0.0-beta.6" } } diff --git a/database-next/package.json b/database-next/package.json index 8ca518b1..36e447be 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.5" + "firebase": "^9.0.0-beta.6" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index 3dbdc53c..8d8aeb5b 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.5" + "firebase": "^9.0.0-beta.6" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 5e80fc86..2a6789f9 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.5", + "firebase": "^9.0.0-beta.6", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/package.json b/functions-next/package.json index 3b9ba918..8af6456f 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.5" + "firebase": "^9.0.0-beta.6" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index 9f079581..7a515c8f 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.5" + "firebase": "^9.0.0-beta.6" } } diff --git a/perf-next/package.json b/perf-next/package.json index 715ad2c2..ae90ad17 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.5" + "firebase": "^9.0.0-beta.6" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index a006de29..f092772d 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.5" + "firebase": "^9.0.0-beta.6" } } diff --git a/storage-next/package.json b/storage-next/package.json index a9fa5b59..e2e1edc8 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.5" + "firebase": "^9.0.0-beta.6" } } From 28ef8d3a13c9454b8f9da33200b1616dc935542a Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 2 Jul 2021 12:06:42 +0100 Subject: [PATCH 162/235] Add AppCheck snippets (#195) --- appcheck-next/index.js | 65 +++++++++++++++++++ appcheck-next/package.json | 11 ++++ appcheck/index.js | 55 ++++++++++++++++ appcheck/package.json | 11 ++++ .../index/appcheck_custom_provider.js | 29 +++++++++ .../index/appcheck_initialize.js | 19 ++++++ .../appcheck_initialize_custom_provider.js | 17 +++++ 7 files changed, 207 insertions(+) create mode 100644 appcheck-next/index.js create mode 100644 appcheck-next/package.json create mode 100644 appcheck/index.js create mode 100644 appcheck/package.json create mode 100644 snippets/appcheck-next/index/appcheck_custom_provider.js create mode 100644 snippets/appcheck-next/index/appcheck_initialize.js create mode 100644 snippets/appcheck-next/index/appcheck_initialize_custom_provider.js diff --git a/appcheck-next/index.js b/appcheck-next/index.js new file mode 100644 index 00000000..824cd3cb --- /dev/null +++ b/appcheck-next/index.js @@ -0,0 +1,65 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +function initialize() { + // [START appcheck_initialize] + const { initializeApp } = require("firebase/app"); + const { initializeAppCheck, ReCaptchaV3Provider } = require("firebase/app-check"); + + const app = initializeApp({ + // Your firebase configuration object + }); + + // Pass your reCAPTCHA v3 site key (public key) to activate(). Make sure this + // key is the counterpart to the secret key you set in the Firebase console. + const appCheck = initializeAppCheck(app, { + provider: new ReCaptchaV3Provider('abcdefghijklmnopqrstuvwxy-1234567890abcd') + }); + // [END appcheck_initialize] +} + +function customProvider() { + // [START appcheck_custom_provider] + const { CustomProvider } = require("firebase/app-check"); + + const appCheckCustomProvider = new CustomProvider({ + getToken: () => { + return new Promise((resolve, _reject) => { + // TODO: Logic to exchange proof of authenticity for an App Check token and + // expiration time. + + // [START_EXCLUDE] + const tokenFromServer = "abc1234"; + const expirationFromServer = 1234; + // [END_EXCLUDE] + + const appCheckToken = { + token: tokenFromServer, + expireTimeMillis: expirationFromServer * 1000 + }; + + resolve(appCheckToken); + }); + } + }); + // [END appcheck_custom_provider] + + return appCheckCustomProvider; +} + +function initializeCustomProvider() { + const appCheckCustomProvider = customProvider(); + + // [START appcheck_initialize_custom_provider] + const { initializeApp } = require("firebase/app"); + const { initializeAppCheck } = require("firebase/app-check"); + + const app = initializeApp({ + // Your firebase configuration object + }); + + const appCheck = initializeAppCheck(app, { + provider: appCheckCustomProvider + }); + // [END appcheck_initialize_custom_provider] +} diff --git a/appcheck-next/package.json b/appcheck-next/package.json new file mode 100644 index 00000000..0514d1e8 --- /dev/null +++ b/appcheck-next/package.json @@ -0,0 +1,11 @@ +{ + "name": "appcheck-next", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^9.0.0-beta.6" + } +} diff --git a/appcheck/index.js b/appcheck/index.js new file mode 100644 index 00000000..04282f4d --- /dev/null +++ b/appcheck/index.js @@ -0,0 +1,55 @@ +import firebase from "firebase/app"; +import "firebase/app-check"; + +function initialize() { + // [START appcheck_initialize] + firebase.initializeApp({ + // Your firebase configuration object + }); + + const appCheck = firebase.appCheck(); + // Pass your reCAPTCHA v3 site key (public key) to activate(). Make sure this + // key is the counterpart to the secret key you set in the Firebase console. + appCheck.activate('abcdefghijklmnopqrstuvwxy-1234567890abcd'); + // [END appcheck_initialize] +} + +function customProvider() { + // [START appcheck_custom_provider] + const appCheckCustomProvider = { + getToken: () => { + return new Promise((resolve, _reject) => { + // TODO: Logic to exchange proof of authenticity for an App Check token and + // expiration time. + + // [START_EXCLUDE] + const tokenFromServer = "abc1234"; + const expirationFromServer = 1234; + // [END_EXCLUDE] + + const appCheckToken = { + token: tokenFromServer, + expireTimeMillis: expirationFromServer * 1000 + }; + + resolve(appCheckToken); + }); + } + }; + // [END appcheck_custom_provider] + + return appCheckCustomProvider; +} + +function initializeCustomProvider() { + const appCheckCustomProvider = customProvider(); + + // [START appcheck_initialize_custom_provider] + firebase.initializeApp({ + // Your firebase configuration object + }); + + const appCheck = firebase.appCheck(); + appCheck.activate(appCheckCustomProvider); + // [END appcheck_initialize_custom_provider] +} diff --git a/appcheck/package.json b/appcheck/package.json new file mode 100644 index 00000000..f40d585d --- /dev/null +++ b/appcheck/package.json @@ -0,0 +1,11 @@ +{ + "name": "appcheck", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^8.7.0" + } +} diff --git a/snippets/appcheck-next/index/appcheck_custom_provider.js b/snippets/appcheck-next/index/appcheck_custom_provider.js new file mode 100644 index 00000000..7bcb0452 --- /dev/null +++ b/snippets/appcheck-next/index/appcheck_custom_provider.js @@ -0,0 +1,29 @@ +// This snippet file was generated by processing the source file: +// ./appcheck-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START appcheck_custom_provider_modular] +import { CustomProvider } from "firebase/app-check"; + +const appCheckCustomProvider = new CustomProvider({ + getToken: () => { + return new Promise((resolve, _reject) => { + // TODO: Logic to exchange proof of authenticity for an App Check token and + // expiration time. + + // [START_EXCLUDE] + const tokenFromServer = "abc1234"; + const expirationFromServer = 1234; + // [END_EXCLUDE] + + const appCheckToken = { + token: tokenFromServer, + expireTimeMillis: expirationFromServer * 1000 + }; + + resolve(appCheckToken); + }); + } +}); +// [END appcheck_custom_provider_modular] \ No newline at end of file diff --git a/snippets/appcheck-next/index/appcheck_initialize.js b/snippets/appcheck-next/index/appcheck_initialize.js new file mode 100644 index 00000000..7aa91572 --- /dev/null +++ b/snippets/appcheck-next/index/appcheck_initialize.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./appcheck-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START appcheck_initialize_modular] +import { initializeApp } from "firebase/app"; +import { initializeAppCheck, ReCaptchaV3Provider } from "firebase/app-check"; + +const app = initializeApp({ + // Your firebase configuration object +}); + +// Pass your reCAPTCHA v3 site key (public key) to activate(). Make sure this +// key is the counterpart to the secret key you set in the Firebase console. +const appCheck = initializeAppCheck(app, { + provider: new ReCaptchaV3Provider('abcdefghijklmnopqrstuvwxy-1234567890abcd') +}); +// [END appcheck_initialize_modular] \ No newline at end of file diff --git a/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js b/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js new file mode 100644 index 00000000..ef721941 --- /dev/null +++ b/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./appcheck-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START appcheck_initialize_custom_provider_modular] +import { initializeApp } from "firebase/app"; +import { initializeAppCheck } from "firebase/app-check"; + +const app = initializeApp({ + // Your firebase configuration object +}); + +const appCheck = initializeAppCheck(app, { + provider: appCheckCustomProvider +}); +// [END appcheck_initialize_custom_provider_modular] \ No newline at end of file From 4e2e1a25845917860fca1858aa3ca3c80dc9ff42 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 2 Jul 2021 12:21:30 +0000 Subject: [PATCH 163/235] Auto-update dependencies. (#196) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 8326796b..264fe1a3 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index d3568384..4ff1a19b 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.6.8/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.6.8/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.7.0/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.7.0/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From e48a146a0f89358c85e5f67aee3fa14047b63cbd Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 5 Jul 2021 10:06:32 +0100 Subject: [PATCH 164/235] Update transaction_promise.js (#198) --- firestore-next/test.firestore.js | 1 + snippets/firestore-next/test-firestore/transaction_promise.js | 1 + 2 files changed, 2 insertions(+) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 29983b26..7dca3d0e 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -559,6 +559,7 @@ describe("firestore", () => { const newPop = sfDoc.data().population + 1; if (newPop <= 1000000) { transaction.update(sfDocRef, { population: newPop }); + return newPop; } else { return Promise.reject("Sorry! Population is too big"); } diff --git a/snippets/firestore-next/test-firestore/transaction_promise.js b/snippets/firestore-next/test-firestore/transaction_promise.js index cda47859..7646bb6d 100644 --- a/snippets/firestore-next/test-firestore/transaction_promise.js +++ b/snippets/firestore-next/test-firestore/transaction_promise.js @@ -19,6 +19,7 @@ try { const newPop = sfDoc.data().population + 1; if (newPop <= 1000000) { transaction.update(sfDocRef, { population: newPop }); + return newPop; } else { return Promise.reject("Sorry! Population is too big"); } From f063360468ed058d43e0ec8a2ff6a7d37ac23300 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Mon, 5 Jul 2021 11:35:31 +0100 Subject: [PATCH 165/235] Add messaging sw snippet (#199) --- messaging-next/service-worker.js | 17 ++++++++++++++++- .../messaging_on_background_message.js | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/messaging-next/service-worker.js b/messaging-next/service-worker.js index 25ee21db..ce0ac6b8 100644 --- a/messaging-next/service-worker.js +++ b/messaging-next/service-worker.js @@ -40,6 +40,21 @@ function initInSw() { function onBackgroundMessage() { // [START messaging_on_background_message] - // TODO(snippet): This snippet is not yet translated to the @exp SDK + const { getMessaging } = require("firebase/messaging"); + const { onBackgroundMessage } = require("firebase/messaging/sw"); + + const messaging = getMessaging(); + onBackgroundMessage(messaging, (payload) => { + console.log('[firebase-messaging-sw.js] Received background message ', payload); + // Customize notification here + const notificationTitle = 'Background Message Title'; + const notificationOptions = { + body: 'Background Message body.', + icon: '/firebase-logo.png' + }; + + self.registration.showNotification(notificationTitle, + notificationOptions); + }); // [END messaging_on_background_message] } diff --git a/snippets/messaging-next/service-worker/messaging_on_background_message.js b/snippets/messaging-next/service-worker/messaging_on_background_message.js index 2c55eab1..000ab312 100644 --- a/snippets/messaging-next/service-worker/messaging_on_background_message.js +++ b/snippets/messaging-next/service-worker/messaging_on_background_message.js @@ -4,5 +4,20 @@ // To make edits to the snippets in this file, please edit the source // [START messaging_on_background_message_modular] -// TODO(snippet): This snippet is not yet translated to the @exp SDK +import { getMessaging } from "firebase/messaging"; +import { onBackgroundMessage } from "firebase/messaging/sw"; + +const messaging = getMessaging(); +onBackgroundMessage(messaging, (payload) => { + console.log('[firebase-messaging-sw.js] Received background message ', payload); + // Customize notification here + const notificationTitle = 'Background Message Title'; + const notificationOptions = { + body: 'Background Message body.', + icon: '/firebase-logo.png' + }; + + self.registration.showNotification(notificationTitle, + notificationOptions); +}); // [END messaging_on_background_message_modular] \ No newline at end of file From 4af4eff5b6359647e95ee300a19ffbdec4f8e975 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 9 Jul 2021 10:51:24 +0000 Subject: [PATCH 166/235] Auto-update dependencies. (#200) --- analytics/package.json | 2 +- appcheck/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 606ce181..279e01b9 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.0" + "firebase": "^8.7.1" } } diff --git a/appcheck/package.json b/appcheck/package.json index f40d585d..1e3e3e4e 100644 --- a/appcheck/package.json +++ b/appcheck/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.0" + "firebase": "^8.7.1" } } diff --git a/auth/package.json b/auth/package.json index 4f1aac94..3b153e5f 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.7.0", + "firebase": "^8.7.1", "firebaseui": "^4.8.0" } } diff --git a/database/package.json b/database/package.json index 300c2819..6065a1e2 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.7.0" + "firebase": "^8.7.1" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 94770adf..9f37e03a 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.0" + "firebase": "^8.7.1" } } diff --git a/firestore/package.json b/firestore/package.json index f7f5cad1..eb8d249b 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.0", + "firebase": "^8.7.1", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 38d4e438..03a0c953 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.0" + "firebase": "^8.7.1" } } diff --git a/installations/package.json b/installations/package.json index 0cf430e2..4e522a00 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.7.0" + "firebase": "^8.7.1" } } diff --git a/messaging/package.json b/messaging/package.json index 508df566..f431485c 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.0" + "firebase": "^8.7.1" } } diff --git a/perf/package.json b/perf/package.json index 6e2069e1..5b3cd047 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.0" + "firebase": "^8.7.1" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 97d84e71..c37579d2 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.0" + "firebase": "^8.7.1" } } diff --git a/storage/package.json b/storage/package.json index c24bbbc9..f38e0b00 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.0" + "firebase": "^8.7.1" } } From fcad62c049a656606546f2c3c1645a6153cbe59b Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 9 Jul 2021 12:59:55 +0000 Subject: [PATCH 167/235] Auto-update dependencies. (#201) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 264fe1a3..2cc69598 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 4ff1a19b..eb4175ca 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.7.0/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.7.0/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.7.1/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.7.1/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 9b05382e6bd01887c1d2636339b39c00b72e7dce Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 13 Jul 2021 15:49:38 +0100 Subject: [PATCH 168/235] Update cache hashing (#202) --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dbfa11d6..3eddc3bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: uses: actions/cache@v1 with: path: ~/.npm - key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }} + key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }} - name: Install dependencies run: | From 9d1c8c51a6b7143605340490795caeea2d8f2e73 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 23 Jul 2021 09:07:01 +0000 Subject: [PATCH 169/235] Auto-update dependencies. (#204) Co-authored-by: Sam --- analytics-next/package.json | 2 +- analytics/package.json | 2 +- appcheck-next/package.json | 2 +- appcheck/package.json | 2 +- auth-next/emulator-suite.js | 4 ++-- auth-next/package.json | 2 +- auth/package.json | 4 ++-- database-next/emulator-suite.js | 4 ++-- database-next/package.json | 2 +- database/package.json | 2 +- firebaseapp-next/package.json | 2 +- firebaseapp/package.json | 2 +- firestore-next/emulator-suite.js | 4 ++-- firestore-next/package.json | 2 +- firestore/package.json | 2 +- functions-next/emulator-suite.js | 4 ++-- functions-next/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging-next/package.json | 2 +- messaging/package.json | 2 +- perf-next/package.json | 2 +- perf/package.json | 2 +- remoteconfig-next/package.json | 2 +- remoteconfig/package.json | 2 +- snippets/auth-next/emulator-suite/auth_emulator_connect.js | 4 ++-- .../database-next/emulator-suite/rtdb_emulator_connect.js | 4 ++-- snippets/firestore-next/emulator-suite/fs_emulator_connect.js | 4 ++-- .../emulator-suite/fb_functions_emulator_connect.js | 4 ++-- storage-next/package.json | 2 +- storage/package.json | 2 +- 31 files changed, 40 insertions(+), 40 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index 8a016e7f..b04876cb 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.6" + "firebase": "^9.0.0-beta.7" } } diff --git a/analytics/package.json b/analytics/package.json index 279e01b9..57c16836 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.1" + "firebase": "^8.8.0" } } diff --git a/appcheck-next/package.json b/appcheck-next/package.json index 0514d1e8..8fc601eb 100644 --- a/appcheck-next/package.json +++ b/appcheck-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.6" + "firebase": "^9.0.0-beta.7" } } diff --git a/appcheck/package.json b/appcheck/package.json index 1e3e3e4e..cf7d82b3 100644 --- a/appcheck/package.json +++ b/appcheck/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.1" + "firebase": "^8.8.0" } } diff --git a/auth-next/emulator-suite.js b/auth-next/emulator-suite.js index ed24e78b..84d57ed0 100644 --- a/auth-next/emulator-suite.js +++ b/auth-next/emulator-suite.js @@ -3,10 +3,10 @@ function emulatorConnect() { // [START auth_emulator_connect] - const { getAuth, useAuthEmulator } = require("firebase/auth"); + const { getAuth, connectAuthEmulator } = require("firebase/auth"); const auth = getAuth(); - useAuthEmulator(auth, "http://localhost:9099"); + connectAuthEmulator(auth, "http://localhost:9099"); // [END auth_emulator_connect] } diff --git a/auth-next/package.json b/auth-next/package.json index 0faf9c39..1a955b2a 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.6" + "firebase": "^9.0.0-beta.7" } } diff --git a/auth/package.json b/auth/package.json index 3b153e5f..f8a0c4de 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.7.1", - "firebaseui": "^4.8.0" + "firebase": "^8.8.0", + "firebaseui": "^4.8.1" } } diff --git a/database-next/emulator-suite.js b/database-next/emulator-suite.js index 083fea80..ab86bf9b 100644 --- a/database-next/emulator-suite.js +++ b/database-next/emulator-suite.js @@ -3,12 +3,12 @@ function onDocumentReady() { // [START rtdb_emulator_connect] - const { getDatabase, useDatabaseEmulator } = require("firebase/database"); + const { getDatabase, connectDatabaseEmulator } = require("firebase/database"); const db = getDatabase(); if (location.hostname === "localhost") { // Point to the RTDB emulator running on localhost. - useDatabaseEmulator(db, "localhost", 9000); + connectDatabaseEmulator(db, "localhost", 9000); } // [END rtdb_emulator_connect] } diff --git a/database-next/package.json b/database-next/package.json index 36e447be..a6c12500 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.6" + "firebase": "^9.0.0-beta.7" } } diff --git a/database/package.json b/database/package.json index 6065a1e2..d26b77fb 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.7.1" + "firebase": "^8.8.0" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index 8d8aeb5b..daeaf862 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.6" + "firebase": "^9.0.0-beta.7" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 9f37e03a..fd76176d 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.1" + "firebase": "^8.8.0" } } diff --git a/firestore-next/emulator-suite.js b/firestore-next/emulator-suite.js index 61463eee..30ad24eb 100644 --- a/firestore-next/emulator-suite.js +++ b/firestore-next/emulator-suite.js @@ -3,10 +3,10 @@ function onDocumentReady() { // [START fs_emulator_connect] - const { getFirestore, useFirestoreEmulator } = require("firebase/firestore"); + const { getFirestore, connectFirestoreEmulator } = require("firebase/firestore"); // firebaseApps previously initialized using initializeApp() const db = getFirestore(); - useFirestoreEmulator(db, 'localhost', 8080); + connectFirestoreEmulator(db, 'localhost', 8080); // [END fs_emulator_connect] } diff --git a/firestore-next/package.json b/firestore-next/package.json index 2a6789f9..fe0e5390 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.6", + "firebase": "^9.0.0-beta.7", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/firestore/package.json b/firestore/package.json index eb8d249b..400d854f 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.1", + "firebase": "^8.8.0", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/emulator-suite.js b/functions-next/emulator-suite.js index 1f519a2e..7a750fc4 100644 --- a/functions-next/emulator-suite.js +++ b/functions-next/emulator-suite.js @@ -12,10 +12,10 @@ initializeApp({ export function emulatorSettings() { // [START fb_functions_emulator_connect] const { getApp } = require("firebase/app"); - const { getFunctions, useFunctionsEmulator } = require("firebase/functions"); + const { getFunctions, connectFunctionsEmulator } = require("firebase/functions"); const functions = getFunctions(getApp()); - useFunctionsEmulator(functions, "localhost", 5001); + connectFunctionsEmulator(functions, "localhost", 5001); // [END fb_functions_emulator_connect] } diff --git a/functions-next/package.json b/functions-next/package.json index 8af6456f..38a60b6f 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.6" + "firebase": "^9.0.0-beta.7" } } diff --git a/functions/package.json b/functions/package.json index 03a0c953..78ddd20e 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.1" + "firebase": "^8.8.0" } } diff --git a/installations/package.json b/installations/package.json index 4e522a00..948ad208 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.7.1" + "firebase": "^8.8.0" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index 7a515c8f..cb9c10c3 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.6" + "firebase": "^9.0.0-beta.7" } } diff --git a/messaging/package.json b/messaging/package.json index f431485c..3d9ea607 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.1" + "firebase": "^8.8.0" } } diff --git a/perf-next/package.json b/perf-next/package.json index ae90ad17..7ff11967 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.6" + "firebase": "^9.0.0-beta.7" } } diff --git a/perf/package.json b/perf/package.json index 5b3cd047..c928467c 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.1" + "firebase": "^8.8.0" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index f092772d..eaa7272d 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.6" + "firebase": "^9.0.0-beta.7" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index c37579d2..781f8363 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.1" + "firebase": "^8.8.0" } } diff --git a/snippets/auth-next/emulator-suite/auth_emulator_connect.js b/snippets/auth-next/emulator-suite/auth_emulator_connect.js index 99f222ff..7e4cf680 100644 --- a/snippets/auth-next/emulator-suite/auth_emulator_connect.js +++ b/snippets/auth-next/emulator-suite/auth_emulator_connect.js @@ -4,8 +4,8 @@ // To make edits to the snippets in this file, please edit the source // [START auth_emulator_connect_modular] -import { getAuth, useAuthEmulator } from "firebase/auth"; +import { getAuth, connectAuthEmulator } from "firebase/auth"; const auth = getAuth(); -useAuthEmulator(auth, "http://localhost:9099"); +connectAuthEmulator(auth, "http://localhost:9099"); // [END auth_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/database-next/emulator-suite/rtdb_emulator_connect.js b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js index 0015f451..709fc10b 100644 --- a/snippets/database-next/emulator-suite/rtdb_emulator_connect.js +++ b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js @@ -4,11 +4,11 @@ // To make edits to the snippets in this file, please edit the source // [START rtdb_emulator_connect_modular] -import { getDatabase, useDatabaseEmulator } from "firebase/database"; +import { getDatabase, connectDatabaseEmulator } from "firebase/database"; const db = getDatabase(); if (location.hostname === "localhost") { // Point to the RTDB emulator running on localhost. - useDatabaseEmulator(db, "localhost", 9000); + connectDatabaseEmulator(db, "localhost", 9000); } // [END rtdb_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js index 140f6a09..3754a2df 100644 --- a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js +++ b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js @@ -4,9 +4,9 @@ // To make edits to the snippets in this file, please edit the source // [START fs_emulator_connect_modular] -import { getFirestore, useFirestoreEmulator } from "firebase/firestore"; +import { getFirestore, connectFirestoreEmulator } from "firebase/firestore"; // firebaseApps previously initialized using initializeApp() const db = getFirestore(); -useFirestoreEmulator(db, 'localhost', 8080); +connectFirestoreEmulator(db, 'localhost', 8080); // [END fs_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js b/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js index 62fc3dd2..1a314acf 100644 --- a/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js +++ b/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js @@ -5,8 +5,8 @@ // [START fb_functions_emulator_connect_modular] import { getApp } from "firebase/app"; -import { getFunctions, useFunctionsEmulator } from "firebase/functions"; +import { getFunctions, connectFunctionsEmulator } from "firebase/functions"; const functions = getFunctions(getApp()); -useFunctionsEmulator(functions, "localhost", 5001); +connectFunctionsEmulator(functions, "localhost", 5001); // [END fb_functions_emulator_connect_modular] \ No newline at end of file diff --git a/storage-next/package.json b/storage-next/package.json index e2e1edc8..a912d510 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.6" + "firebase": "^9.0.0-beta.7" } } diff --git a/storage/package.json b/storage/package.json index f38e0b00..9ab7fd82 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.7.1" + "firebase": "^8.8.0" } } From 9fcfc6425e99f0a4dba4807693eca8f86d0188a3 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 23 Jul 2021 12:05:27 +0100 Subject: [PATCH 170/235] Initialize functions snippet (#205) --- functions-next/callable.js | 17 +++++++++++++++++ functions/callable.js | 16 ++++++++++++++++ .../callable/fb_functions_initialize.js | 19 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 snippets/functions-next/callable/fb_functions_initialize.js diff --git a/functions-next/callable.js b/functions-next/callable.js index 70049563..5ebc03d9 100644 --- a/functions-next/callable.js +++ b/functions-next/callable.js @@ -1,6 +1,23 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] +export function initialize() { + // [START fb_functions_initialize] + const { initializeApp } = require("firebase/app"); + const { getFunctions } = require("firebase/functions"); + + initializeApp({ + // Your Firebase Web SDK configuration + // [START_EXCLUDE] + projectId: "", + apiKey: "", + // [END_EXCLUDE] + }); + + const functions = getFunctions(); + // [END fb_functions_initialize] +} + export function callAddMessage() { const messageText = "Hello, World!"; diff --git a/functions/callable.js b/functions/callable.js index 2b605ae1..66b576d5 100644 --- a/functions/callable.js +++ b/functions/callable.js @@ -1,5 +1,21 @@ +// [START fb_functions_imports] import firebase from "firebase/app"; import "firebase/functions"; +// [END fb_functions_imports] + +function initialize() { + // [START fb_functions_initialize] + firebase.initializeApp({ + // Your Firebase Web SDK configuration + // [START_EXCLUDE] + projectId: "", + apiKey: "", + // [END_EXCLUDE] + }); + + const functions = firebase.functions(); + // [END fb_functions_initialize] +} function callAddMessage() { const messageText = "Hello, World!"; diff --git a/snippets/functions-next/callable/fb_functions_initialize.js b/snippets/functions-next/callable/fb_functions_initialize.js new file mode 100644 index 00000000..7c8e4d49 --- /dev/null +++ b/snippets/functions-next/callable/fb_functions_initialize.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./functions-next/callable.js +// +// To make edits to the snippets in this file, please edit the source + +// [START fb_functions_initialize_modular] +import { initializeApp } from "firebase/app"; +import { getFunctions } from "firebase/functions"; + +initializeApp({ + // Your Firebase Web SDK configuration + // [START_EXCLUDE] + projectId: "", + apiKey: "", + // [END_EXCLUDE] +}); + +const functions = getFunctions(); +// [END fb_functions_initialize_modular] \ No newline at end of file From f29550c38f02bad94cfd87c15d3cd1cba36ece9a Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 23 Jul 2021 12:46:38 +0000 Subject: [PATCH 171/235] Auto-update dependencies. (#206) * Auto-update dependencies. * Auto-update dependencies. --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 2cc69598..81809b77 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index eb4175ca..7877457c 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.7.1/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.7.1/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.8.0/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.8.0/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From da7abdba24bff614c2c5ef0eb6ce836480d82dd5 Mon Sep 17 00:00:00 2001 From: Kevin Cheung Date: Tue, 27 Jul 2021 12:54:13 -0700 Subject: [PATCH 172/235] Add App Check non-Firebase resource snippets (#207) * Add App Check non-Firebase resource snippets * Pass lint * npm run snippet * more lint fixes * npm run snippets again --- appcheck-next/index.js | 37 +++++++++++++++++++ appcheck/index.js | 21 +++++++++++ .../index/appcheck_nonfirebase.js | 32 ++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 snippets/appcheck-next/index/appcheck_nonfirebase.js diff --git a/appcheck-next/index.js b/appcheck-next/index.js index 824cd3cb..b2faba28 100644 --- a/appcheck-next/index.js +++ b/appcheck-next/index.js @@ -63,3 +63,40 @@ function initializeCustomProvider() { }); // [END appcheck_initialize_custom_provider] } + +function nonFirebase() { + const { initializeApp } = require("firebase/app"); + const app = initializeApp({ + // Your firebase configuration object + }); + const { ReCaptchaV3Provider } = require('firebase/app-check'); + const provider = new ReCaptchaV3Provider(''); + + // [START appcheck_nonfirebase] + const { initializeAppCheck, getToken } = require('firebase/app-check'); + + const appCheck = initializeAppCheck( + app, + { provider: provider } // ReCaptchaV3Provider or CustomProvider + ); + + const callApiWithAppCheckExample = async () => { + let appCheckTokenResponse; + try { + appCheckTokenResponse = await getToken(appCheck, /* forceRefresh= */ false); + } catch (err) { + // Handle any errors if the token was not retrieved. + return; + } + + // Include the App Check token with requests to your server. + const apiResponse = await fetch('https://yourbackend.example.com/yourApiEndpoint', { + headers: { + 'X-Firebase-AppCheck': appCheckTokenResponse.token, + } + }); + + // Handle response from your backend. + }; + // [END appcheck_nonfirebase] +} diff --git a/appcheck/index.js b/appcheck/index.js index 04282f4d..6ad5079a 100644 --- a/appcheck/index.js +++ b/appcheck/index.js @@ -53,3 +53,24 @@ function initializeCustomProvider() { appCheck.activate(appCheckCustomProvider); // [END appcheck_initialize_custom_provider] } + +// [START appcheck_nonfirebase] +const callApiWithAppCheckExample = async () => { + let appCheckTokenResponse; + try { + appCheckTokenResponse = await firebase.appCheck().getToken(/* forceRefresh= */ false); + } catch (err) { + // Handle any errors if the token was not retrieved. + return; + } + + // Include the App Check token with requests to your server. + const apiResponse = await fetch('https://yourbackend.example.com/yourApiEndpoint', { + headers: { + 'X-Firebase-AppCheck': appCheckTokenResponse.token, + } + }); + + // Handle response from your backend. +}; +// [END appcheck_nonfirebase] diff --git a/snippets/appcheck-next/index/appcheck_nonfirebase.js b/snippets/appcheck-next/index/appcheck_nonfirebase.js new file mode 100644 index 00000000..e1d8dc87 --- /dev/null +++ b/snippets/appcheck-next/index/appcheck_nonfirebase.js @@ -0,0 +1,32 @@ +// This snippet file was generated by processing the source file: +// ./appcheck-next/index.js +// +// To make edits to the snippets in this file, please edit the source + +// [START appcheck_nonfirebase_modular] +import { initializeAppCheck, getToken } from 'firebase/app-check'; + +const appCheck = initializeAppCheck( + app, + { provider: provider } // ReCaptchaV3Provider or CustomProvider +); + +const callApiWithAppCheckExample = async () => { + let appCheckTokenResponse; + try { + appCheckTokenResponse = await getToken(appCheck, /* forceRefresh= */ false); + } catch (err) { + // Handle any errors if the token was not retrieved. + return; + } + + // Include the App Check token with requests to your server. + const apiResponse = await fetch('https://yourbackend.example.com/yourApiEndpoint', { + headers: { + 'X-Firebase-AppCheck': appCheckTokenResponse.token, + } + }); + + // Handle response from your backend. +}; +// [END appcheck_nonfirebase_modular] \ No newline at end of file From 74b104c98c9312132d690617fa17248212bc52ed Mon Sep 17 00:00:00 2001 From: Kevin Cheung Date: Wed, 28 Jul 2021 16:03:21 -0700 Subject: [PATCH 173/235] Show isTokenAutoRefreshEnabled in App Check (#208) * Show isTokenAutoRefreshEnabled in App Check * npm run snippets --- appcheck-next/index.js | 12 ++++++++++-- appcheck/index.js | 14 ++++++++++++-- .../appcheck-next/index/appcheck_initialize.js | 6 +++++- .../index/appcheck_initialize_custom_provider.js | 6 +++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/appcheck-next/index.js b/appcheck-next/index.js index b2faba28..f5598ebd 100644 --- a/appcheck-next/index.js +++ b/appcheck-next/index.js @@ -13,7 +13,11 @@ function initialize() { // Pass your reCAPTCHA v3 site key (public key) to activate(). Make sure this // key is the counterpart to the secret key you set in the Firebase console. const appCheck = initializeAppCheck(app, { - provider: new ReCaptchaV3Provider('abcdefghijklmnopqrstuvwxy-1234567890abcd') + provider: new ReCaptchaV3Provider('abcdefghijklmnopqrstuvwxy-1234567890abcd'), + + // Optional argument. If true, the SDK automatically refreshes App Check + // tokens as needed. + isTokenAutoRefreshEnabled: true }); // [END appcheck_initialize] } @@ -59,7 +63,11 @@ function initializeCustomProvider() { }); const appCheck = initializeAppCheck(app, { - provider: appCheckCustomProvider + provider: appCheckCustomProvider, + + // Optional argument. If true, the SDK automatically refreshes App Check + // tokens as needed. + isTokenAutoRefreshEnabled: true }); // [END appcheck_initialize_custom_provider] } diff --git a/appcheck/index.js b/appcheck/index.js index 6ad5079a..3721b16c 100644 --- a/appcheck/index.js +++ b/appcheck/index.js @@ -10,7 +10,12 @@ function initialize() { const appCheck = firebase.appCheck(); // Pass your reCAPTCHA v3 site key (public key) to activate(). Make sure this // key is the counterpart to the secret key you set in the Firebase console. - appCheck.activate('abcdefghijklmnopqrstuvwxy-1234567890abcd'); + appCheck.activate( + 'abcdefghijklmnopqrstuvwxy-1234567890abcd', + + // Optional argument. If true, the SDK automatically refreshes App Check + // tokens as needed. + true); // [END appcheck_initialize] } @@ -50,7 +55,12 @@ function initializeCustomProvider() { }); const appCheck = firebase.appCheck(); - appCheck.activate(appCheckCustomProvider); + appCheck.activate( + appCheckCustomProvider, + + // Optional argument. If true, the SDK automatically refreshes App Check + // tokens as needed. + true); // [END appcheck_initialize_custom_provider] } diff --git a/snippets/appcheck-next/index/appcheck_initialize.js b/snippets/appcheck-next/index/appcheck_initialize.js index 7aa91572..54074768 100644 --- a/snippets/appcheck-next/index/appcheck_initialize.js +++ b/snippets/appcheck-next/index/appcheck_initialize.js @@ -14,6 +14,10 @@ const app = initializeApp({ // Pass your reCAPTCHA v3 site key (public key) to activate(). Make sure this // key is the counterpart to the secret key you set in the Firebase console. const appCheck = initializeAppCheck(app, { - provider: new ReCaptchaV3Provider('abcdefghijklmnopqrstuvwxy-1234567890abcd') + provider: new ReCaptchaV3Provider('abcdefghijklmnopqrstuvwxy-1234567890abcd'), + + // Optional argument. If true, the SDK automatically refreshes App Check + // tokens as needed. + isTokenAutoRefreshEnabled: true }); // [END appcheck_initialize_modular] \ No newline at end of file diff --git a/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js b/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js index ef721941..787e13a0 100644 --- a/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js +++ b/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js @@ -12,6 +12,10 @@ const app = initializeApp({ }); const appCheck = initializeAppCheck(app, { - provider: appCheckCustomProvider + provider: appCheckCustomProvider, + + // Optional argument. If true, the SDK automatically refreshes App Check + // tokens as needed. + isTokenAutoRefreshEnabled: true }); // [END appcheck_initialize_custom_provider_modular] \ No newline at end of file From ae2d5c7ba741f18f3f213b269cac36424be4eb6d Mon Sep 17 00:00:00 2001 From: Kevin Cheung Date: Thu, 29 Jul 2021 01:29:42 -0700 Subject: [PATCH 174/235] Say how to generate separated snippets (#210) --- scripts/separate-snippets.ts | 3 ++- .../analytics-next/ecommerce/analytics_ecommerce_add_cart.js | 3 ++- .../analytics-next/ecommerce/analytics_ecommerce_checkout.js | 3 ++- snippets/analytics-next/ecommerce/analytics_ecommerce_items.js | 3 ++- .../ecommerce/analytics_ecommerce_payment_info.js | 3 ++- .../analytics-next/ecommerce/analytics_ecommerce_promotions.js | 3 ++- .../analytics-next/ecommerce/analytics_ecommerce_purchase.js | 3 ++- .../analytics-next/ecommerce/analytics_ecommerce_refund.js | 3 ++- .../ecommerce/analytics_ecommerce_remove_cart.js | 3 ++- .../ecommerce/analytics_ecommerce_select_item.js | 3 ++- .../ecommerce/analytics_ecommerce_shipping_info.js | 3 ++- .../analytics-next/ecommerce/analytics_ecommerce_view_cart.js | 3 ++- .../ecommerce/analytics_ecommerce_view_item_details.js | 3 ++- .../ecommerce/analytics_ecommerce_view_item_list.js | 3 ++- snippets/analytics-next/index/analytics_initialize.js | 3 ++- snippets/analytics-next/index/analytics_log_event.js | 3 ++- .../analytics-next/index/analytics_log_event_custom_params.js | 3 ++- snippets/analytics-next/index/analytics_log_event_params.js | 3 ++- snippets/analytics-next/index/analytics_set_user_properties.js | 3 ++- snippets/appcheck-next/index/appcheck_custom_provider.js | 3 ++- snippets/appcheck-next/index/appcheck_initialize.js | 3 ++- .../appcheck-next/index/appcheck_initialize_custom_provider.js | 3 ++- snippets/appcheck-next/index/appcheck_nonfirebase.js | 3 ++- snippets/auth-next/anonymous/auth_anon_sign_in.js | 3 ++- snippets/auth-next/apple/auth_apple_link_facebook.js | 3 ++- snippets/auth-next/apple/auth_apple_nonce_node.js | 3 ++- snippets/auth-next/apple/auth_apple_provider_create.js | 3 ++- snippets/auth-next/apple/auth_apple_provider_params.js | 3 ++- snippets/auth-next/apple/auth_apple_provider_scopes.js | 3 ++- snippets/auth-next/apple/auth_apple_reauthenticate_popup.js | 3 ++- snippets/auth-next/apple/auth_apple_signin_nonce.js | 3 ++- snippets/auth-next/apple/auth_apple_signin_popup.js | 3 ++- snippets/auth-next/apple/auth_apple_signin_redirect.js | 3 ++- snippets/auth-next/apple/auth_apple_signin_redirect_result.js | 3 ++- .../auth-state-persistence/auth_set_persistence_none.js | 3 ++- .../auth-state-persistence/auth_set_persistence_session.js | 3 ++- snippets/auth-next/cordova/auth_cordova_redirect_result.js | 3 ++- snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js | 3 ++- snippets/auth-next/cordova/auth_create_google_provider.js | 3 ++- .../custom-email-handler/auth_handle_mgmt_query_params.js | 3 ++- .../custom-email-handler/auth_handle_recover_email.js | 3 ++- .../custom-email-handler/auth_handle_reset_password.js | 3 ++- .../auth-next/custom-email-handler/auth_handle_verify_email.js | 3 ++- snippets/auth-next/custom/auth_sign_in_custom.js | 3 ++- .../email-link-auth/auth_email_link_actioncode_settings.js | 3 ++- snippets/auth-next/email-link-auth/auth_email_link_link.js | 3 ++- snippets/auth-next/email-link-auth/auth_email_link_reauth.js | 3 ++- snippets/auth-next/email-link-auth/auth_email_link_send.js | 3 ++- snippets/auth-next/email-link-auth/email_link_complete.js | 3 ++- snippets/auth-next/email-link-auth/email_link_diferentiate.js | 3 ++- snippets/auth-next/email/auth_send_email_verification.js | 3 ++- snippets/auth-next/email/auth_send_password_reset.js | 3 ++- snippets/auth-next/email/auth_signin_password.js | 3 ++- snippets/auth-next/email/auth_signup_password.js | 3 ++- snippets/auth-next/emulator-suite/auth_emulator_connect.js | 3 ++- snippets/auth-next/facebook/auth_facebook_callback.js | 3 ++- snippets/auth-next/facebook/auth_facebook_checksameuser.js | 3 ++- snippets/auth-next/facebook/auth_facebook_provider_create.js | 3 ++- snippets/auth-next/facebook/auth_facebook_provider_params.js | 3 ++- snippets/auth-next/facebook/auth_facebook_provider_scopes.js | 3 ++- snippets/auth-next/facebook/auth_facebook_signin_credential.js | 3 ++- snippets/auth-next/facebook/auth_facebook_signin_popup.js | 3 ++- .../auth-next/facebook/auth_facebook_signin_redirect_result.js | 3 ++- snippets/auth-next/github/auth_github_provider_create.js | 3 ++- snippets/auth-next/github/auth_github_provider_credential.js | 3 ++- snippets/auth-next/github/auth_github_provider_params.js | 3 ++- snippets/auth-next/github/auth_github_provider_scopes.js | 3 ++- snippets/auth-next/github/auth_github_signin_popup.js | 3 ++- .../auth-next/github/auth_github_signin_redirect_result.js | 3 ++- snippets/auth-next/google-signin/auth_google_build_signin.js | 3 ++- snippets/auth-next/google-signin/auth_google_callback.js | 3 ++- snippets/auth-next/google-signin/auth_google_checksameuser.js | 3 ++- .../auth-next/google-signin/auth_google_provider_create.js | 3 ++- .../auth-next/google-signin/auth_google_provider_params.js | 3 ++- .../auth-next/google-signin/auth_google_provider_scopes.js | 3 ++- .../auth-next/google-signin/auth_google_signin_credential.js | 3 ++- snippets/auth-next/google-signin/auth_google_signin_popup.js | 3 ++- .../google-signin/auth_google_signin_redirect_result.js | 3 ++- snippets/auth-next/index/auth_current_user.js | 3 ++- snippets/auth-next/index/auth_make_email_credential.js | 3 ++- snippets/auth-next/index/auth_make_facebook_credential.js | 3 ++- snippets/auth-next/index/auth_make_google_credential.js | 3 ++- snippets/auth-next/index/auth_set_language_code.js | 3 ++- snippets/auth-next/index/auth_sign_out.js | 3 ++- snippets/auth-next/index/auth_signin_credential.js | 3 ++- snippets/auth-next/index/auth_signin_redirect.js | 3 ++- snippets/auth-next/index/auth_state_listener.js | 3 ++- .../auth-next/link-multiple-accounts/auth_anonymous_link.js | 3 ++- .../auth-next/link-multiple-accounts/auth_get_providers.js | 3 ++- .../link-multiple-accounts/auth_get_redirect_result.js | 3 ++- .../auth-next/link-multiple-accounts/auth_link_with_popup.js | 3 ++- .../link-multiple-accounts/auth_link_with_redirect.js | 3 ++- .../link-multiple-accounts/auth_make_email_credential.js | 3 ++- .../auth-next/link-multiple-accounts/auth_merge_accounts.js | 3 ++- snippets/auth-next/link-multiple-accounts/auth_simple_link.js | 3 ++- .../auth-next/link-multiple-accounts/auth_unlink_provider.js | 3 ++- snippets/auth-next/manage/auth_delete_user.js | 3 ++- snippets/auth-next/manage/auth_get_user_profile.js | 3 ++- snippets/auth-next/manage/auth_get_user_profile_provider.js | 3 ++- snippets/auth-next/manage/auth_reauth_with_credential.js | 3 ++- snippets/auth-next/manage/auth_send_password_reset.js | 3 ++- snippets/auth-next/manage/auth_update_password.js | 3 ++- snippets/auth-next/manage/auth_update_user_email.js | 3 ++- snippets/auth-next/manage/auth_update_user_profile.js | 3 ++- snippets/auth-next/manage/send_email_verification.js | 3 ++- .../auth-next/microsoft-oauth/auth_msft_create_provider.js | 3 ++- snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js | 3 ++- .../auth-next/microsoft-oauth/auth_msft_provider_params.js | 3 ++- .../microsoft-oauth/auth_msft_provider_params_tenant.js | 3 ++- .../auth-next/microsoft-oauth/auth_msft_provider_scopes.js | 3 ++- snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js | 3 ++- snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js | 3 ++- .../auth-next/microsoft-oauth/auth_msft_signin_redirect.js | 3 ++- .../microsoft-oauth/auth_msft_signin_redirect_result.js | 3 ++- snippets/auth-next/phone-auth/auth_get_recaptcha_response.js | 3 ++- snippets/auth-next/phone-auth/auth_phone_recaptcha_render.js | 3 ++- .../phone-auth/auth_phone_recaptcha_verifier_invisible.js | 3 ++- .../phone-auth/auth_phone_recaptcha_verifier_simple.js | 3 ++- .../phone-auth/auth_phone_recaptcha_verifier_visible.js | 3 ++- snippets/auth-next/phone-auth/auth_phone_signin.js | 3 ++- snippets/auth-next/phone-auth/auth_phone_verify_code.js | 3 ++- .../auth-next/service-worker-sessions/auth_svc_get_idtoken.js | 3 ++- .../auth-next/service-worker-sessions/auth_svc_intercept.js | 3 ++- .../service-worker-sessions/auth_svc_listen_activate.js | 3 ++- .../auth-next/service-worker-sessions/auth_svc_register.js | 3 ++- .../service-worker-sessions/auth_svc_sign_in_email.js | 3 ++- .../auth-next/service-worker-sessions/auth_svc_subscribe.js | 3 ++- snippets/auth-next/twitter/auth_twitter_provider_create.js | 3 ++- snippets/auth-next/twitter/auth_twitter_provider_params.js | 3 ++- snippets/auth-next/twitter/auth_twitter_signin_popup.js | 3 ++- .../auth-next/twitter/auth_twitter_signin_redirect_result.js | 3 ++- snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js | 3 ++- snippets/auth-next/yahoo-oauth/auth_yahoo_provider_create.js | 3 ++- snippets/auth-next/yahoo-oauth/auth_yahoo_provider_params.js | 3 ++- snippets/auth-next/yahoo-oauth/auth_yahoo_provider_scopes.js | 3 ++- snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js | 3 ++- snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js | 3 ++- snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js | 3 ++- .../auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js | 3 ++- snippets/database-next/emulator-suite/rtdb_emulator_connect.js | 3 ++- snippets/database-next/emulator-suite/rtdb_emulator_flush.js | 3 ++- snippets/database-next/index/rtdb_get_reference.js | 3 ++- .../database-next/lists-of-data/rtdb_social_listen_children.js | 3 ++- .../database-next/lists-of-data/rtdb_social_listen_value.js | 3 ++- .../database-next/lists-of-data/rtdb_social_most_starred.js | 3 ++- .../database-next/lists-of-data/rtdb_social_most_viewed.js | 3 ++- snippets/database-next/lists-of-data/rtdb_social_push.js | 3 ++- snippets/database-next/lists-of-data/rtdb_social_recent.js | 3 ++- snippets/database-next/offline/rtdb_detect_connection_state.js | 3 ++- snippets/database-next/offline/rtdb_estimate_clock_skew.js | 3 ++- snippets/database-next/offline/rtdb_ondisconnect_callback.js | 3 ++- snippets/database-next/offline/rtdb_ondisconnect_cancel.js | 3 ++- snippets/database-next/offline/rtdb_ondisconnect_simple.js | 3 ++- snippets/database-next/offline/rtdb_sample_presence_app.js | 3 ++- snippets/database-next/offline/rtdb_set_server_timestamp.js | 3 ++- snippets/database-next/read-and-write/rtdb_read_once_get.js | 3 ++- .../read-and-write/rtdb_social_completion_callback.js | 3 ++- .../read-and-write/rtdb_social_listen_star_count.js | 3 ++- .../read-and-write/rtdb_social_single_value_read.js | 3 ++- .../database-next/read-and-write/rtdb_social_star_increment.js | 3 ++- .../read-and-write/rtdb_social_star_transaction.js | 3 ++- .../database-next/read-and-write/rtdb_social_write_fan_out.js | 3 ++- snippets/database-next/read-and-write/rtdb_write_new_user.js | 3 ++- .../read-and-write/rtdb_write_new_user_completion.js | 3 ++- snippets/database-next/sharding/rtdb_multiple_instances.js | 3 ++- snippets/firebaseapp-next/firebaseapp/firebase_options.js | 3 ++- snippets/firebaseapp-next/firebaseapp/firebase_secondary.js | 3 ++- snippets/firestore-next/emulator-suite/fs_emulator_connect.js | 3 ++- snippets/firestore-next/test-firestore/add_ada_lovelace.js | 3 ++- snippets/firestore-next/test-firestore/add_alan_turing.js | 3 ++- snippets/firestore-next/test-firestore/add_document.js | 3 ++- .../firestore-next/test-firestore/add_rating_transaction.js | 3 ++- .../firestore-next/test-firestore/array_contains_any_filter.js | 3 ++- .../firestore-next/test-firestore/array_contains_filter.js | 3 ++- snippets/firestore-next/test-firestore/chain_filters.js | 3 ++- snippets/firestore-next/test-firestore/cities_document_set.js | 3 ++- snippets/firestore-next/test-firestore/city_custom_object.js | 3 ++- snippets/firestore-next/test-firestore/collection_reference.js | 3 ++- snippets/firestore-next/test-firestore/data_types.js | 3 ++- snippets/firestore-next/test-firestore/delete_collection.js | 3 ++- snippets/firestore-next/test-firestore/delete_document.js | 3 ++- snippets/firestore-next/test-firestore/detach_listener.js | 3 ++- snippets/firestore-next/test-firestore/disable_network.js | 3 ++- snippets/firestore-next/test-firestore/doc_reference.js | 3 ++- .../firestore-next/test-firestore/doc_reference_alternative.js | 3 ++- snippets/firestore-next/test-firestore/enable_network.js | 3 ++- snippets/firestore-next/test-firestore/example_data.js | 3 ++- snippets/firestore-next/test-firestore/example_filters.js | 3 ++- snippets/firestore-next/test-firestore/filter_and_order.js | 3 ++- .../firestore-next/test-firestore/fs_collection_group_query.js | 3 ++- .../test-firestore/fs_collection_group_query_data_setup.js | 3 ++- snippets/firestore-next/test-firestore/fs_setup_cache.js | 3 ++- snippets/firestore-next/test-firestore/get_all_users.js | 3 ++- snippets/firestore-next/test-firestore/get_custom_object.js | 3 ++- snippets/firestore-next/test-firestore/get_document.js | 3 ++- snippets/firestore-next/test-firestore/get_document_options.js | 3 ++- snippets/firestore-next/test-firestore/get_multiple.js | 3 ++- snippets/firestore-next/test-firestore/get_multiple_all.js | 3 ++- snippets/firestore-next/test-firestore/handle_listen_errors.js | 3 ++- snippets/firestore-next/test-firestore/in_filter.js | 3 ++- snippets/firestore-next/test-firestore/in_filter_with_array.js | 3 ++- .../firestore-next/test-firestore/initialize_persistence.js | 3 ++- .../firestore-next/test-firestore/invalid_filter_and_order.js | 3 ++- .../firestore-next/test-firestore/invalid_range_filters.js | 3 ++- snippets/firestore-next/test-firestore/listen_diffs.js | 3 ++- snippets/firestore-next/test-firestore/listen_document.js | 3 ++- .../firestore-next/test-firestore/listen_document_local.js | 3 ++- snippets/firestore-next/test-firestore/listen_for_users.js | 3 ++- snippets/firestore-next/test-firestore/listen_multiple.js | 3 ++- snippets/firestore-next/test-firestore/listen_with_metadata.js | 3 ++- snippets/firestore-next/test-firestore/new_document.js | 3 ++- snippets/firestore-next/test-firestore/not_in_filter.js | 3 ++- snippets/firestore-next/test-firestore/order_and_end.js | 3 ++- snippets/firestore-next/test-firestore/order_and_limit.js | 3 ++- snippets/firestore-next/test-firestore/order_and_limit_desc.js | 3 ++- snippets/firestore-next/test-firestore/order_and_start.js | 3 ++- snippets/firestore-next/test-firestore/order_multiple.js | 3 ++- snippets/firestore-next/test-firestore/paginate.js | 3 ++- .../test-firestore/server_timestamp_resolution_options.js | 3 ++- snippets/firestore-next/test-firestore/set_custom_object.js | 3 ++- snippets/firestore-next/test-firestore/set_document.js | 3 ++- snippets/firestore-next/test-firestore/set_with_merge.js | 3 ++- snippets/firestore-next/test-firestore/simple_queries.js | 3 ++- snippets/firestore-next/test-firestore/simple_queries_again.js | 3 ++- .../firestore-next/test-firestore/simple_query_not_equal.js | 3 ++- snippets/firestore-next/test-firestore/start_doc.js | 3 ++- .../firestore-next/test-firestore/start_multiple_orderby.js | 3 ++- .../firestore-next/test-firestore/subcollection_reference.js | 3 ++- snippets/firestore-next/test-firestore/transaction.js | 3 ++- snippets/firestore-next/test-firestore/transaction_promise.js | 3 ++- snippets/firestore-next/test-firestore/update_delete_field.js | 3 ++- snippets/firestore-next/test-firestore/update_document.js | 3 ++- .../firestore-next/test-firestore/update_document_array.js | 3 ++- .../firestore-next/test-firestore/update_document_increment.js | 3 ++- .../firestore-next/test-firestore/update_document_nested.js | 3 ++- .../test-firestore/update_with_server_timestamp.js | 3 ++- snippets/firestore-next/test-firestore/use_from_cache.js | 3 ++- .../firestore-next/test-firestore/valid_filter_and_order.js | 3 ++- snippets/firestore-next/test-firestore/valid_range_filters.js | 3 ++- snippets/firestore-next/test-firestore/write_batch.js | 3 ++- .../test-solution-aggregation/get_collection_ratings.js | 3 ++- .../firestore-next/test-solution-aggregation/sample_doc.js | 3 ++- .../firestore-next/test-solution-arrays/post_with_array.js | 3 ++- snippets/firestore-next/test-solution-arrays/post_with_map.js | 3 ++- .../test-solution-arrays/post_with_map_advanced.js | 3 ++- .../firestore-next/test-solution-arrays/query_in_category.js | 3 ++- .../test-solution-arrays/query_in_category_timestamp.js | 3 ++- .../query_in_category_timestamp_invalid.js | 3 ++- .../firestore-next/test-solution-bundles/fs_bundle_load.js | 3 ++- .../firestore-next/test-solution-counters/create_counter.js | 3 ++- snippets/firestore-next/test-solution-counters/get_count.js | 3 ++- .../firestore-next/test-solution-counters/increment_counter.js | 3 ++- .../firestore-next/test-solution-geoqueries/fs_geo_add_hash.js | 3 ++- .../test-solution-geoqueries/fs_geo_query_hashes.js | 3 ++- .../functions-next/callable/fb_functions_call_add_message.js | 3 ++- .../callable/fb_functions_call_add_message_error.js | 3 ++- snippets/functions-next/callable/fb_functions_initialize.js | 3 ++- .../emulator-suite/fb_functions_callable_call.js | 3 ++- .../emulator-suite/fb_functions_emulator_connect.js | 3 ++- snippets/messaging-next/index/messaging_delete_token.js | 3 ++- .../messaging-next/index/messaging_get_messaging_object.js | 3 ++- snippets/messaging-next/index/messaging_get_token.js | 3 ++- snippets/messaging-next/index/messaging_receive_message.js | 3 ++- snippets/messaging-next/index/messaging_request_permission.js | 3 ++- snippets/messaging-next/service-worker/messaging_init_in_sw.js | 3 ++- .../service-worker/messaging_on_background_message.js | 3 ++- snippets/perf-next/index/perf_add_custom_attributes.js | 3 ++- snippets/perf-next/index/perf_add_custom_metrics.js | 3 ++- snippets/perf-next/index/perf_add_custom_trace.js | 3 ++- snippets/perf-next/index/perf_get_instance.js | 3 ++- snippets/perf-next/index/perf_initialize.js | 3 ++- snippets/perf-next/index/perf_user_timing_marks.js | 3 ++- snippets/placeholder/coming_soon.js | 3 ++- snippets/remoteconfig-next/index/rc_fetch_config_callback.js | 3 ++- snippets/remoteconfig-next/index/rc_get_instance.js | 3 ++- snippets/remoteconfig-next/index/rc_get_values.js | 3 ++- snippets/remoteconfig-next/index/rc_set_default_values.js | 3 ++- snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js | 3 ++- snippets/storage-next/create-reference/storage_create_ref.js | 3 ++- .../storage-next/create-reference/storage_create_ref_child.js | 3 ++- snippets/storage-next/create-reference/storage_navigate_ref.js | 3 ++- .../create-reference/storage_navigate_ref_chain.js | 3 ++- .../storage-next/create-reference/storage_ref_full_example.js | 3 ++- .../storage-next/create-reference/storage_ref_properties.js | 3 ++- snippets/storage-next/delete-files/storage_delete_file.js | 3 ++- .../storage-next/download-files/storage_download_create_ref.js | 3 ++- .../download-files/storage_download_full_example.js | 3 ++- .../storage-next/download-files/storage_download_via_url.js | 3 ++- snippets/storage-next/file-metadata/storage_custom_metadata.js | 3 ++- snippets/storage-next/file-metadata/storage_delete_metadata.js | 3 ++- snippets/storage-next/file-metadata/storage_get_metadata.js | 3 ++- snippets/storage-next/file-metadata/storage_update_metadata.js | 3 ++- snippets/storage-next/index/storage_custom_app.js | 3 ++- snippets/storage-next/index/storage_initialize.js | 3 ++- snippets/storage-next/index/storage_multiple_buckets.js | 3 ++- snippets/storage-next/index/storage_on_complete.js | 3 ++- snippets/storage-next/list-files/storage_list_all.js | 3 ++- snippets/storage-next/list-files/storage_list_paginate.js | 3 ++- snippets/storage-next/upload-files/storage_manage_uploads.js | 3 ++- snippets/storage-next/upload-files/storage_monitor_upload.js | 3 ++- snippets/storage-next/upload-files/storage_upload_blob.js | 3 ++- snippets/storage-next/upload-files/storage_upload_bytes.js | 3 ++- .../storage-next/upload-files/storage_upload_handle_error.js | 3 ++- snippets/storage-next/upload-files/storage_upload_metadata.js | 3 ++- snippets/storage-next/upload-files/storage_upload_ref.js | 3 ++- snippets/storage-next/upload-files/storage_upload_string.js | 3 ++- 306 files changed, 612 insertions(+), 306 deletions(-) diff --git a/scripts/separate-snippets.ts b/scripts/separate-snippets.ts index dbc89c52..86821383 100644 --- a/scripts/separate-snippets.ts +++ b/scripts/separate-snippets.ts @@ -125,7 +125,8 @@ function processSnippet( `// This snippet file was generated by processing the source file:`, `// ${sourceFile}`, `//`, - `// To make edits to the snippets in this file, please edit the source`, + `// To update the snippets in this file, edit the source and then run`, + `// 'npm run snippets'.`, ``, ]; const content = [...preambleLines, ...outputLines].join("\n"); diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js index 8d7f87cf..8f0e68bd 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_add_cart.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_add_cart_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js index 85611fb1..beaae722 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_checkout.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_checkout_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_items.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_items.js index e3ad7cbe..03b27b47 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_items.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_items.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_items_modular] // A pair of jeggings diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js index db328513..048ad5da 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_payment_info.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_payment_info_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js index 666241ee..d0577a18 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_promotions.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_promotions_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js index a5ba8c62..12b6d02d 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_purchase.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_purchase_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js index fab84487..706e1d7d 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_refund.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_refund_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js index aa841d8f..1ad9790f 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_remove_cart.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_remove_cart_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js index 74f3c8c2..d4eda55c 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_select_item.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_select_item_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js index 09cd0f05..a4f43cbe 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_shipping_info.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_shipping_info_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js index 89ab04ec..cc2359dc 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_cart.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_view_cart_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js index 920e2c18..83f3474e 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_details.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_view_item_details_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js index 13eb197c..fb2fec01 100644 --- a/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js +++ b/snippets/analytics-next/ecommerce/analytics_ecommerce_view_item_list.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/ecommerce.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_ecommerce_view_item_list_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/index/analytics_initialize.js b/snippets/analytics-next/index/analytics_initialize.js index 4fb42cb3..42a9578d 100644 --- a/snippets/analytics-next/index/analytics_initialize.js +++ b/snippets/analytics-next/index/analytics_initialize.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_initialize_modular] import { getAnalytics } from "firebase/analytics"; diff --git a/snippets/analytics-next/index/analytics_log_event.js b/snippets/analytics-next/index/analytics_log_event.js index c5537b5b..7bd74243 100644 --- a/snippets/analytics-next/index/analytics_log_event.js +++ b/snippets/analytics-next/index/analytics_log_event.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_log_event_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/index/analytics_log_event_custom_params.js b/snippets/analytics-next/index/analytics_log_event_custom_params.js index 122d94d1..7d76b3f5 100644 --- a/snippets/analytics-next/index/analytics_log_event_custom_params.js +++ b/snippets/analytics-next/index/analytics_log_event_custom_params.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_log_event_custom_params_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/index/analytics_log_event_params.js b/snippets/analytics-next/index/analytics_log_event_params.js index 86831dbd..27e6528d 100644 --- a/snippets/analytics-next/index/analytics_log_event_params.js +++ b/snippets/analytics-next/index/analytics_log_event_params.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_log_event_params_modular] import { getAnalytics, logEvent } from "firebase/analytics"; diff --git a/snippets/analytics-next/index/analytics_set_user_properties.js b/snippets/analytics-next/index/analytics_set_user_properties.js index b064cdbf..f432e5bf 100644 --- a/snippets/analytics-next/index/analytics_set_user_properties.js +++ b/snippets/analytics-next/index/analytics_set_user_properties.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./analytics-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START analytics_set_user_properties_modular] import { getAnalytics, setUserProperties } from "firebase/analytics"; diff --git a/snippets/appcheck-next/index/appcheck_custom_provider.js b/snippets/appcheck-next/index/appcheck_custom_provider.js index 7bcb0452..35c7bc99 100644 --- a/snippets/appcheck-next/index/appcheck_custom_provider.js +++ b/snippets/appcheck-next/index/appcheck_custom_provider.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./appcheck-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START appcheck_custom_provider_modular] import { CustomProvider } from "firebase/app-check"; diff --git a/snippets/appcheck-next/index/appcheck_initialize.js b/snippets/appcheck-next/index/appcheck_initialize.js index 54074768..f7763562 100644 --- a/snippets/appcheck-next/index/appcheck_initialize.js +++ b/snippets/appcheck-next/index/appcheck_initialize.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./appcheck-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START appcheck_initialize_modular] import { initializeApp } from "firebase/app"; diff --git a/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js b/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js index 787e13a0..03f2baa8 100644 --- a/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js +++ b/snippets/appcheck-next/index/appcheck_initialize_custom_provider.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./appcheck-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START appcheck_initialize_custom_provider_modular] import { initializeApp } from "firebase/app"; diff --git a/snippets/appcheck-next/index/appcheck_nonfirebase.js b/snippets/appcheck-next/index/appcheck_nonfirebase.js index e1d8dc87..275891f8 100644 --- a/snippets/appcheck-next/index/appcheck_nonfirebase.js +++ b/snippets/appcheck-next/index/appcheck_nonfirebase.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./appcheck-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START appcheck_nonfirebase_modular] import { initializeAppCheck, getToken } from 'firebase/app-check'; diff --git a/snippets/auth-next/anonymous/auth_anon_sign_in.js b/snippets/auth-next/anonymous/auth_anon_sign_in.js index b495ec28..3db81772 100644 --- a/snippets/auth-next/anonymous/auth_anon_sign_in.js +++ b/snippets/auth-next/anonymous/auth_anon_sign_in.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/anonymous.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_anon_sign_in_modular] import { getAuth, signInAnonymously } from "firebase/auth"; diff --git a/snippets/auth-next/apple/auth_apple_link_facebook.js b/snippets/auth-next/apple/auth_apple_link_facebook.js index a9f116ad..1ed9d764 100644 --- a/snippets/auth-next/apple/auth_apple_link_facebook.js +++ b/snippets/auth-next/apple/auth_apple_link_facebook.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/apple.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_apple_link_facebook_modular] import { getAuth, linkWithPopup, FacebookAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/apple/auth_apple_nonce_node.js b/snippets/auth-next/apple/auth_apple_nonce_node.js index 27b08552..26bb2ef0 100644 --- a/snippets/auth-next/apple/auth_apple_nonce_node.js +++ b/snippets/auth-next/apple/auth_apple_nonce_node.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/apple.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_apple_nonce_node_modular] const crypto = require("crypto"); diff --git a/snippets/auth-next/apple/auth_apple_provider_create.js b/snippets/auth-next/apple/auth_apple_provider_create.js index 9612b2c3..b6c0aefd 100644 --- a/snippets/auth-next/apple/auth_apple_provider_create.js +++ b/snippets/auth-next/apple/auth_apple_provider_create.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/apple.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_apple_provider_create_modular] import { OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/apple/auth_apple_provider_params.js b/snippets/auth-next/apple/auth_apple_provider_params.js index f0f914a2..775ab94b 100644 --- a/snippets/auth-next/apple/auth_apple_provider_params.js +++ b/snippets/auth-next/apple/auth_apple_provider_params.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/apple.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_apple_provider_params_modular] provider.setCustomParameters({ diff --git a/snippets/auth-next/apple/auth_apple_provider_scopes.js b/snippets/auth-next/apple/auth_apple_provider_scopes.js index 306853bd..86da8bbc 100644 --- a/snippets/auth-next/apple/auth_apple_provider_scopes.js +++ b/snippets/auth-next/apple/auth_apple_provider_scopes.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/apple.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_apple_provider_scopes_modular] provider.addScope('email'); diff --git a/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js b/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js index 5d1b9257..129fe920 100644 --- a/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js +++ b/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/apple.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_apple_reauthenticate_popup_modular] import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/apple/auth_apple_signin_nonce.js b/snippets/auth-next/apple/auth_apple_signin_nonce.js index 36962b8f..ffa3a3d2 100644 --- a/snippets/auth-next/apple/auth_apple_signin_nonce.js +++ b/snippets/auth-next/apple/auth_apple_signin_nonce.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/apple.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_apple_signin_nonce_modular] import { getAuth, signInWithCredential, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/apple/auth_apple_signin_popup.js b/snippets/auth-next/apple/auth_apple_signin_popup.js index 3fb9436c..2db09607 100644 --- a/snippets/auth-next/apple/auth_apple_signin_popup.js +++ b/snippets/auth-next/apple/auth_apple_signin_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/apple.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_apple_signin_popup_modular] import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/apple/auth_apple_signin_redirect.js b/snippets/auth-next/apple/auth_apple_signin_redirect.js index 9b97a683..f000195d 100644 --- a/snippets/auth-next/apple/auth_apple_signin_redirect.js +++ b/snippets/auth-next/apple/auth_apple_signin_redirect.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/apple.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_apple_signin_redirect_modular] import { getAuth, signInWithRedirect } from "firebase/auth"; diff --git a/snippets/auth-next/apple/auth_apple_signin_redirect_result.js b/snippets/auth-next/apple/auth_apple_signin_redirect_result.js index f0b2d64c..68dba4ab 100644 --- a/snippets/auth-next/apple/auth_apple_signin_redirect_result.js +++ b/snippets/auth-next/apple/auth_apple_signin_redirect_result.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/apple.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_apple_signin_redirect_result_modular] import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js b/snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js index 88b579f9..5224cc21 100644 --- a/snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js +++ b/snippets/auth-next/auth-state-persistence/auth_set_persistence_none.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/auth-state-persistence.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_set_persistence_none_modular] import { getAuth, setPersistence, signInWithRedirect, inMemoryPersistence, GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js b/snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js index 6644370d..d21183ff 100644 --- a/snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js +++ b/snippets/auth-next/auth-state-persistence/auth_set_persistence_session.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/auth-state-persistence.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_set_persistence_session_modular] import { getAuth, setPersistence, signInWithEmailAndPassword, browserSessionPersistence } from "firebase/auth"; diff --git a/snippets/auth-next/cordova/auth_cordova_redirect_result.js b/snippets/auth-next/cordova/auth_cordova_redirect_result.js index f4794507..7bcc69a3 100644 --- a/snippets/auth-next/cordova/auth_cordova_redirect_result.js +++ b/snippets/auth-next/cordova/auth_cordova_redirect_result.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/cordova.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_cordova_redirect_result_modular] import { getAuth, getRedirectResult, GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js b/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js index 14084a12..5aaee22d 100644 --- a/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js +++ b/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/cordova.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_cordova_sign_in_redirect_modular] import { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/cordova/auth_create_google_provider.js b/snippets/auth-next/cordova/auth_create_google_provider.js index 7fb88bc9..aab60312 100644 --- a/snippets/auth-next/cordova/auth_create_google_provider.js +++ b/snippets/auth-next/cordova/auth_create_google_provider.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/cordova.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_create_google_provider_modular] import { GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js b/snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js index 8810372f..6dec3399 100644 --- a/snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js +++ b/snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/custom-email-handler.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_handle_mgmt_query_params_modular] import { initializeApp } from "firebase/app"; diff --git a/snippets/auth-next/custom-email-handler/auth_handle_recover_email.js b/snippets/auth-next/custom-email-handler/auth_handle_recover_email.js index db2bdea8..a4351a50 100644 --- a/snippets/auth-next/custom-email-handler/auth_handle_recover_email.js +++ b/snippets/auth-next/custom-email-handler/auth_handle_recover_email.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/custom-email-handler.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_handle_recover_email_modular] import { checkActionCode, applyActionCode, sendPasswordResetEmail } from "firebase/auth"; diff --git a/snippets/auth-next/custom-email-handler/auth_handle_reset_password.js b/snippets/auth-next/custom-email-handler/auth_handle_reset_password.js index 85f32168..95a3faea 100644 --- a/snippets/auth-next/custom-email-handler/auth_handle_reset_password.js +++ b/snippets/auth-next/custom-email-handler/auth_handle_reset_password.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/custom-email-handler.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_handle_reset_password_modular] import { verifyPasswordResetCode, confirmPasswordReset } from "firebase/auth"; diff --git a/snippets/auth-next/custom-email-handler/auth_handle_verify_email.js b/snippets/auth-next/custom-email-handler/auth_handle_verify_email.js index ca0089f0..730d4601 100644 --- a/snippets/auth-next/custom-email-handler/auth_handle_verify_email.js +++ b/snippets/auth-next/custom-email-handler/auth_handle_verify_email.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/custom-email-handler.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_handle_verify_email_modular] function handleVerifyEmail(auth, actionCode, continueUrl, lang) { diff --git a/snippets/auth-next/custom/auth_sign_in_custom.js b/snippets/auth-next/custom/auth_sign_in_custom.js index 3500d6d9..c345c0ce 100644 --- a/snippets/auth-next/custom/auth_sign_in_custom.js +++ b/snippets/auth-next/custom/auth_sign_in_custom.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/custom.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_sign_in_custom_modular] import { getAuth, signInWithCustomToken } from "firebase/auth"; diff --git a/snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js b/snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js index dd6f4de2..a1480a11 100644 --- a/snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js +++ b/snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/email-link-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_email_link_actioncode_settings_modular] const actionCodeSettings = { diff --git a/snippets/auth-next/email-link-auth/auth_email_link_link.js b/snippets/auth-next/email-link-auth/auth_email_link_link.js index 07abe3c8..a49b979f 100644 --- a/snippets/auth-next/email-link-auth/auth_email_link_link.js +++ b/snippets/auth-next/email-link-auth/auth_email_link_link.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/email-link-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_email_link_link_modular] import { getAuth, linkWithCredential, EmailAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/email-link-auth/auth_email_link_reauth.js b/snippets/auth-next/email-link-auth/auth_email_link_reauth.js index f6c57144..128650cb 100644 --- a/snippets/auth-next/email-link-auth/auth_email_link_reauth.js +++ b/snippets/auth-next/email-link-auth/auth_email_link_reauth.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/email-link-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_email_link_reauth_modular] import { getAuth, reauthenticateWithCredential, EmailAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/email-link-auth/auth_email_link_send.js b/snippets/auth-next/email-link-auth/auth_email_link_send.js index 8a3065c8..5b97d87f 100644 --- a/snippets/auth-next/email-link-auth/auth_email_link_send.js +++ b/snippets/auth-next/email-link-auth/auth_email_link_send.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/email-link-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_email_link_send_modular] import { getAuth, sendSignInLinkToEmail } from "firebase/auth"; diff --git a/snippets/auth-next/email-link-auth/email_link_complete.js b/snippets/auth-next/email-link-auth/email_link_complete.js index b0da2093..b42b9af9 100644 --- a/snippets/auth-next/email-link-auth/email_link_complete.js +++ b/snippets/auth-next/email-link-auth/email_link_complete.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/email-link-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START email_link_complete_modular] import { getAuth, isSignInWithEmailLink, signInWithEmailLink } from "firebase/auth"; diff --git a/snippets/auth-next/email-link-auth/email_link_diferentiate.js b/snippets/auth-next/email-link-auth/email_link_diferentiate.js index cbbe0e57..4fc06b41 100644 --- a/snippets/auth-next/email-link-auth/email_link_diferentiate.js +++ b/snippets/auth-next/email-link-auth/email_link_diferentiate.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/email-link-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START email_link_diferentiate_modular] import { getAuth, fetchSignInMethodsForEmail, EmailAuthProvider} from "firebase/auth"; diff --git a/snippets/auth-next/email/auth_send_email_verification.js b/snippets/auth-next/email/auth_send_email_verification.js index ef0c64b8..9290a421 100644 --- a/snippets/auth-next/email/auth_send_email_verification.js +++ b/snippets/auth-next/email/auth_send_email_verification.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/email.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_send_email_verification_modular] import { getAuth, sendEmailVerification } from "firebase/auth"; diff --git a/snippets/auth-next/email/auth_send_password_reset.js b/snippets/auth-next/email/auth_send_password_reset.js index 1b195344..e8e18a58 100644 --- a/snippets/auth-next/email/auth_send_password_reset.js +++ b/snippets/auth-next/email/auth_send_password_reset.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/email.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_send_password_reset_modular] import { getAuth, sendPasswordResetEmail } from "firebase/auth"; diff --git a/snippets/auth-next/email/auth_signin_password.js b/snippets/auth-next/email/auth_signin_password.js index 2652af74..f0a211d5 100644 --- a/snippets/auth-next/email/auth_signin_password.js +++ b/snippets/auth-next/email/auth_signin_password.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/email.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_signin_password_modular] import { getAuth, signInWithEmailAndPassword } from "firebase/auth"; diff --git a/snippets/auth-next/email/auth_signup_password.js b/snippets/auth-next/email/auth_signup_password.js index 679bfbb0..00aa9bd5 100644 --- a/snippets/auth-next/email/auth_signup_password.js +++ b/snippets/auth-next/email/auth_signup_password.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/email.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_signup_password_modular] import { getAuth, createUserWithEmailAndPassword } from "firebase/auth"; diff --git a/snippets/auth-next/emulator-suite/auth_emulator_connect.js b/snippets/auth-next/emulator-suite/auth_emulator_connect.js index 7e4cf680..dd0b2e37 100644 --- a/snippets/auth-next/emulator-suite/auth_emulator_connect.js +++ b/snippets/auth-next/emulator-suite/auth_emulator_connect.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/emulator-suite.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_emulator_connect_modular] import { getAuth, connectAuthEmulator } from "firebase/auth"; diff --git a/snippets/auth-next/facebook/auth_facebook_callback.js b/snippets/auth-next/facebook/auth_facebook_callback.js index 144928d8..8596bb68 100644 --- a/snippets/auth-next/facebook/auth_facebook_callback.js +++ b/snippets/auth-next/facebook/auth_facebook_callback.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/facebook.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_facebook_callback_modular] import { getAuth, onAuthStateChanged, signInWithCredential, signOut, FacebookAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/facebook/auth_facebook_checksameuser.js b/snippets/auth-next/facebook/auth_facebook_checksameuser.js index e4ed4845..0b1d170b 100644 --- a/snippets/auth-next/facebook/auth_facebook_checksameuser.js +++ b/snippets/auth-next/facebook/auth_facebook_checksameuser.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/facebook.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_facebook_checksameuser_modular] import { FacebookAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/facebook/auth_facebook_provider_create.js b/snippets/auth-next/facebook/auth_facebook_provider_create.js index 93913be7..403abcd2 100644 --- a/snippets/auth-next/facebook/auth_facebook_provider_create.js +++ b/snippets/auth-next/facebook/auth_facebook_provider_create.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/facebook.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_facebook_provider_create_modular] import { FacebookAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/facebook/auth_facebook_provider_params.js b/snippets/auth-next/facebook/auth_facebook_provider_params.js index 04c8532b..308fadd4 100644 --- a/snippets/auth-next/facebook/auth_facebook_provider_params.js +++ b/snippets/auth-next/facebook/auth_facebook_provider_params.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/facebook.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_facebook_provider_params_modular] provider.setCustomParameters({ diff --git a/snippets/auth-next/facebook/auth_facebook_provider_scopes.js b/snippets/auth-next/facebook/auth_facebook_provider_scopes.js index ba67a6f3..06386449 100644 --- a/snippets/auth-next/facebook/auth_facebook_provider_scopes.js +++ b/snippets/auth-next/facebook/auth_facebook_provider_scopes.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/facebook.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // / [START auth_facebook_provider_scopes_modular] provider.addScope('user_birthday'); diff --git a/snippets/auth-next/facebook/auth_facebook_signin_credential.js b/snippets/auth-next/facebook/auth_facebook_signin_credential.js index 84ce9612..dcd42c7e 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_credential.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_credential.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/facebook.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_facebook_signin_credential_modular] import { getAuth, signInWithCredential, FacebookAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/facebook/auth_facebook_signin_popup.js b/snippets/auth-next/facebook/auth_facebook_signin_popup.js index 164948a2..2bc014ed 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_popup.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/facebook.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_facebook_signin_popup_modular] import { getAuth, signInWithPopup, FacebookAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js b/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js index 9c2d5e30..49f3a494 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/facebook.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_facebook_signin_redirect_result_modular] import { getAuth, getRedirectResult, FacebookAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/github/auth_github_provider_create.js b/snippets/auth-next/github/auth_github_provider_create.js index eb5250d9..92cc4171 100644 --- a/snippets/auth-next/github/auth_github_provider_create.js +++ b/snippets/auth-next/github/auth_github_provider_create.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/github.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_github_provider_create_modular] import { GithubAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/github/auth_github_provider_credential.js b/snippets/auth-next/github/auth_github_provider_credential.js index ee159180..ca122a35 100644 --- a/snippets/auth-next/github/auth_github_provider_credential.js +++ b/snippets/auth-next/github/auth_github_provider_credential.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/github.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_github_provider_credential_modular] import { GithubAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/github/auth_github_provider_params.js b/snippets/auth-next/github/auth_github_provider_params.js index 159dcd8c..e2d4f341 100644 --- a/snippets/auth-next/github/auth_github_provider_params.js +++ b/snippets/auth-next/github/auth_github_provider_params.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/github.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_github_provider_params_modular] provider.setCustomParameters({ diff --git a/snippets/auth-next/github/auth_github_provider_scopes.js b/snippets/auth-next/github/auth_github_provider_scopes.js index 09f26298..b9237208 100644 --- a/snippets/auth-next/github/auth_github_provider_scopes.js +++ b/snippets/auth-next/github/auth_github_provider_scopes.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/github.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_github_provider_scopes_modular] provider.addScope('repo'); diff --git a/snippets/auth-next/github/auth_github_signin_popup.js b/snippets/auth-next/github/auth_github_signin_popup.js index 5b7a78b1..74e76cc9 100644 --- a/snippets/auth-next/github/auth_github_signin_popup.js +++ b/snippets/auth-next/github/auth_github_signin_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/github.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_github_signin_popup_modular] import { getAuth, signInWithPopup, GithubAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/github/auth_github_signin_redirect_result.js b/snippets/auth-next/github/auth_github_signin_redirect_result.js index 6884ed36..6147d9de 100644 --- a/snippets/auth-next/github/auth_github_signin_redirect_result.js +++ b/snippets/auth-next/github/auth_github_signin_redirect_result.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/github.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_github_signin_redirect_result_modular] import { getAuth, getRedirectResult, GithubAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/google-signin/auth_google_build_signin.js b/snippets/auth-next/google-signin/auth_google_build_signin.js index b6f4bbb9..6df84e3e 100644 --- a/snippets/auth-next/google-signin/auth_google_build_signin.js +++ b/snippets/auth-next/google-signin/auth_google_build_signin.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/google-signin.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_google_build_signin_modular] import { getAuth, signInWithCredential, GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/google-signin/auth_google_callback.js b/snippets/auth-next/google-signin/auth_google_callback.js index 2c23aa69..27aa8dc6 100644 --- a/snippets/auth-next/google-signin/auth_google_callback.js +++ b/snippets/auth-next/google-signin/auth_google_callback.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/google-signin.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_google_callback_modular] import { getAuth, onAuthStateChanged, signInWithCredential, GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/google-signin/auth_google_checksameuser.js b/snippets/auth-next/google-signin/auth_google_checksameuser.js index e2a7cad9..cc451991 100644 --- a/snippets/auth-next/google-signin/auth_google_checksameuser.js +++ b/snippets/auth-next/google-signin/auth_google_checksameuser.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/google-signin.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_google_checksameuser_modular] import { GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/google-signin/auth_google_provider_create.js b/snippets/auth-next/google-signin/auth_google_provider_create.js index 6d696d21..76b356d6 100644 --- a/snippets/auth-next/google-signin/auth_google_provider_create.js +++ b/snippets/auth-next/google-signin/auth_google_provider_create.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/google-signin.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_google_provider_create_modular] import { GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/google-signin/auth_google_provider_params.js b/snippets/auth-next/google-signin/auth_google_provider_params.js index 4799da72..25f1ea99 100644 --- a/snippets/auth-next/google-signin/auth_google_provider_params.js +++ b/snippets/auth-next/google-signin/auth_google_provider_params.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/google-signin.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_google_provider_params_modular] provider.setCustomParameters({ diff --git a/snippets/auth-next/google-signin/auth_google_provider_scopes.js b/snippets/auth-next/google-signin/auth_google_provider_scopes.js index f370a854..346b6432 100644 --- a/snippets/auth-next/google-signin/auth_google_provider_scopes.js +++ b/snippets/auth-next/google-signin/auth_google_provider_scopes.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/google-signin.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_google_provider_scopes_modular] provider.addScope('https://www.googleapis.com/auth/contacts.readonly'); diff --git a/snippets/auth-next/google-signin/auth_google_signin_credential.js b/snippets/auth-next/google-signin/auth_google_signin_credential.js index 6c8a5641..a3a8808e 100644 --- a/snippets/auth-next/google-signin/auth_google_signin_credential.js +++ b/snippets/auth-next/google-signin/auth_google_signin_credential.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/google-signin.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_google_signin_credential_modular] signInWithCredential(auth, credential).catch((error) => { diff --git a/snippets/auth-next/google-signin/auth_google_signin_popup.js b/snippets/auth-next/google-signin/auth_google_signin_popup.js index f74b800d..55c46488 100644 --- a/snippets/auth-next/google-signin/auth_google_signin_popup.js +++ b/snippets/auth-next/google-signin/auth_google_signin_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/google-signin.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_google_signin_popup_modular] import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js b/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js index 2e91c4c6..a64977bb 100644 --- a/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js +++ b/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/google-signin.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_google_signin_redirect_result_modular] import { getAuth, getRedirectResult, GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/index/auth_current_user.js b/snippets/auth-next/index/auth_current_user.js index 474f66bf..c094a464 100644 --- a/snippets/auth-next/index/auth_current_user.js +++ b/snippets/auth-next/index/auth_current_user.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_current_user_modular] import { getAuth } from "firebase/auth"; diff --git a/snippets/auth-next/index/auth_make_email_credential.js b/snippets/auth-next/index/auth_make_email_credential.js index 7009633b..6487fe62 100644 --- a/snippets/auth-next/index/auth_make_email_credential.js +++ b/snippets/auth-next/index/auth_make_email_credential.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_make_email_credential_modular] import { EmailAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/index/auth_make_facebook_credential.js b/snippets/auth-next/index/auth_make_facebook_credential.js index 7a68e3b7..91f5ae63 100644 --- a/snippets/auth-next/index/auth_make_facebook_credential.js +++ b/snippets/auth-next/index/auth_make_facebook_credential.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_make_facebook_credential_modular] import { FacebookAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/index/auth_make_google_credential.js b/snippets/auth-next/index/auth_make_google_credential.js index 007bb7eb..2640d101 100644 --- a/snippets/auth-next/index/auth_make_google_credential.js +++ b/snippets/auth-next/index/auth_make_google_credential.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_make_google_credential_modular] import { GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/index/auth_set_language_code.js b/snippets/auth-next/index/auth_set_language_code.js index 6d4126f9..47e78295 100644 --- a/snippets/auth-next/index/auth_set_language_code.js +++ b/snippets/auth-next/index/auth_set_language_code.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_set_language_code_modular] import { getAuth } from "firebase/auth"; diff --git a/snippets/auth-next/index/auth_sign_out.js b/snippets/auth-next/index/auth_sign_out.js index 7360528c..4cef4757 100644 --- a/snippets/auth-next/index/auth_sign_out.js +++ b/snippets/auth-next/index/auth_sign_out.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_sign_out_modular] import { getAuth, signOut } from "firebase/auth"; diff --git a/snippets/auth-next/index/auth_signin_credential.js b/snippets/auth-next/index/auth_signin_credential.js index eccad4e6..ba2db6b8 100644 --- a/snippets/auth-next/index/auth_signin_credential.js +++ b/snippets/auth-next/index/auth_signin_credential.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_signin_credential_modular] import { getAuth, signInWithCredential } from "firebase/auth"; diff --git a/snippets/auth-next/index/auth_signin_redirect.js b/snippets/auth-next/index/auth_signin_redirect.js index f5187cb3..49c95513 100644 --- a/snippets/auth-next/index/auth_signin_redirect.js +++ b/snippets/auth-next/index/auth_signin_redirect.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_signin_redirect_modular] import { getAuth, signInWithRedirect } from "firebase/auth"; diff --git a/snippets/auth-next/index/auth_state_listener.js b/snippets/auth-next/index/auth_state_listener.js index 4764642b..aebe6818 100644 --- a/snippets/auth-next/index/auth_state_listener.js +++ b/snippets/auth-next/index/auth_state_listener.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_state_listener_modular] import { getAuth, onAuthStateChanged } from "firebase/auth"; diff --git a/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js b/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js index fb3cc1a8..3bf9ab56 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js +++ b/snippets/auth-next/link-multiple-accounts/auth_anonymous_link.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/link-multiple-accounts.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_anonymous_link_modular] import { getAuth, linkWithCredential } from "firebase/auth"; diff --git a/snippets/auth-next/link-multiple-accounts/auth_get_providers.js b/snippets/auth-next/link-multiple-accounts/auth_get_providers.js index 2550bdd7..0f1ebbc1 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_get_providers.js +++ b/snippets/auth-next/link-multiple-accounts/auth_get_providers.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/link-multiple-accounts.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_get_providers_modular] import { GoogleAuthProvider, FacebookAuthProvider, TwitterAuthProvider, GithubAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/link-multiple-accounts/auth_get_redirect_result.js b/snippets/auth-next/link-multiple-accounts/auth_get_redirect_result.js index 2118d9ba..1608a933 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_get_redirect_result.js +++ b/snippets/auth-next/link-multiple-accounts/auth_get_redirect_result.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/link-multiple-accounts.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_get_redirect_result_modular] import { getRedirectResult } from "firebase/auth"; diff --git a/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js b/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js index b531cbc6..b6619cad 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js +++ b/snippets/auth-next/link-multiple-accounts/auth_link_with_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/link-multiple-accounts.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_link_with_popup_modular] import { getAuth, linkWithPopup, GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js b/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js index fc06ec47..1e496f42 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js +++ b/snippets/auth-next/link-multiple-accounts/auth_link_with_redirect.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/link-multiple-accounts.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_link_with_redirect_modular] import { getAuth, linkWithRedirect, GoogleAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/link-multiple-accounts/auth_make_email_credential.js b/snippets/auth-next/link-multiple-accounts/auth_make_email_credential.js index e78c54e1..861d77e8 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_make_email_credential.js +++ b/snippets/auth-next/link-multiple-accounts/auth_make_email_credential.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/link-multiple-accounts.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_make_email_credential_modular] import { EmailAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js b/snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js index 2525d20a..f7cc113c 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js +++ b/snippets/auth-next/link-multiple-accounts/auth_merge_accounts.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/link-multiple-accounts.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_merge_accounts_modular] import { getAuth, signInWithCredential, linkWithCredential, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/link-multiple-accounts/auth_simple_link.js b/snippets/auth-next/link-multiple-accounts/auth_simple_link.js index ca360976..15c434a2 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_simple_link.js +++ b/snippets/auth-next/link-multiple-accounts/auth_simple_link.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/link-multiple-accounts.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_simple_link_modular] import { getAuth, linkWithCredential } from "firebase/auth"; diff --git a/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js b/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js index 7818cb06..46617b26 100644 --- a/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js +++ b/snippets/auth-next/link-multiple-accounts/auth_unlink_provider.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/link-multiple-accounts.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_unlink_provider_modular] import { getAuth, unlink } from "firebase/auth"; diff --git a/snippets/auth-next/manage/auth_delete_user.js b/snippets/auth-next/manage/auth_delete_user.js index 8d725aa4..389a0852 100644 --- a/snippets/auth-next/manage/auth_delete_user.js +++ b/snippets/auth-next/manage/auth_delete_user.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/manage.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_delete_user_modular] import { getAuth, deleteUser } from "firebase/auth"; diff --git a/snippets/auth-next/manage/auth_get_user_profile.js b/snippets/auth-next/manage/auth_get_user_profile.js index 106104e8..9dce7fdc 100644 --- a/snippets/auth-next/manage/auth_get_user_profile.js +++ b/snippets/auth-next/manage/auth_get_user_profile.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/manage.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_get_user_profile_modular] import { getAuth } from "firebase/auth"; diff --git a/snippets/auth-next/manage/auth_get_user_profile_provider.js b/snippets/auth-next/manage/auth_get_user_profile_provider.js index 63e9654f..1d165d49 100644 --- a/snippets/auth-next/manage/auth_get_user_profile_provider.js +++ b/snippets/auth-next/manage/auth_get_user_profile_provider.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/manage.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_get_user_profile_provider_modular] import { getAuth } from "firebase/auth"; diff --git a/snippets/auth-next/manage/auth_reauth_with_credential.js b/snippets/auth-next/manage/auth_reauth_with_credential.js index 0b02de6c..74e84732 100644 --- a/snippets/auth-next/manage/auth_reauth_with_credential.js +++ b/snippets/auth-next/manage/auth_reauth_with_credential.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/manage.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_reauth_with_credential_modular] import { getAuth, reauthenticateWithCredential } from "firebase/auth"; diff --git a/snippets/auth-next/manage/auth_send_password_reset.js b/snippets/auth-next/manage/auth_send_password_reset.js index fa6118bb..9e8f2c3c 100644 --- a/snippets/auth-next/manage/auth_send_password_reset.js +++ b/snippets/auth-next/manage/auth_send_password_reset.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/manage.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_send_password_reset_modular] import { getAuth, sendPasswordResetEmail } from "firebase/auth"; diff --git a/snippets/auth-next/manage/auth_update_password.js b/snippets/auth-next/manage/auth_update_password.js index 69543928..56e578b9 100644 --- a/snippets/auth-next/manage/auth_update_password.js +++ b/snippets/auth-next/manage/auth_update_password.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/manage.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_update_password_modular] import { getAuth, updatePassword } from "firebase/auth"; diff --git a/snippets/auth-next/manage/auth_update_user_email.js b/snippets/auth-next/manage/auth_update_user_email.js index 8e313ece..d3607f75 100644 --- a/snippets/auth-next/manage/auth_update_user_email.js +++ b/snippets/auth-next/manage/auth_update_user_email.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/manage.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_update_user_email_modular] import { getAuth, updateEmail } from "firebase/auth"; diff --git a/snippets/auth-next/manage/auth_update_user_profile.js b/snippets/auth-next/manage/auth_update_user_profile.js index 9449474e..2af9185a 100644 --- a/snippets/auth-next/manage/auth_update_user_profile.js +++ b/snippets/auth-next/manage/auth_update_user_profile.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/manage.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_update_user_profile_modular] import { getAuth, updateProfile } from "firebase/auth"; diff --git a/snippets/auth-next/manage/send_email_verification.js b/snippets/auth-next/manage/send_email_verification.js index 82b0dcf9..34f06fdb 100644 --- a/snippets/auth-next/manage/send_email_verification.js +++ b/snippets/auth-next/manage/send_email_verification.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/manage.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START send_email_verification_modular] import { getAuth, sendEmailVerification } from "firebase/auth"; diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_create_provider.js b/snippets/auth-next/microsoft-oauth/auth_msft_create_provider.js index bbde8267..c0a9039c 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_create_provider.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_create_provider.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/microsoft-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_msft_create_provider_modular] import { OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js b/snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js index 8e4da503..1a029c7e 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_link_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/microsoft-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_msft_link_popup_modular] import { getAuth, linkWithPopup, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_provider_params.js b/snippets/auth-next/microsoft-oauth/auth_msft_provider_params.js index dea75ee7..007ae646 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_provider_params.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_provider_params.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/microsoft-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_msft_provider_params_modular] provider.setCustomParameters({ diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_provider_params_tenant.js b/snippets/auth-next/microsoft-oauth/auth_msft_provider_params_tenant.js index 82abfe9b..341ff1f1 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_provider_params_tenant.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_provider_params_tenant.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/microsoft-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_msft_provider_params_tenant_modular] provider.setCustomParameters({ diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_provider_scopes.js b/snippets/auth-next/microsoft-oauth/auth_msft_provider_scopes.js index 6c4d2fed..ad86ac6e 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_provider_scopes.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_provider_scopes.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/microsoft-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_msft_provider_scopes_modular] provider.addScope('mail.read'); diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js b/snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js index b257ec88..1d222fba 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_reauth_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/microsoft-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_msft_reauth_popup_modular] import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js b/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js index 2b1fffa9..a19e598d 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_signin_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/microsoft-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_msft_signin_popup_modular] import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js index 7e04a832..c020dcf5 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/microsoft-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_msft_signin_redirect_modular] import { getAuth, signInWithRedirect } from "firebase/auth"; diff --git a/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js index 3992a4d1..e1249de1 100644 --- a/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js +++ b/snippets/auth-next/microsoft-oauth/auth_msft_signin_redirect_result.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/microsoft-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_msft_signin_redirect_result_modular] import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/phone-auth/auth_get_recaptcha_response.js b/snippets/auth-next/phone-auth/auth_get_recaptcha_response.js index 83a31ed1..f19a93e6 100644 --- a/snippets/auth-next/phone-auth/auth_get_recaptcha_response.js +++ b/snippets/auth-next/phone-auth/auth_get_recaptcha_response.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/phone-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_get_recaptcha_response_modular] const recaptchaResponse = grecaptcha.getResponse(recaptchaWidgetId); diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_render.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_render.js index 0bbceb0d..27e9d8c9 100644 --- a/snippets/auth-next/phone-auth/auth_phone_recaptcha_render.js +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_render.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/phone-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_phone_recaptcha_render_modular] recaptchaVerifier.render().then((widgetId) => { diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js index 2ee43e7c..f6b6893f 100644 --- a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/phone-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_phone_recaptcha_verifier_invisible_modular] import { getAuth, RecaptchaVerifier } from "firebase/auth"; diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js index 5a318bce..ed56fe99 100644 --- a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/phone-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_phone_recaptcha_verifier_simple_modular] import { getAuth, RecaptchaVerifier } from "firebase/auth"; diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js index 4b987ee7..c91e6041 100644 --- a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/phone-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_phone_recaptcha_verifier_visible_modular] import { getAuth, RecaptchaVerifier } from "firebase/auth"; diff --git a/snippets/auth-next/phone-auth/auth_phone_signin.js b/snippets/auth-next/phone-auth/auth_phone_signin.js index a7a3f0af..31c3d248 100644 --- a/snippets/auth-next/phone-auth/auth_phone_signin.js +++ b/snippets/auth-next/phone-auth/auth_phone_signin.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/phone-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_phone_signin_modular] import { getAuth, signInWithPhoneNumber } from "firebase/auth"; diff --git a/snippets/auth-next/phone-auth/auth_phone_verify_code.js b/snippets/auth-next/phone-auth/auth_phone_verify_code.js index 51265141..299f8cf3 100644 --- a/snippets/auth-next/phone-auth/auth_phone_verify_code.js +++ b/snippets/auth-next/phone-auth/auth_phone_verify_code.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/phone-auth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_phone_verify_code_modular] const code = getCodeFromUserInput(); diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js b/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js index e3a61d07..dd78ada8 100644 --- a/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js +++ b/snippets/auth-next/service-worker-sessions/auth_svc_get_idtoken.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/service-worker-sessions.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_svc_get_idtoken_modular] import { getAuth, getIdToken } from "firebase/auth"; diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_intercept.js b/snippets/auth-next/service-worker-sessions/auth_svc_intercept.js index b14ccbed..419614ff 100644 --- a/snippets/auth-next/service-worker-sessions/auth_svc_intercept.js +++ b/snippets/auth-next/service-worker-sessions/auth_svc_intercept.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/service-worker-sessions.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_svc_intercept_modular] const getOriginFromUrl = (url) => { diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js b/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js index a51cfedb..0337fc83 100644 --- a/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js +++ b/snippets/auth-next/service-worker-sessions/auth_svc_listen_activate.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/service-worker-sessions.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_svc_listen_activate_modular] self.addEventListener('activate', (event) => { diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_register.js b/snippets/auth-next/service-worker-sessions/auth_svc_register.js index 1b0b19c1..0cb36be3 100644 --- a/snippets/auth-next/service-worker-sessions/auth_svc_register.js +++ b/snippets/auth-next/service-worker-sessions/auth_svc_register.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/service-worker-sessions.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_svc_register_modular] // Install servicerWorker if supported on sign-in/sign-up page. diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js b/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js index a7d6e30b..02e3a62a 100644 --- a/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js +++ b/snippets/auth-next/service-worker-sessions/auth_svc_sign_in_email.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/service-worker-sessions.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_svc_sign_in_email_modular] import { getAuth, signInWithEmailAndPassword } from "firebase/auth"; diff --git a/snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js b/snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js index a3bb5c2a..76448570 100644 --- a/snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js +++ b/snippets/auth-next/service-worker-sessions/auth_svc_subscribe.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/service-worker-sessions.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_svc_subscribe_modular] import { initializeApp } from "firebase/app"; diff --git a/snippets/auth-next/twitter/auth_twitter_provider_create.js b/snippets/auth-next/twitter/auth_twitter_provider_create.js index 496ae5f5..7fb82507 100644 --- a/snippets/auth-next/twitter/auth_twitter_provider_create.js +++ b/snippets/auth-next/twitter/auth_twitter_provider_create.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/twitter.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_twitter_provider_create_modular] import { TwitterAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/twitter/auth_twitter_provider_params.js b/snippets/auth-next/twitter/auth_twitter_provider_params.js index cb7c7a39..14d457f0 100644 --- a/snippets/auth-next/twitter/auth_twitter_provider_params.js +++ b/snippets/auth-next/twitter/auth_twitter_provider_params.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/twitter.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_twitter_provider_params_modular] provider.setCustomParameters({ diff --git a/snippets/auth-next/twitter/auth_twitter_signin_popup.js b/snippets/auth-next/twitter/auth_twitter_signin_popup.js index be2b7f57..a5fb5a95 100644 --- a/snippets/auth-next/twitter/auth_twitter_signin_popup.js +++ b/snippets/auth-next/twitter/auth_twitter_signin_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/twitter.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_twitter_signin_popup_modular] import { getAuth, signInWithPopup, TwitterAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js b/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js index cfecf9cc..53b42c85 100644 --- a/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js +++ b/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/twitter.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_twitter_signin_redirect_result_modular] import { getAuth, getRedirectResult, TwitterAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js index 8f672f6b..1a921bce 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_link_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/yahoo-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_yahoo_link_popup_modular] import { getAuth, linkWithPopup, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_create.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_create.js index c30a64f0..c26cd5fd 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_create.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_create.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/yahoo-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_yahoo_provider_create_modular] import { OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_params.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_params.js index 7bd28592..f8d918f9 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_params.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_params.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/yahoo-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_yahoo_provider_params_modular] provider.setCustomParameters({ diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_scopes.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_scopes.js index 24e059c8..8a02ff7b 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_scopes.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_provider_scopes.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/yahoo-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_yahoo_provider_scopes_modular] // Request access to Yahoo Mail API. diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js index b35e162d..57243f05 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_reauth_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/yahoo-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_yahoo_reauth_popup_modular] import { getAuth, reauthenticateWithPopup, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js index 8c8c2713..91c04abc 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_popup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/yahoo-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_yahoo_signin_popup_modular] import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth"; diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js index 5acb5687..f16cac73 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/yahoo-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_yahoo_signin_redirect_modular] import { getAuth, signInWithRedirect } from "firebase/auth"; diff --git a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js index 73f69951..61709b2c 100644 --- a/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js +++ b/snippets/auth-next/yahoo-oauth/auth_yahoo_signin_redirect_result.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./auth-next/yahoo-oauth.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START auth_yahoo_signin_redirect_result_modular] import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; diff --git a/snippets/database-next/emulator-suite/rtdb_emulator_connect.js b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js index 709fc10b..4cc268e7 100644 --- a/snippets/database-next/emulator-suite/rtdb_emulator_connect.js +++ b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/emulator-suite.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_emulator_connect_modular] import { getDatabase, connectDatabaseEmulator } from "firebase/database"; diff --git a/snippets/database-next/emulator-suite/rtdb_emulator_flush.js b/snippets/database-next/emulator-suite/rtdb_emulator_flush.js index 0476a256..3e17ef9a 100644 --- a/snippets/database-next/emulator-suite/rtdb_emulator_flush.js +++ b/snippets/database-next/emulator-suite/rtdb_emulator_flush.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/emulator-suite.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_emulator_flush_modular] import { getDatabase, ref, set } from "firebase/database"; diff --git a/snippets/database-next/index/rtdb_get_reference.js b/snippets/database-next/index/rtdb_get_reference.js index fe16c855..ee87937e 100644 --- a/snippets/database-next/index/rtdb_get_reference.js +++ b/snippets/database-next/index/rtdb_get_reference.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_get_reference_modular] import { getDatabase } from "firebase/database"; diff --git a/snippets/database-next/lists-of-data/rtdb_social_listen_children.js b/snippets/database-next/lists-of-data/rtdb_social_listen_children.js index 644c0334..78f90ff2 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_listen_children.js +++ b/snippets/database-next/lists-of-data/rtdb_social_listen_children.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/lists-of-data.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_listen_children_modular] import { getDatabase, ref, onChildAdded, onChildChanged, onChildRemoved } from "firebase/database"; diff --git a/snippets/database-next/lists-of-data/rtdb_social_listen_value.js b/snippets/database-next/lists-of-data/rtdb_social_listen_value.js index 938308ad..d234eeea 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_listen_value.js +++ b/snippets/database-next/lists-of-data/rtdb_social_listen_value.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/lists-of-data.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_listen_value_modular] import { getDatabase, ref, onValue } from "firebase/database"; diff --git a/snippets/database-next/lists-of-data/rtdb_social_most_starred.js b/snippets/database-next/lists-of-data/rtdb_social_most_starred.js index 5c364682..63237fdf 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_most_starred.js +++ b/snippets/database-next/lists-of-data/rtdb_social_most_starred.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/lists-of-data.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_most_starred_modular] import { getDatabase, ref, query, orderByChild } from "firebase/database"; diff --git a/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js b/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js index 784df41e..1ebe7edc 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js +++ b/snippets/database-next/lists-of-data/rtdb_social_most_viewed.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/lists-of-data.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_most_viewed_modular] import { getDatabase, ref, query, orderByChild } from "firebase/database"; diff --git a/snippets/database-next/lists-of-data/rtdb_social_push.js b/snippets/database-next/lists-of-data/rtdb_social_push.js index c62c0a0a..ec366352 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_push.js +++ b/snippets/database-next/lists-of-data/rtdb_social_push.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/lists-of-data.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_push_modular] import { getDatabase, ref, push, set } from "firebase/database"; diff --git a/snippets/database-next/lists-of-data/rtdb_social_recent.js b/snippets/database-next/lists-of-data/rtdb_social_recent.js index 0f26c486..8b35d6e6 100644 --- a/snippets/database-next/lists-of-data/rtdb_social_recent.js +++ b/snippets/database-next/lists-of-data/rtdb_social_recent.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/lists-of-data.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_recent_modular] import { getDatabase, ref, query, limitToLast } from "firebase/database"; diff --git a/snippets/database-next/offline/rtdb_detect_connection_state.js b/snippets/database-next/offline/rtdb_detect_connection_state.js index e37375d2..313af6ee 100644 --- a/snippets/database-next/offline/rtdb_detect_connection_state.js +++ b/snippets/database-next/offline/rtdb_detect_connection_state.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/offline.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_detect_connection_state_modular] import { getDatabase, ref, onValue } from "firebase/database"; diff --git a/snippets/database-next/offline/rtdb_estimate_clock_skew.js b/snippets/database-next/offline/rtdb_estimate_clock_skew.js index 9e4b6f5d..e1a92581 100644 --- a/snippets/database-next/offline/rtdb_estimate_clock_skew.js +++ b/snippets/database-next/offline/rtdb_estimate_clock_skew.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/offline.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_estimate_clock_skew_modular] import { getDatabase, ref, onValue } from "firebase/database"; diff --git a/snippets/database-next/offline/rtdb_ondisconnect_callback.js b/snippets/database-next/offline/rtdb_ondisconnect_callback.js index 6b7f2950..16071828 100644 --- a/snippets/database-next/offline/rtdb_ondisconnect_callback.js +++ b/snippets/database-next/offline/rtdb_ondisconnect_callback.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/offline.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_ondisconnect_callback_modular] onDisconnect(presenceRef).remove().catch((err) => { diff --git a/snippets/database-next/offline/rtdb_ondisconnect_cancel.js b/snippets/database-next/offline/rtdb_ondisconnect_cancel.js index f5c3c972..f18cab8e 100644 --- a/snippets/database-next/offline/rtdb_ondisconnect_cancel.js +++ b/snippets/database-next/offline/rtdb_ondisconnect_cancel.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/offline.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_ondisconnect_cancel_modular] const onDisconnectRef = onDisconnect(presenceRef); diff --git a/snippets/database-next/offline/rtdb_ondisconnect_simple.js b/snippets/database-next/offline/rtdb_ondisconnect_simple.js index da1fdf4f..340e3fe5 100644 --- a/snippets/database-next/offline/rtdb_ondisconnect_simple.js +++ b/snippets/database-next/offline/rtdb_ondisconnect_simple.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/offline.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_ondisconnect_simple_modular] import { getDatabase, ref, onDisconnect } from "firebase/database"; diff --git a/snippets/database-next/offline/rtdb_sample_presence_app.js b/snippets/database-next/offline/rtdb_sample_presence_app.js index 504f396f..394e64e6 100644 --- a/snippets/database-next/offline/rtdb_sample_presence_app.js +++ b/snippets/database-next/offline/rtdb_sample_presence_app.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/offline.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_sample_presence_app_modular] import { getDatabase, ref, onValue, push, onDisconnect, set, serverTimestamp } from "firebase/database"; diff --git a/snippets/database-next/offline/rtdb_set_server_timestamp.js b/snippets/database-next/offline/rtdb_set_server_timestamp.js index 4a1a219b..8a9d2e8a 100644 --- a/snippets/database-next/offline/rtdb_set_server_timestamp.js +++ b/snippets/database-next/offline/rtdb_set_server_timestamp.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/offline.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_set_server_timestamp_modular] import { getDatabase, ref, onDisconnect, serverTimestamp } from "firebase/database"; diff --git a/snippets/database-next/read-and-write/rtdb_read_once_get.js b/snippets/database-next/read-and-write/rtdb_read_once_get.js index ec618da0..a0cf77a5 100644 --- a/snippets/database-next/read-and-write/rtdb_read_once_get.js +++ b/snippets/database-next/read-and-write/rtdb_read_once_get.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/read-and-write.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_read_once_get_modular] import { getDatabase, ref, child, get } from "firebase/database"; diff --git a/snippets/database-next/read-and-write/rtdb_social_completion_callback.js b/snippets/database-next/read-and-write/rtdb_social_completion_callback.js index 483dd962..b1ab42a1 100644 --- a/snippets/database-next/read-and-write/rtdb_social_completion_callback.js +++ b/snippets/database-next/read-and-write/rtdb_social_completion_callback.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/read-and-write.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_completion_callback_modular] import { getDatabase, ref, set } from "firebase/database"; diff --git a/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js b/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js index 3f7f498b..ab520ce6 100644 --- a/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js +++ b/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/read-and-write.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_listen_star_count_modular] import { getDatabase, ref, onValue} from "firebase/database"; diff --git a/snippets/database-next/read-and-write/rtdb_social_single_value_read.js b/snippets/database-next/read-and-write/rtdb_social_single_value_read.js index 276bdfd3..3debb5e5 100644 --- a/snippets/database-next/read-and-write/rtdb_social_single_value_read.js +++ b/snippets/database-next/read-and-write/rtdb_social_single_value_read.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/read-and-write.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_single_value_read_modular] import { getDatabase, ref, onValue } from "firebase/database"; diff --git a/snippets/database-next/read-and-write/rtdb_social_star_increment.js b/snippets/database-next/read-and-write/rtdb_social_star_increment.js index bb4f9d7e..dce5e8a9 100644 --- a/snippets/database-next/read-and-write/rtdb_social_star_increment.js +++ b/snippets/database-next/read-and-write/rtdb_social_star_increment.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/read-and-write.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_star_increment_modular] function addStar(uid, key) { diff --git a/snippets/database-next/read-and-write/rtdb_social_star_transaction.js b/snippets/database-next/read-and-write/rtdb_social_star_transaction.js index af817f0c..bf837c92 100644 --- a/snippets/database-next/read-and-write/rtdb_social_star_transaction.js +++ b/snippets/database-next/read-and-write/rtdb_social_star_transaction.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/read-and-write.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_star_transaction_modular] import { getDatabase, ref, runTransaction } from "firebase/database"; diff --git a/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js b/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js index a87824e9..f787d4bd 100644 --- a/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js +++ b/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/read-and-write.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_social_write_fan_out_modular] function writeNewPost(uid, username, picture, title, body) { diff --git a/snippets/database-next/read-and-write/rtdb_write_new_user.js b/snippets/database-next/read-and-write/rtdb_write_new_user.js index 85ecc9f4..eef24086 100644 --- a/snippets/database-next/read-and-write/rtdb_write_new_user.js +++ b/snippets/database-next/read-and-write/rtdb_write_new_user.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/read-and-write.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_write_new_user_modular] import { getDatabase, ref, set } from "firebase/database"; diff --git a/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js b/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js index b6e0dacb..8bb5878e 100644 --- a/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js +++ b/snippets/database-next/read-and-write/rtdb_write_new_user_completion.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/read-and-write.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_write_new_user_completion_modular] import { getDatabase, ref, set } from "firebase/database"; diff --git a/snippets/database-next/sharding/rtdb_multiple_instances.js b/snippets/database-next/sharding/rtdb_multiple_instances.js index cd40b918..fe66cbc8 100644 --- a/snippets/database-next/sharding/rtdb_multiple_instances.js +++ b/snippets/database-next/sharding/rtdb_multiple_instances.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./database-next/sharding.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rtdb_multiple_instances_modular] import { initializeApp } from "firebase/app"; diff --git a/snippets/firebaseapp-next/firebaseapp/firebase_options.js b/snippets/firebaseapp-next/firebaseapp/firebase_options.js index 76a420e9..f951d4d7 100644 --- a/snippets/firebaseapp-next/firebaseapp/firebase_options.js +++ b/snippets/firebaseapp-next/firebaseapp/firebase_options.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firebaseapp-next/firebaseapp.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START firebase_options_modular] import { initializeApp } from "firebase/app"; diff --git a/snippets/firebaseapp-next/firebaseapp/firebase_secondary.js b/snippets/firebaseapp-next/firebaseapp/firebase_secondary.js index c78f2b3f..2dd04f0f 100644 --- a/snippets/firebaseapp-next/firebaseapp/firebase_secondary.js +++ b/snippets/firebaseapp-next/firebaseapp/firebase_secondary.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firebaseapp-next/firebaseapp.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START firebase_secondary_modular] // Initialize another app with a different config diff --git a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js index 3754a2df..7e31fcfd 100644 --- a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js +++ b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/emulator-suite.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fs_emulator_connect_modular] import { getFirestore, connectFirestoreEmulator } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/add_ada_lovelace.js b/snippets/firestore-next/test-firestore/add_ada_lovelace.js index 7e9a0516..ae9e168a 100644 --- a/snippets/firestore-next/test-firestore/add_ada_lovelace.js +++ b/snippets/firestore-next/test-firestore/add_ada_lovelace.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START add_ada_lovelace_modular] import { collection, addDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/add_alan_turing.js b/snippets/firestore-next/test-firestore/add_alan_turing.js index 6ea96265..0c7abaaf 100644 --- a/snippets/firestore-next/test-firestore/add_alan_turing.js +++ b/snippets/firestore-next/test-firestore/add_alan_turing.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START add_alan_turing_modular] // Add a second document with a generated ID. diff --git a/snippets/firestore-next/test-firestore/add_document.js b/snippets/firestore-next/test-firestore/add_document.js index 2ecb5c36..ddfea007 100644 --- a/snippets/firestore-next/test-firestore/add_document.js +++ b/snippets/firestore-next/test-firestore/add_document.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START add_document_modular] import { collection, addDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/add_rating_transaction.js b/snippets/firestore-next/test-firestore/add_rating_transaction.js index e5c279a9..7d698806 100644 --- a/snippets/firestore-next/test-firestore/add_rating_transaction.js +++ b/snippets/firestore-next/test-firestore/add_rating_transaction.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START add_rating_transaction_modular] import { collection, doc, runTransaction } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/array_contains_any_filter.js b/snippets/firestore-next/test-firestore/array_contains_any_filter.js index 72c550f8..3ee6e4d9 100644 --- a/snippets/firestore-next/test-firestore/array_contains_any_filter.js +++ b/snippets/firestore-next/test-firestore/array_contains_any_filter.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START array_contains_any_filter_modular] import { query, where } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/array_contains_filter.js b/snippets/firestore-next/test-firestore/array_contains_filter.js index 9a9fcdb3..4576a193 100644 --- a/snippets/firestore-next/test-firestore/array_contains_filter.js +++ b/snippets/firestore-next/test-firestore/array_contains_filter.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START array_contains_filter_modular] import { query, where } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/chain_filters.js b/snippets/firestore-next/test-firestore/chain_filters.js index b13640b4..cbf3322f 100644 --- a/snippets/firestore-next/test-firestore/chain_filters.js +++ b/snippets/firestore-next/test-firestore/chain_filters.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START chain_filters_modular] import { query, where } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/cities_document_set.js b/snippets/firestore-next/test-firestore/cities_document_set.js index 793c4a8e..4b85b25d 100644 --- a/snippets/firestore-next/test-firestore/cities_document_set.js +++ b/snippets/firestore-next/test-firestore/cities_document_set.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START cities_document_set_modular] import { doc, setDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/city_custom_object.js b/snippets/firestore-next/test-firestore/city_custom_object.js index 2b9f2c02..c8e4b80c 100644 --- a/snippets/firestore-next/test-firestore/city_custom_object.js +++ b/snippets/firestore-next/test-firestore/city_custom_object.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START city_custom_object_modular] class City { diff --git a/snippets/firestore-next/test-firestore/collection_reference.js b/snippets/firestore-next/test-firestore/collection_reference.js index 2b43362d..d69f17e4 100644 --- a/snippets/firestore-next/test-firestore/collection_reference.js +++ b/snippets/firestore-next/test-firestore/collection_reference.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START collection_reference_modular] import { collection } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/data_types.js b/snippets/firestore-next/test-firestore/data_types.js index 9aa46b2b..9218ae6b 100644 --- a/snippets/firestore-next/test-firestore/data_types.js +++ b/snippets/firestore-next/test-firestore/data_types.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START data_types_modular] import { doc, setDoc, Timestamp } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/delete_collection.js b/snippets/firestore-next/test-firestore/delete_collection.js index 758e653e..4adef6f8 100644 --- a/snippets/firestore-next/test-firestore/delete_collection.js +++ b/snippets/firestore-next/test-firestore/delete_collection.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START delete_collection_modular] /** diff --git a/snippets/firestore-next/test-firestore/delete_document.js b/snippets/firestore-next/test-firestore/delete_document.js index 0933d311..b00ae490 100644 --- a/snippets/firestore-next/test-firestore/delete_document.js +++ b/snippets/firestore-next/test-firestore/delete_document.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START delete_document_modular] import { doc, deleteDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/detach_listener.js b/snippets/firestore-next/test-firestore/detach_listener.js index 24848db2..cd921018 100644 --- a/snippets/firestore-next/test-firestore/detach_listener.js +++ b/snippets/firestore-next/test-firestore/detach_listener.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START detach_listener_modular] import { collection, onSnapshot } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/disable_network.js b/snippets/firestore-next/test-firestore/disable_network.js index 095e6090..efa1fc27 100644 --- a/snippets/firestore-next/test-firestore/disable_network.js +++ b/snippets/firestore-next/test-firestore/disable_network.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START disable_network_modular] import { disableNetwork } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/doc_reference.js b/snippets/firestore-next/test-firestore/doc_reference.js index 10b96445..c5380539 100644 --- a/snippets/firestore-next/test-firestore/doc_reference.js +++ b/snippets/firestore-next/test-firestore/doc_reference.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START doc_reference_modular] import { doc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/doc_reference_alternative.js b/snippets/firestore-next/test-firestore/doc_reference_alternative.js index 8b60f4de..c88294a9 100644 --- a/snippets/firestore-next/test-firestore/doc_reference_alternative.js +++ b/snippets/firestore-next/test-firestore/doc_reference_alternative.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START doc_reference_alternative_modular] import { doc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/enable_network.js b/snippets/firestore-next/test-firestore/enable_network.js index e6d59889..2df9171b 100644 --- a/snippets/firestore-next/test-firestore/enable_network.js +++ b/snippets/firestore-next/test-firestore/enable_network.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START enable_network_modular] import { enableNetwork } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/example_data.js b/snippets/firestore-next/test-firestore/example_data.js index 52204078..cb7e92aa 100644 --- a/snippets/firestore-next/test-firestore/example_data.js +++ b/snippets/firestore-next/test-firestore/example_data.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START example_data_modular] import { collection, doc, setDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/example_filters.js b/snippets/firestore-next/test-firestore/example_filters.js index b5f58a5c..b481e5a8 100644 --- a/snippets/firestore-next/test-firestore/example_filters.js +++ b/snippets/firestore-next/test-firestore/example_filters.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START example_filters_modular] const stateQuery = query(citiesRef, where("state", "==", "CA")); diff --git a/snippets/firestore-next/test-firestore/filter_and_order.js b/snippets/firestore-next/test-firestore/filter_and_order.js index 13e31c0a..b8c03705 100644 --- a/snippets/firestore-next/test-firestore/filter_and_order.js +++ b/snippets/firestore-next/test-firestore/filter_and_order.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START filter_and_order_modular] import { query, where, orderBy, limit } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/fs_collection_group_query.js b/snippets/firestore-next/test-firestore/fs_collection_group_query.js index 96a2d735..3468017b 100644 --- a/snippets/firestore-next/test-firestore/fs_collection_group_query.js +++ b/snippets/firestore-next/test-firestore/fs_collection_group_query.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fs_collection_group_query_modular] import { collectionGroup, query, where, getDocs } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js b/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js index a4e07952..f4f62178 100644 --- a/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js +++ b/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fs_collection_group_query_data_setup_modular] import { collection, doc, setDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/fs_setup_cache.js b/snippets/firestore-next/test-firestore/fs_setup_cache.js index 3085eb65..8429da4c 100644 --- a/snippets/firestore-next/test-firestore/fs_setup_cache.js +++ b/snippets/firestore-next/test-firestore/fs_setup_cache.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fs_setup_cache_modular] import { initializeFirestore, CACHE_SIZE_UNLIMITED } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/get_all_users.js b/snippets/firestore-next/test-firestore/get_all_users.js index c8c86b5d..59dd760a 100644 --- a/snippets/firestore-next/test-firestore/get_all_users.js +++ b/snippets/firestore-next/test-firestore/get_all_users.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START get_all_users_modular] import { collection, getDocs } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/get_custom_object.js b/snippets/firestore-next/test-firestore/get_custom_object.js index 3e39eafa..e20a6839 100644 --- a/snippets/firestore-next/test-firestore/get_custom_object.js +++ b/snippets/firestore-next/test-firestore/get_custom_object.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START get_custom_object_modular] import { doc, getDoc} from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/get_document.js b/snippets/firestore-next/test-firestore/get_document.js index 1ca4787d..4cfbaaf6 100644 --- a/snippets/firestore-next/test-firestore/get_document.js +++ b/snippets/firestore-next/test-firestore/get_document.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START get_document_modular] import { doc, getDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/get_document_options.js b/snippets/firestore-next/test-firestore/get_document_options.js index 8b161b27..3a708a0d 100644 --- a/snippets/firestore-next/test-firestore/get_document_options.js +++ b/snippets/firestore-next/test-firestore/get_document_options.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START get_document_options_modular] import { doc, getDocFromCache } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/get_multiple.js b/snippets/firestore-next/test-firestore/get_multiple.js index 9b1616c2..59f8f9c3 100644 --- a/snippets/firestore-next/test-firestore/get_multiple.js +++ b/snippets/firestore-next/test-firestore/get_multiple.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START get_multiple_modular] import { collection, query, where, getDocs } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/get_multiple_all.js b/snippets/firestore-next/test-firestore/get_multiple_all.js index c61ec1ad..721f222e 100644 --- a/snippets/firestore-next/test-firestore/get_multiple_all.js +++ b/snippets/firestore-next/test-firestore/get_multiple_all.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START get_multiple_all_modular] import { collection, getDocs } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/handle_listen_errors.js b/snippets/firestore-next/test-firestore/handle_listen_errors.js index bb59c7d5..c330b67b 100644 --- a/snippets/firestore-next/test-firestore/handle_listen_errors.js +++ b/snippets/firestore-next/test-firestore/handle_listen_errors.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START handle_listen_errors_modular] import { collection, onSnapshot } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/in_filter.js b/snippets/firestore-next/test-firestore/in_filter.js index 55f0a0a7..4a041397 100644 --- a/snippets/firestore-next/test-firestore/in_filter.js +++ b/snippets/firestore-next/test-firestore/in_filter.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START in_filter_modular] import { query, where } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/in_filter_with_array.js b/snippets/firestore-next/test-firestore/in_filter_with_array.js index 722b11aa..ebe6f18b 100644 --- a/snippets/firestore-next/test-firestore/in_filter_with_array.js +++ b/snippets/firestore-next/test-firestore/in_filter_with_array.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START in_filter_with_array_modular] import { query, where } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/initialize_persistence.js b/snippets/firestore-next/test-firestore/initialize_persistence.js index 97936466..acd5e988 100644 --- a/snippets/firestore-next/test-firestore/initialize_persistence.js +++ b/snippets/firestore-next/test-firestore/initialize_persistence.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START initialize_persistence_modular] import { enableIndexedDbPersistence } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/invalid_filter_and_order.js b/snippets/firestore-next/test-firestore/invalid_filter_and_order.js index 5d8e73e6..708c9cd1 100644 --- a/snippets/firestore-next/test-firestore/invalid_filter_and_order.js +++ b/snippets/firestore-next/test-firestore/invalid_filter_and_order.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START invalid_filter_and_order_modular] import { query, where, orderBy } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/invalid_range_filters.js b/snippets/firestore-next/test-firestore/invalid_range_filters.js index 9ebde4ef..b6236824 100644 --- a/snippets/firestore-next/test-firestore/invalid_range_filters.js +++ b/snippets/firestore-next/test-firestore/invalid_range_filters.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START invalid_range_filters_modular] import { query, where } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/listen_diffs.js b/snippets/firestore-next/test-firestore/listen_diffs.js index 0ef32dff..531c6f1e 100644 --- a/snippets/firestore-next/test-firestore/listen_diffs.js +++ b/snippets/firestore-next/test-firestore/listen_diffs.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START listen_diffs_modular] import { collection, query, where, onSnapshot } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/listen_document.js b/snippets/firestore-next/test-firestore/listen_document.js index 9b6507fc..47b65229 100644 --- a/snippets/firestore-next/test-firestore/listen_document.js +++ b/snippets/firestore-next/test-firestore/listen_document.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START listen_document_modular] import { doc, onSnapshot } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/listen_document_local.js b/snippets/firestore-next/test-firestore/listen_document_local.js index 08041a3f..cdb4e63b 100644 --- a/snippets/firestore-next/test-firestore/listen_document_local.js +++ b/snippets/firestore-next/test-firestore/listen_document_local.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START listen_document_local_modular] import { doc, onSnapshot } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/listen_for_users.js b/snippets/firestore-next/test-firestore/listen_for_users.js index 3c42287a..5a519349 100644 --- a/snippets/firestore-next/test-firestore/listen_for_users.js +++ b/snippets/firestore-next/test-firestore/listen_for_users.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START listen_for_users_modular] import { collection, where, query, onSnapshot } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/listen_multiple.js b/snippets/firestore-next/test-firestore/listen_multiple.js index 0c7f9d46..cf30c178 100644 --- a/snippets/firestore-next/test-firestore/listen_multiple.js +++ b/snippets/firestore-next/test-firestore/listen_multiple.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START listen_multiple_modular] import { collection, query, where, onSnapshot } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/listen_with_metadata.js b/snippets/firestore-next/test-firestore/listen_with_metadata.js index 42848f62..693c1dc1 100644 --- a/snippets/firestore-next/test-firestore/listen_with_metadata.js +++ b/snippets/firestore-next/test-firestore/listen_with_metadata.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START listen_with_metadata_modular] import { doc, onSnapshot } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/new_document.js b/snippets/firestore-next/test-firestore/new_document.js index c83e4aa6..219efce7 100644 --- a/snippets/firestore-next/test-firestore/new_document.js +++ b/snippets/firestore-next/test-firestore/new_document.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START new_document_modular] import { collection, doc, setDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/not_in_filter.js b/snippets/firestore-next/test-firestore/not_in_filter.js index c880cb02..70e82480 100644 --- a/snippets/firestore-next/test-firestore/not_in_filter.js +++ b/snippets/firestore-next/test-firestore/not_in_filter.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START not_in_filter_modular] import { query, where } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/order_and_end.js b/snippets/firestore-next/test-firestore/order_and_end.js index d543ea06..7c68047f 100644 --- a/snippets/firestore-next/test-firestore/order_and_end.js +++ b/snippets/firestore-next/test-firestore/order_and_end.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START order_and_end_modular] import { query, orderBy, endAt } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/order_and_limit.js b/snippets/firestore-next/test-firestore/order_and_limit.js index 6979b518..6ff03737 100644 --- a/snippets/firestore-next/test-firestore/order_and_limit.js +++ b/snippets/firestore-next/test-firestore/order_and_limit.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START order_and_limit_modular] import { query, orderBy, limit } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/order_and_limit_desc.js b/snippets/firestore-next/test-firestore/order_and_limit_desc.js index ed61d2ab..725983de 100644 --- a/snippets/firestore-next/test-firestore/order_and_limit_desc.js +++ b/snippets/firestore-next/test-firestore/order_and_limit_desc.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START order_and_limit_desc_modular] import { query, orderBy, limit } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/order_and_start.js b/snippets/firestore-next/test-firestore/order_and_start.js index 20587a90..35cccc84 100644 --- a/snippets/firestore-next/test-firestore/order_and_start.js +++ b/snippets/firestore-next/test-firestore/order_and_start.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START order_and_start_modular] import { query, orderBy, startAt } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/order_multiple.js b/snippets/firestore-next/test-firestore/order_multiple.js index c0991c8c..7e6e5ad6 100644 --- a/snippets/firestore-next/test-firestore/order_multiple.js +++ b/snippets/firestore-next/test-firestore/order_multiple.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START order_multiple_modular] import { query, orderBy } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/paginate.js b/snippets/firestore-next/test-firestore/paginate.js index 26a7325b..cdc146ca 100644 --- a/snippets/firestore-next/test-firestore/paginate.js +++ b/snippets/firestore-next/test-firestore/paginate.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START paginate_modular] import { collection, query, orderBy, startAfter, limit, getDocs } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js b/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js index 9fab8f77..ac0ce5cb 100644 --- a/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js +++ b/snippets/firestore-next/test-firestore/server_timestamp_resolution_options.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START server_timestamp_resolution_options_modular] import { doc, updateDoc, serverTimestamp, onSnapshot } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/set_custom_object.js b/snippets/firestore-next/test-firestore/set_custom_object.js index 54febc9f..e27d3dd4 100644 --- a/snippets/firestore-next/test-firestore/set_custom_object.js +++ b/snippets/firestore-next/test-firestore/set_custom_object.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START set_custom_object_modular] import { doc, setDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/set_document.js b/snippets/firestore-next/test-firestore/set_document.js index 94a562af..a4c9bdb4 100644 --- a/snippets/firestore-next/test-firestore/set_document.js +++ b/snippets/firestore-next/test-firestore/set_document.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START set_document_modular] import { doc, setDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/set_with_merge.js b/snippets/firestore-next/test-firestore/set_with_merge.js index ca0fd3b6..f33def30 100644 --- a/snippets/firestore-next/test-firestore/set_with_merge.js +++ b/snippets/firestore-next/test-firestore/set_with_merge.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START set_with_merge_modular] import { doc, setDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/simple_queries.js b/snippets/firestore-next/test-firestore/simple_queries.js index 348cd4e6..9eede831 100644 --- a/snippets/firestore-next/test-firestore/simple_queries.js +++ b/snippets/firestore-next/test-firestore/simple_queries.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START simple_queries_modular] // Create a reference to the cities collection diff --git a/snippets/firestore-next/test-firestore/simple_queries_again.js b/snippets/firestore-next/test-firestore/simple_queries_again.js index f6256baf..bb2ebc83 100644 --- a/snippets/firestore-next/test-firestore/simple_queries_again.js +++ b/snippets/firestore-next/test-firestore/simple_queries_again.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START simple_queries_again_modular] import { collection, query, where } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/simple_query_not_equal.js b/snippets/firestore-next/test-firestore/simple_query_not_equal.js index a9ca2690..d2bef734 100644 --- a/snippets/firestore-next/test-firestore/simple_query_not_equal.js +++ b/snippets/firestore-next/test-firestore/simple_query_not_equal.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START simple_query_not_equal_modular] const notCapitalQuery = query(citiesRef, where("capital", "!=", false)); diff --git a/snippets/firestore-next/test-firestore/start_doc.js b/snippets/firestore-next/test-firestore/start_doc.js index 23f38e63..e75c7984 100644 --- a/snippets/firestore-next/test-firestore/start_doc.js +++ b/snippets/firestore-next/test-firestore/start_doc.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START start_doc_modular] import { collection, doc, getDoc, query, orderBy, startAt } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/start_multiple_orderby.js b/snippets/firestore-next/test-firestore/start_multiple_orderby.js index f0faaec0..88133d16 100644 --- a/snippets/firestore-next/test-firestore/start_multiple_orderby.js +++ b/snippets/firestore-next/test-firestore/start_multiple_orderby.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START start_multiple_orderby_modular] // Will return all Springfields diff --git a/snippets/firestore-next/test-firestore/subcollection_reference.js b/snippets/firestore-next/test-firestore/subcollection_reference.js index 7b42af67..997714f1 100644 --- a/snippets/firestore-next/test-firestore/subcollection_reference.js +++ b/snippets/firestore-next/test-firestore/subcollection_reference.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START subcollection_reference_modular] import { doc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/transaction.js b/snippets/firestore-next/test-firestore/transaction.js index 27b84264..727c5f41 100644 --- a/snippets/firestore-next/test-firestore/transaction.js +++ b/snippets/firestore-next/test-firestore/transaction.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START transaction_modular] import { runTransaction } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/transaction_promise.js b/snippets/firestore-next/test-firestore/transaction_promise.js index 7646bb6d..94792933 100644 --- a/snippets/firestore-next/test-firestore/transaction_promise.js +++ b/snippets/firestore-next/test-firestore/transaction_promise.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START transaction_promise_modular] import { doc, runTransaction } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/update_delete_field.js b/snippets/firestore-next/test-firestore/update_delete_field.js index 7bff4444..fc6f1f94 100644 --- a/snippets/firestore-next/test-firestore/update_delete_field.js +++ b/snippets/firestore-next/test-firestore/update_delete_field.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START update_delete_field_modular] import { doc, updateDoc, deleteField } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/update_document.js b/snippets/firestore-next/test-firestore/update_document.js index 23488474..1073482a 100644 --- a/snippets/firestore-next/test-firestore/update_document.js +++ b/snippets/firestore-next/test-firestore/update_document.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START update_document_modular] import { doc, updateDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/update_document_array.js b/snippets/firestore-next/test-firestore/update_document_array.js index 463e857d..29a5c04e 100644 --- a/snippets/firestore-next/test-firestore/update_document_array.js +++ b/snippets/firestore-next/test-firestore/update_document_array.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START update_document_array_modular] import { doc, updateDoc, arrayUnion, arrayRemove } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/update_document_increment.js b/snippets/firestore-next/test-firestore/update_document_increment.js index 30258a6c..b8555bcf 100644 --- a/snippets/firestore-next/test-firestore/update_document_increment.js +++ b/snippets/firestore-next/test-firestore/update_document_increment.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START update_document_increment_modular] import { doc, updateDoc, increment } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/update_document_nested.js b/snippets/firestore-next/test-firestore/update_document_nested.js index d3c12533..be66b031 100644 --- a/snippets/firestore-next/test-firestore/update_document_nested.js +++ b/snippets/firestore-next/test-firestore/update_document_nested.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START update_document_nested_modular] import { doc, setDoc, updateDoc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/update_with_server_timestamp.js b/snippets/firestore-next/test-firestore/update_with_server_timestamp.js index e4e2f248..e761f11f 100644 --- a/snippets/firestore-next/test-firestore/update_with_server_timestamp.js +++ b/snippets/firestore-next/test-firestore/update_with_server_timestamp.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START update_with_server_timestamp_modular] import { updateDoc, serverTimestamp } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/use_from_cache.js b/snippets/firestore-next/test-firestore/use_from_cache.js index 9f125e6c..e9f257da 100644 --- a/snippets/firestore-next/test-firestore/use_from_cache.js +++ b/snippets/firestore-next/test-firestore/use_from_cache.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START use_from_cache_modular] import { collection, onSnapshot, where, query } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/valid_filter_and_order.js b/snippets/firestore-next/test-firestore/valid_filter_and_order.js index ae2519d0..d75524e9 100644 --- a/snippets/firestore-next/test-firestore/valid_filter_and_order.js +++ b/snippets/firestore-next/test-firestore/valid_filter_and_order.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START valid_filter_and_order_modular] import { query, where, orderBy } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/valid_range_filters.js b/snippets/firestore-next/test-firestore/valid_range_filters.js index cd559456..9a7f5350 100644 --- a/snippets/firestore-next/test-firestore/valid_range_filters.js +++ b/snippets/firestore-next/test-firestore/valid_range_filters.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START valid_range_filters_modular] import { query, where } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-firestore/write_batch.js b/snippets/firestore-next/test-firestore/write_batch.js index 42494f5a..38f41f47 100644 --- a/snippets/firestore-next/test-firestore/write_batch.js +++ b/snippets/firestore-next/test-firestore/write_batch.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.firestore.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START write_batch_modular] import { writeBatch, doc } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js b/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js index 06b85efc..bc83cf8b 100644 --- a/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js +++ b/snippets/firestore-next/test-solution-aggregation/get_collection_ratings.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-aggregation.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START get_collection_ratings_modular] import { collection, getDocs } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-solution-aggregation/sample_doc.js b/snippets/firestore-next/test-solution-aggregation/sample_doc.js index 651b4d37..4cec6773 100644 --- a/snippets/firestore-next/test-solution-aggregation/sample_doc.js +++ b/snippets/firestore-next/test-solution-aggregation/sample_doc.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-aggregation.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START sample_doc_modular] const arinellDoc = { diff --git a/snippets/firestore-next/test-solution-arrays/post_with_array.js b/snippets/firestore-next/test-solution-arrays/post_with_array.js index da070d3d..eb336d14 100644 --- a/snippets/firestore-next/test-solution-arrays/post_with_array.js +++ b/snippets/firestore-next/test-solution-arrays/post_with_array.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-arrays.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START post_with_array_modular] // Sample document in the 'posts' collection. diff --git a/snippets/firestore-next/test-solution-arrays/post_with_map.js b/snippets/firestore-next/test-solution-arrays/post_with_map.js index 36ce26cc..16313ace 100644 --- a/snippets/firestore-next/test-solution-arrays/post_with_map.js +++ b/snippets/firestore-next/test-solution-arrays/post_with_map.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-arrays.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START post_with_map_modular] // Sample document in the 'posts' collection diff --git a/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js b/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js index b5b40eca..4cb176db 100644 --- a/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js +++ b/snippets/firestore-next/test-solution-arrays/post_with_map_advanced.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-arrays.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START post_with_map_advanced_modular] // The value of each entry in 'categories' is a unix timestamp diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category.js b/snippets/firestore-next/test-solution-arrays/query_in_category.js index 212ef92b..3a13d2cf 100644 --- a/snippets/firestore-next/test-solution-arrays/query_in_category.js +++ b/snippets/firestore-next/test-solution-arrays/query_in_category.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-arrays.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START query_in_category_modular] import { collection, getDocs, query, where } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js index 31336fac..87dd9c6f 100644 --- a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js +++ b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-arrays.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START query_in_category_timestamp_modular] import { collection, query, where, orderBy } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js index 29c0a18c..c387ac2d 100644 --- a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js +++ b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-arrays.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START query_in_category_timestamp_invalid_modular] import { collection, query, where, orderBy, FirebaseFirestore } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-solution-bundles/fs_bundle_load.js b/snippets/firestore-next/test-solution-bundles/fs_bundle_load.js index 9aa8f430..e61315d2 100644 --- a/snippets/firestore-next/test-solution-bundles/fs_bundle_load.js +++ b/snippets/firestore-next/test-solution-bundles/fs_bundle_load.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-bundles.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fs_bundle_load_modular] import { loadBundle, namedQuery, getDocsFromCache } from "firebase/firestore"; diff --git a/snippets/firestore-next/test-solution-counters/create_counter.js b/snippets/firestore-next/test-solution-counters/create_counter.js index 738dd634..11dfb3d8 100644 --- a/snippets/firestore-next/test-solution-counters/create_counter.js +++ b/snippets/firestore-next/test-solution-counters/create_counter.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-counters.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START create_counter_modular] function createCounter(ref, num_shards) { diff --git a/snippets/firestore-next/test-solution-counters/get_count.js b/snippets/firestore-next/test-solution-counters/get_count.js index 2fc01217..7dec78f1 100644 --- a/snippets/firestore-next/test-solution-counters/get_count.js +++ b/snippets/firestore-next/test-solution-counters/get_count.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-counters.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START get_count_modular] async function getCount(ref) { diff --git a/snippets/firestore-next/test-solution-counters/increment_counter.js b/snippets/firestore-next/test-solution-counters/increment_counter.js index c74ec711..22defe9c 100644 --- a/snippets/firestore-next/test-solution-counters/increment_counter.js +++ b/snippets/firestore-next/test-solution-counters/increment_counter.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-counters.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START increment_counter_modular] function incrementCounter(db, ref, num_shards) { diff --git a/snippets/firestore-next/test-solution-geoqueries/fs_geo_add_hash.js b/snippets/firestore-next/test-solution-geoqueries/fs_geo_add_hash.js index f50ab477..29caa3d5 100644 --- a/snippets/firestore-next/test-solution-geoqueries/fs_geo_add_hash.js +++ b/snippets/firestore-next/test-solution-geoqueries/fs_geo_add_hash.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-geoqueries.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fs_geo_add_hash_modular] import { doc, updateDoc } from 'firebase/firestore'; diff --git a/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js b/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js index 1230a989..95a8863c 100644 --- a/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js +++ b/snippets/firestore-next/test-solution-geoqueries/fs_geo_query_hashes.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./firestore-next/test.solution-geoqueries.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fs_geo_query_hashes_modular] import { collection, query, orderBy, startAt, endAt, getDocs } from 'firebase/firestore'; diff --git a/snippets/functions-next/callable/fb_functions_call_add_message.js b/snippets/functions-next/callable/fb_functions_call_add_message.js index 12d4d242..67c01eff 100644 --- a/snippets/functions-next/callable/fb_functions_call_add_message.js +++ b/snippets/functions-next/callable/fb_functions_call_add_message.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./functions-next/callable.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fb_functions_call_add_message_modular] import { getFunctions, httpsCallable } from "firebase/functions"; diff --git a/snippets/functions-next/callable/fb_functions_call_add_message_error.js b/snippets/functions-next/callable/fb_functions_call_add_message_error.js index 3a34c845..e87afbdd 100644 --- a/snippets/functions-next/callable/fb_functions_call_add_message_error.js +++ b/snippets/functions-next/callable/fb_functions_call_add_message_error.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./functions-next/callable.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fb_functions_call_add_message_error_modular] import { getFunctions, httpsCallable } from "firebase/functions"; diff --git a/snippets/functions-next/callable/fb_functions_initialize.js b/snippets/functions-next/callable/fb_functions_initialize.js index 7c8e4d49..d03268c8 100644 --- a/snippets/functions-next/callable/fb_functions_initialize.js +++ b/snippets/functions-next/callable/fb_functions_initialize.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./functions-next/callable.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fb_functions_initialize_modular] import { initializeApp } from "firebase/app"; diff --git a/snippets/functions-next/emulator-suite/fb_functions_callable_call.js b/snippets/functions-next/emulator-suite/fb_functions_callable_call.js index 2619806b..e547c3d3 100644 --- a/snippets/functions-next/emulator-suite/fb_functions_callable_call.js +++ b/snippets/functions-next/emulator-suite/fb_functions_callable_call.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./functions-next/emulator-suite.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fb_functions_callable_call_modular] import { getApp } from "firebase/app"; diff --git a/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js b/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js index 1a314acf..9b186fc2 100644 --- a/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js +++ b/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./functions-next/emulator-suite.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START fb_functions_emulator_connect_modular] import { getApp } from "firebase/app"; diff --git a/snippets/messaging-next/index/messaging_delete_token.js b/snippets/messaging-next/index/messaging_delete_token.js index f8d6ef63..2e27ab2a 100644 --- a/snippets/messaging-next/index/messaging_delete_token.js +++ b/snippets/messaging-next/index/messaging_delete_token.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./messaging-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START messaging_delete_token_modular] import { getMessaging, deleteToken } from "firebase/messaging"; diff --git a/snippets/messaging-next/index/messaging_get_messaging_object.js b/snippets/messaging-next/index/messaging_get_messaging_object.js index 5dc88c68..1768bdd2 100644 --- a/snippets/messaging-next/index/messaging_get_messaging_object.js +++ b/snippets/messaging-next/index/messaging_get_messaging_object.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./messaging-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START messaging_get_messaging_object_modular] import { getMessaging } from "firebase/messaging"; diff --git a/snippets/messaging-next/index/messaging_get_token.js b/snippets/messaging-next/index/messaging_get_token.js index f1f4b3aa..fe571340 100644 --- a/snippets/messaging-next/index/messaging_get_token.js +++ b/snippets/messaging-next/index/messaging_get_token.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./messaging-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START messaging_get_token_modular] import { getMessaging, getToken } from "firebase/messaging"; diff --git a/snippets/messaging-next/index/messaging_receive_message.js b/snippets/messaging-next/index/messaging_receive_message.js index 94c3864d..63825c00 100644 --- a/snippets/messaging-next/index/messaging_receive_message.js +++ b/snippets/messaging-next/index/messaging_receive_message.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./messaging-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START messaging_receive_message_modular] // Handle incoming messages. Called when: diff --git a/snippets/messaging-next/index/messaging_request_permission.js b/snippets/messaging-next/index/messaging_request_permission.js index 77e2d311..c6653037 100644 --- a/snippets/messaging-next/index/messaging_request_permission.js +++ b/snippets/messaging-next/index/messaging_request_permission.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./messaging-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START messaging_request_permission_modular] Notification.requestPermission().then((permission) => { diff --git a/snippets/messaging-next/service-worker/messaging_init_in_sw.js b/snippets/messaging-next/service-worker/messaging_init_in_sw.js index 703e687d..abce8e1d 100644 --- a/snippets/messaging-next/service-worker/messaging_init_in_sw.js +++ b/snippets/messaging-next/service-worker/messaging_init_in_sw.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./messaging-next/service-worker.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START messaging_init_in_sw_modular] import { initializeApp } from "firebase/app"; diff --git a/snippets/messaging-next/service-worker/messaging_on_background_message.js b/snippets/messaging-next/service-worker/messaging_on_background_message.js index 000ab312..b7f65b53 100644 --- a/snippets/messaging-next/service-worker/messaging_on_background_message.js +++ b/snippets/messaging-next/service-worker/messaging_on_background_message.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./messaging-next/service-worker.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START messaging_on_background_message_modular] import { getMessaging } from "firebase/messaging"; diff --git a/snippets/perf-next/index/perf_add_custom_attributes.js b/snippets/perf-next/index/perf_add_custom_attributes.js index 42639c63..a1a7b13d 100644 --- a/snippets/perf-next/index/perf_add_custom_attributes.js +++ b/snippets/perf-next/index/perf_add_custom_attributes.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./perf-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START perf_add_custom_attributes_modular] import { trace } from "firebase/performance"; diff --git a/snippets/perf-next/index/perf_add_custom_metrics.js b/snippets/perf-next/index/perf_add_custom_metrics.js index ad8ef48c..86dd674b 100644 --- a/snippets/perf-next/index/perf_add_custom_metrics.js +++ b/snippets/perf-next/index/perf_add_custom_metrics.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./perf-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START perf_add_custom_metrics_modular] import { trace } from "firebase/performance"; diff --git a/snippets/perf-next/index/perf_add_custom_trace.js b/snippets/perf-next/index/perf_add_custom_trace.js index 004ecda2..6fd54e49 100644 --- a/snippets/perf-next/index/perf_add_custom_trace.js +++ b/snippets/perf-next/index/perf_add_custom_trace.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./perf-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START perf_add_custom_trace_modular] import { trace } from "firebase/performance"; diff --git a/snippets/perf-next/index/perf_get_instance.js b/snippets/perf-next/index/perf_get_instance.js index cbee11e6..8b62eb72 100644 --- a/snippets/perf-next/index/perf_get_instance.js +++ b/snippets/perf-next/index/perf_get_instance.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./perf-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START perf_get_instance_modular] import { getPerformance } from "firebase/performance"; diff --git a/snippets/perf-next/index/perf_initialize.js b/snippets/perf-next/index/perf_initialize.js index c4802566..3b87e9c8 100644 --- a/snippets/perf-next/index/perf_initialize.js +++ b/snippets/perf-next/index/perf_initialize.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./perf-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START perf_initialize_modular] import { initializeApp } from "firebase/app"; diff --git a/snippets/perf-next/index/perf_user_timing_marks.js b/snippets/perf-next/index/perf_user_timing_marks.js index 5854f85c..8450370f 100644 --- a/snippets/perf-next/index/perf_user_timing_marks.js +++ b/snippets/perf-next/index/perf_user_timing_marks.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./perf-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START perf_user_timing_marks_modular] const performance = window.performance; diff --git a/snippets/placeholder/coming_soon.js b/snippets/placeholder/coming_soon.js index 715d6a3d..0477645f 100644 --- a/snippets/placeholder/coming_soon.js +++ b/snippets/placeholder/coming_soon.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./placeholder.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START coming_soon_modular] // TODO: Snippet coming soon! diff --git a/snippets/remoteconfig-next/index/rc_fetch_config_callback.js b/snippets/remoteconfig-next/index/rc_fetch_config_callback.js index 3975befd..3cb39de0 100644 --- a/snippets/remoteconfig-next/index/rc_fetch_config_callback.js +++ b/snippets/remoteconfig-next/index/rc_fetch_config_callback.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./remoteconfig-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rc_fetch_config_callback_modular] import { fetchAndActivate } from "firebase/remote-config"; diff --git a/snippets/remoteconfig-next/index/rc_get_instance.js b/snippets/remoteconfig-next/index/rc_get_instance.js index 7d59bf9d..0bf952b8 100644 --- a/snippets/remoteconfig-next/index/rc_get_instance.js +++ b/snippets/remoteconfig-next/index/rc_get_instance.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./remoteconfig-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rc_get_instance_modular] import { getRemoteConfig } from "firebase/remote-config"; diff --git a/snippets/remoteconfig-next/index/rc_get_values.js b/snippets/remoteconfig-next/index/rc_get_values.js index 1266cfe9..67018e3b 100644 --- a/snippets/remoteconfig-next/index/rc_get_values.js +++ b/snippets/remoteconfig-next/index/rc_get_values.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./remoteconfig-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rc_get_values_modular] import { getValue } from "firebase/remote-config"; diff --git a/snippets/remoteconfig-next/index/rc_set_default_values.js b/snippets/remoteconfig-next/index/rc_set_default_values.js index 6db33c0d..80e0e8c2 100644 --- a/snippets/remoteconfig-next/index/rc_set_default_values.js +++ b/snippets/remoteconfig-next/index/rc_set_default_values.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./remoteconfig-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rc_set_default_values_modular] remoteConfig.defaultConfig = { diff --git a/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js b/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js index 77a442f9..131976c5 100644 --- a/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js +++ b/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./remoteconfig-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START rc_set_minimum_fetch_time_modular] remoteConfig.settings.minimumFetchIntervalMillis = 3600000; diff --git a/snippets/storage-next/create-reference/storage_create_ref.js b/snippets/storage-next/create-reference/storage_create_ref.js index eb27bacb..761a634a 100644 --- a/snippets/storage-next/create-reference/storage_create_ref.js +++ b/snippets/storage-next/create-reference/storage_create_ref.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/create-reference.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_create_ref_modular] import { getStorage, ref } from "firebase/storage"; diff --git a/snippets/storage-next/create-reference/storage_create_ref_child.js b/snippets/storage-next/create-reference/storage_create_ref_child.js index 53b6834c..5e16407a 100644 --- a/snippets/storage-next/create-reference/storage_create_ref_child.js +++ b/snippets/storage-next/create-reference/storage_create_ref_child.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/create-reference.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_create_ref_child_modular] import { getStorage, ref } from "firebase/storage"; diff --git a/snippets/storage-next/create-reference/storage_navigate_ref.js b/snippets/storage-next/create-reference/storage_navigate_ref.js index 00a9e53f..ee279c72 100644 --- a/snippets/storage-next/create-reference/storage_navigate_ref.js +++ b/snippets/storage-next/create-reference/storage_navigate_ref.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/create-reference.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_navigate_ref_modular] import { getStorage, ref } from "firebase/storage"; diff --git a/snippets/storage-next/create-reference/storage_navigate_ref_chain.js b/snippets/storage-next/create-reference/storage_navigate_ref_chain.js index e0f2a056..d5e13752 100644 --- a/snippets/storage-next/create-reference/storage_navigate_ref_chain.js +++ b/snippets/storage-next/create-reference/storage_navigate_ref_chain.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/create-reference.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_navigate_ref_chain_modular] import { getStorage, ref } from "firebase/storage"; diff --git a/snippets/storage-next/create-reference/storage_ref_full_example.js b/snippets/storage-next/create-reference/storage_ref_full_example.js index 3c9f94c6..e61f4594 100644 --- a/snippets/storage-next/create-reference/storage_ref_full_example.js +++ b/snippets/storage-next/create-reference/storage_ref_full_example.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/create-reference.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_ref_full_example_modular] import { getStorage, ref } from "firebase/storage"; diff --git a/snippets/storage-next/create-reference/storage_ref_properties.js b/snippets/storage-next/create-reference/storage_ref_properties.js index 494817ea..c95a5b13 100644 --- a/snippets/storage-next/create-reference/storage_ref_properties.js +++ b/snippets/storage-next/create-reference/storage_ref_properties.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/create-reference.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_ref_properties_modular] import { getStorage, ref } from "firebase/storage"; diff --git a/snippets/storage-next/delete-files/storage_delete_file.js b/snippets/storage-next/delete-files/storage_delete_file.js index 86520968..c851c447 100644 --- a/snippets/storage-next/delete-files/storage_delete_file.js +++ b/snippets/storage-next/delete-files/storage_delete_file.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/delete-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_delete_file_modular] import { getStorage, ref, deleteObject } from "firebase/storage"; diff --git a/snippets/storage-next/download-files/storage_download_create_ref.js b/snippets/storage-next/download-files/storage_download_create_ref.js index bf12aaa9..8b1345b7 100644 --- a/snippets/storage-next/download-files/storage_download_create_ref.js +++ b/snippets/storage-next/download-files/storage_download_create_ref.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/download-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_download_create_ref_modular] import { getStorage, ref } from "firebase/storage"; diff --git a/snippets/storage-next/download-files/storage_download_full_example.js b/snippets/storage-next/download-files/storage_download_full_example.js index 4b66880e..cdd12166 100644 --- a/snippets/storage-next/download-files/storage_download_full_example.js +++ b/snippets/storage-next/download-files/storage_download_full_example.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/download-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_download_full_example_modular] import { getStorage, ref, getDownloadURL } from "firebase/storage"; diff --git a/snippets/storage-next/download-files/storage_download_via_url.js b/snippets/storage-next/download-files/storage_download_via_url.js index 0e45cada..c90e235c 100644 --- a/snippets/storage-next/download-files/storage_download_via_url.js +++ b/snippets/storage-next/download-files/storage_download_via_url.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/download-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_download_via_url_modular] import { getStorage, ref, getDownloadURL } from "firebase/storage"; diff --git a/snippets/storage-next/file-metadata/storage_custom_metadata.js b/snippets/storage-next/file-metadata/storage_custom_metadata.js index 7674c7d4..d6fb5ab4 100644 --- a/snippets/storage-next/file-metadata/storage_custom_metadata.js +++ b/snippets/storage-next/file-metadata/storage_custom_metadata.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/file-metadata.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_custom_metadata_modular] const metadata = { diff --git a/snippets/storage-next/file-metadata/storage_delete_metadata.js b/snippets/storage-next/file-metadata/storage_delete_metadata.js index c6b2ece3..71db946e 100644 --- a/snippets/storage-next/file-metadata/storage_delete_metadata.js +++ b/snippets/storage-next/file-metadata/storage_delete_metadata.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/file-metadata.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_delete_metadata_modular] import { getStorage, ref, updateMetadata } from "firebase/storage"; diff --git a/snippets/storage-next/file-metadata/storage_get_metadata.js b/snippets/storage-next/file-metadata/storage_get_metadata.js index e77444db..b2c96f1a 100644 --- a/snippets/storage-next/file-metadata/storage_get_metadata.js +++ b/snippets/storage-next/file-metadata/storage_get_metadata.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/file-metadata.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_get_metadata_modular] import { getStorage, ref, getMetadata } from "firebase/storage"; diff --git a/snippets/storage-next/file-metadata/storage_update_metadata.js b/snippets/storage-next/file-metadata/storage_update_metadata.js index fd9d6183..2435983b 100644 --- a/snippets/storage-next/file-metadata/storage_update_metadata.js +++ b/snippets/storage-next/file-metadata/storage_update_metadata.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/file-metadata.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_update_metadata_modular] import { getStorage, ref, updateMetadata } from "firebase/storage"; diff --git a/snippets/storage-next/index/storage_custom_app.js b/snippets/storage-next/index/storage_custom_app.js index 0c4f26fe..7196c252 100644 --- a/snippets/storage-next/index/storage_custom_app.js +++ b/snippets/storage-next/index/storage_custom_app.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_custom_app_modular] import { getStorage } from "firebase/storage"; diff --git a/snippets/storage-next/index/storage_initialize.js b/snippets/storage-next/index/storage_initialize.js index 61ad21be..422df3dd 100644 --- a/snippets/storage-next/index/storage_initialize.js +++ b/snippets/storage-next/index/storage_initialize.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_initialize_modular] import { initializeApp } from "firebase/app"; diff --git a/snippets/storage-next/index/storage_multiple_buckets.js b/snippets/storage-next/index/storage_multiple_buckets.js index 1022299b..426dd4f4 100644 --- a/snippets/storage-next/index/storage_multiple_buckets.js +++ b/snippets/storage-next/index/storage_multiple_buckets.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_multiple_buckets_modular] import { getApp } from "firebase/app"; diff --git a/snippets/storage-next/index/storage_on_complete.js b/snippets/storage-next/index/storage_on_complete.js index aa3edca8..e5d792f3 100644 --- a/snippets/storage-next/index/storage_on_complete.js +++ b/snippets/storage-next/index/storage_on_complete.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/index.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_on_complete_modular] import { getStorage, ref, uploadBytesResumable, getDownloadURL } from "firebase/storage"; diff --git a/snippets/storage-next/list-files/storage_list_all.js b/snippets/storage-next/list-files/storage_list_all.js index 1adf935a..11e72e9e 100644 --- a/snippets/storage-next/list-files/storage_list_all.js +++ b/snippets/storage-next/list-files/storage_list_all.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/list-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_list_all_modular] import { getStorage, ref, listAll } from "firebase/storage"; diff --git a/snippets/storage-next/list-files/storage_list_paginate.js b/snippets/storage-next/list-files/storage_list_paginate.js index d04cd1d3..c7dd314e 100644 --- a/snippets/storage-next/list-files/storage_list_paginate.js +++ b/snippets/storage-next/list-files/storage_list_paginate.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/list-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_list_paginate_modular] import { getStorage, ref, list } from "firebase/storage"; diff --git a/snippets/storage-next/upload-files/storage_manage_uploads.js b/snippets/storage-next/upload-files/storage_manage_uploads.js index 2623e8a1..0eaf008a 100644 --- a/snippets/storage-next/upload-files/storage_manage_uploads.js +++ b/snippets/storage-next/upload-files/storage_manage_uploads.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/upload-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_manage_uploads_modular] import { getStorage, ref, uploadBytesResumable } from "firebase/storage"; diff --git a/snippets/storage-next/upload-files/storage_monitor_upload.js b/snippets/storage-next/upload-files/storage_monitor_upload.js index 101f509a..cf035832 100644 --- a/snippets/storage-next/upload-files/storage_monitor_upload.js +++ b/snippets/storage-next/upload-files/storage_monitor_upload.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/upload-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_monitor_upload_modular] import { getStorage, ref, uploadBytesResumable, getDownloadURL } from "firebase/storage"; diff --git a/snippets/storage-next/upload-files/storage_upload_blob.js b/snippets/storage-next/upload-files/storage_upload_blob.js index c33593cb..5ad22f8e 100644 --- a/snippets/storage-next/upload-files/storage_upload_blob.js +++ b/snippets/storage-next/upload-files/storage_upload_blob.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/upload-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_upload_blob_modular] import { getStorage, ref, uploadBytes } from "firebase/storage"; diff --git a/snippets/storage-next/upload-files/storage_upload_bytes.js b/snippets/storage-next/upload-files/storage_upload_bytes.js index ebf12e66..82acac25 100644 --- a/snippets/storage-next/upload-files/storage_upload_bytes.js +++ b/snippets/storage-next/upload-files/storage_upload_bytes.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/upload-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_upload_bytes_modular] import { getStorage, ref, uploadBytes } from "firebase/storage"; diff --git a/snippets/storage-next/upload-files/storage_upload_handle_error.js b/snippets/storage-next/upload-files/storage_upload_handle_error.js index 434fc230..bf50c6b5 100644 --- a/snippets/storage-next/upload-files/storage_upload_handle_error.js +++ b/snippets/storage-next/upload-files/storage_upload_handle_error.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/upload-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_upload_handle_error_modular] import { getStorage, ref, uploadBytesResumable, getDownloadURL } from "firebase/storage"; diff --git a/snippets/storage-next/upload-files/storage_upload_metadata.js b/snippets/storage-next/upload-files/storage_upload_metadata.js index 1ac39783..3dd304b4 100644 --- a/snippets/storage-next/upload-files/storage_upload_metadata.js +++ b/snippets/storage-next/upload-files/storage_upload_metadata.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/upload-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_upload_metadata_modular] import { getStorage, ref, uploadBytes } from "firebase/storage"; diff --git a/snippets/storage-next/upload-files/storage_upload_ref.js b/snippets/storage-next/upload-files/storage_upload_ref.js index e776120d..ef565bf2 100644 --- a/snippets/storage-next/upload-files/storage_upload_ref.js +++ b/snippets/storage-next/upload-files/storage_upload_ref.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/upload-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_upload_ref_modular] import { getStorage, ref } from "firebase/storage"; diff --git a/snippets/storage-next/upload-files/storage_upload_string.js b/snippets/storage-next/upload-files/storage_upload_string.js index ce0d4736..6450a566 100644 --- a/snippets/storage-next/upload-files/storage_upload_string.js +++ b/snippets/storage-next/upload-files/storage_upload_string.js @@ -1,7 +1,8 @@ // This snippet file was generated by processing the source file: // ./storage-next/upload-files.js // -// To make edits to the snippets in this file, please edit the source +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. // [START storage_upload_string_modular] import { getStorage, ref, uploadString } from "firebase/storage"; From ccf43903c930d121980e3f9ec2208160318d6dca Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 30 Jul 2021 09:01:37 +0000 Subject: [PATCH 175/235] Auto-update dependencies. (#211) --- analytics/package.json | 2 +- appcheck/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 57c16836..78c425e7 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.0" + "firebase": "^8.8.1" } } diff --git a/appcheck/package.json b/appcheck/package.json index cf7d82b3..7208eddf 100644 --- a/appcheck/package.json +++ b/appcheck/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.0" + "firebase": "^8.8.1" } } diff --git a/auth/package.json b/auth/package.json index f8a0c4de..95ed84c2 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.8.0", + "firebase": "^8.8.1", "firebaseui": "^4.8.1" } } diff --git a/database/package.json b/database/package.json index d26b77fb..356597c4 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.8.0" + "firebase": "^8.8.1" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index fd76176d..65e8ce77 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.0" + "firebase": "^8.8.1" } } diff --git a/firestore/package.json b/firestore/package.json index 400d854f..b831157a 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.0", + "firebase": "^8.8.1", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 78ddd20e..c2ad0aa1 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.0" + "firebase": "^8.8.1" } } diff --git a/installations/package.json b/installations/package.json index 948ad208..412aade6 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.8.0" + "firebase": "^8.8.1" } } diff --git a/messaging/package.json b/messaging/package.json index 3d9ea607..35a95be2 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.0" + "firebase": "^8.8.1" } } diff --git a/perf/package.json b/perf/package.json index c928467c..d6f57401 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.0" + "firebase": "^8.8.1" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 781f8363..8d5f02f8 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.0" + "firebase": "^8.8.1" } } diff --git a/storage/package.json b/storage/package.json index 9ab7fd82..18190f7a 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.0" + "firebase": "^8.8.1" } } From 3c57ca857d15e079ffe20a800bc3612e855849a0 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Fri, 30 Jul 2021 14:18:39 +0000 Subject: [PATCH 176/235] Auto-update dependencies. (#212) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 81809b77..107339fc 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 7877457c..65f0aa01 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.8.0/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.8.0/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.8.1/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.8.1/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 4126f18e92092c07f8eef2d78314da27822c20f0 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 3 Aug 2021 13:30:49 +0100 Subject: [PATCH 177/235] Add snippet for Auth Emulator + Google Credential (#213) --- auth-next/emulator-suite.js | 12 ++++++++++++ auth/emulator-suite.js | 11 ++++++++++- .../auth_emulator_google_credential.js | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 snippets/auth-next/emulator-suite/auth_emulator_google_credential.js diff --git a/auth-next/emulator-suite.js b/auth-next/emulator-suite.js index 84d57ed0..66507de3 100644 --- a/auth-next/emulator-suite.js +++ b/auth-next/emulator-suite.js @@ -10,3 +10,15 @@ function emulatorConnect() { // [END auth_emulator_connect] } +function emulatorGoogleCredential() { + // [START auth_emulator_google_credential] + const { getAuth, signInWithCredential, GoogleAuthProvider } = require("firebase/auth"); + + const auth = getAuth(); + signInWithCredential(auth, GoogleAuthProvider.credential( + '{"sub": "abc123", "email": "foo@example.com", "email_verified": true}' + )); + // [END auth_emulator_google_credential] +} + + diff --git a/auth/emulator-suite.js b/auth/emulator-suite.js index 044795a7..b14a72db 100644 --- a/auth/emulator-suite.js +++ b/auth/emulator-suite.js @@ -3,7 +3,16 @@ import "firebase/auth"; function emulatorConnect() { // [START auth_emulator_connect] - var auth = firebase.auth(); + const auth = firebase.auth(); auth.useEmulator("http://localhost:9099"); // [END auth_emulator_connect] } + +function emulatorGoogleCredential() { + // [START auth_emulator_google_credential] + const auth = firebase.auth(); + auth.signInWithCredential(firebase.auth.GoogleAuthProvider.credential( + '{"sub": "abc123", "email": "foo@example.com", "email_verified": true}' + )); + // [END auth_emulator_google_credential] +} diff --git a/snippets/auth-next/emulator-suite/auth_emulator_google_credential.js b/snippets/auth-next/emulator-suite/auth_emulator_google_credential.js new file mode 100644 index 00000000..d3683bb0 --- /dev/null +++ b/snippets/auth-next/emulator-suite/auth_emulator_google_credential.js @@ -0,0 +1,14 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/emulator-suite.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_emulator_google_credential_modular] +import { getAuth, signInWithCredential, GoogleAuthProvider } from "firebase/auth"; + +const auth = getAuth(); +signInWithCredential(auth, GoogleAuthProvider.credential( + '{"sub": "abc123", "email": "foo@example.com", "email_verified": true}' +)); +// [END auth_emulator_google_credential_modular] \ No newline at end of file From eee411f0580eb061e4c6eeabf9b4fd8aac9b49ab Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 3 Aug 2021 13:42:34 +0100 Subject: [PATCH 178/235] Update to vNext Beta 8 (#214) --- analytics-next/package.json | 2 +- appcheck-next/package.json | 2 +- auth-next/package.json | 2 +- database-next/package.json | 2 +- firebaseapp-next/package.json | 2 +- firestore-next/package.json | 2 +- firestore-next/test.firestore.js | 4 ++-- firestore-next/test.solution-aggregation.js | 4 ++-- firestore-next/test.solution-arrays.js | 6 +++--- firestore-next/test.solution-bundles.js | 4 ++-- firestore-next/test.solution-counters.js | 4 ++-- firestore-next/test.solution-geoqueries.js | 4 ++-- functions-next/package.json | 2 +- messaging-next/package.json | 2 +- perf-next/package.json | 2 +- remoteconfig-next/package.json | 2 +- .../query_in_category_timestamp_invalid.js | 2 +- storage-next/package.json | 2 +- 18 files changed, 25 insertions(+), 25 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index b04876cb..94d9a07e 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.7" + "firebase": "^9.0.0-beta.8" } } diff --git a/appcheck-next/package.json b/appcheck-next/package.json index 8fc601eb..9a7a71bb 100644 --- a/appcheck-next/package.json +++ b/appcheck-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.7" + "firebase": "^9.0.0-beta.8" } } diff --git a/auth-next/package.json b/auth-next/package.json index 1a955b2a..68d38869 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.7" + "firebase": "^9.0.0-beta.8" } } diff --git a/database-next/package.json b/database-next/package.json index a6c12500..1c21a0e6 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.7" + "firebase": "^9.0.0-beta.8" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index daeaf862..4eec0161 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.7" + "firebase": "^9.0.0-beta.8" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index fe0e5390..f15f2ed0 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.7", + "firebase": "^9.0.0-beta.8", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 7dca3d0e..71c54b95 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -32,9 +32,9 @@ const cityConverter = { // [END city_custom_object] describe("firestore", () => { - const { FirebaseFirestore } = require("firebase/firestore"); + const { Firestore } = require("firebase/firestore"); - /** @type {FirebaseFirestore} */ + /** @type {Firestore} */ let db; let app; diff --git a/firestore-next/test.solution-aggregation.js b/firestore-next/test.solution-aggregation.js index c0a825b5..7106a0c9 100644 --- a/firestore-next/test.solution-aggregation.js +++ b/firestore-next/test.solution-aggregation.js @@ -10,9 +10,9 @@ const arinellDoc = { // [END sample_doc] describe("firestore-solution-arrays", () => { - const { FirebaseFirestore } = require("firebase/firestore"); + const { Firestore } = require("firebase/firestore"); - /** @type {FirebaseFirestore} */ + /** @type {Firestore} */ let db; before(async () => { diff --git a/firestore-next/test.solution-arrays.js b/firestore-next/test.solution-arrays.js index 3ca186ac..3746a8d1 100644 --- a/firestore-next/test.solution-arrays.js +++ b/firestore-next/test.solution-arrays.js @@ -44,9 +44,9 @@ const postsWithMapAdvanced = [ ]; describe("firestore-solution-arrays", () => { - const { FirebaseFirestore } = require("firebase/firestore"); + const { Firestore } = require("firebase/firestore"); - /** @type {FirebaseFirestore} */ + /** @type {Firestore} */ let db; before(() => { @@ -78,7 +78,7 @@ describe("firestore-solution-arrays", () => { it("should query in a category by timestamp", () => { function queryOne() { // [START query_in_category_timestamp_invalid] - const { collection, query, where, orderBy, FirebaseFirestore } = require("firebase/firestore"); + const { collection, query, where, orderBy, Firestore } = require("firebase/firestore"); const q = query(collection(db, "posts"), where("categories.cats", "==", true), diff --git a/firestore-next/test.solution-bundles.js b/firestore-next/test.solution-bundles.js index 400aeeb8..94bf7ff2 100644 --- a/firestore-next/test.solution-bundles.js +++ b/firestore-next/test.solution-bundles.js @@ -1,10 +1,10 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -const { FirebaseFirestore } = require('firebase/firestore'); +const { Firestore } = require('firebase/firestore'); /** - * @type FirebaseFirestore + * @type Firestore */ var db; diff --git a/firestore-next/test.solution-counters.js b/firestore-next/test.solution-counters.js index ec671731..da854797 100644 --- a/firestore-next/test.solution-counters.js +++ b/firestore-next/test.solution-counters.js @@ -1,9 +1,9 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -const { FirebaseFirestore } = require('firebase/firestore'); +const { Firestore } = require('firebase/firestore'); -/** @type {FirebaseFirestore} */ +/** @type {Firestore} */ let db; // [START create_counter] diff --git a/firestore-next/test.solution-geoqueries.js b/firestore-next/test.solution-geoqueries.js index 1293229e..507c6178 100644 --- a/firestore-next/test.solution-geoqueries.js +++ b/firestore-next/test.solution-geoqueries.js @@ -1,11 +1,11 @@ // [SNIPPET_REGISTRY disabled] // [SNIPPETS_SEPARATION enabled] -const { FirebaseFirestore } = require('firebase/firestore'); +const { Firestore } = require('firebase/firestore'); const geofire = require('geofire-common'); -/** @type {FirebaseFirestore} */ +/** @type {Firestore} */ let db; async function addHash(done) { diff --git a/functions-next/package.json b/functions-next/package.json index 38a60b6f..8e0e6422 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.7" + "firebase": "^9.0.0-beta.8" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index cb9c10c3..2137e3e2 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.7" + "firebase": "^9.0.0-beta.8" } } diff --git a/perf-next/package.json b/perf-next/package.json index 7ff11967..9321e3c8 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.7" + "firebase": "^9.0.0-beta.8" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index eaa7272d..6f8e1636 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.7" + "firebase": "^9.0.0-beta.8" } } diff --git a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js index c387ac2d..f50dc17c 100644 --- a/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js +++ b/snippets/firestore-next/test-solution-arrays/query_in_category_timestamp_invalid.js @@ -5,7 +5,7 @@ // 'npm run snippets'. // [START query_in_category_timestamp_invalid_modular] -import { collection, query, where, orderBy, FirebaseFirestore } from "firebase/firestore"; +import { collection, query, where, orderBy, Firestore } from "firebase/firestore"; const q = query(collection(db, "posts"), where("categories.cats", "==", true), diff --git a/storage-next/package.json b/storage-next/package.json index a912d510..6aca1112 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.7" + "firebase": "^9.0.0-beta.8" } } From dc5474c6b5375edc700485e1d49a007e9605be7b Mon Sep 17 00:00:00 2001 From: ochui princewill patrick Date: Mon, 9 Aug 2021 13:35:57 +0100 Subject: [PATCH 179/235] Fix broken link (#217) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b6f50ee..b45ac156 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This repository holds code snippets used in Web documentation on [firebase.google.com](https://firebase.google.com/docs/). -These snippets are part of our documentation and best read in the context of a documentation page rather than used directly. If you're looking to get started with the Firebase Web SDK the best place to start is [quicstart-web](https://github.com/firebase/quickstart-web). +These snippets are part of our documentation and best read in the context of a documentation page rather than used directly. If you're looking to get started with the Firebase Web SDK the best place to start is [quickstart-js](https://github.com/firebase/quickstart-js). ## Example From 981c7a5040fd42cd5b1c87e3035d4748b6e8f62e Mon Sep 17 00:00:00 2001 From: DPEBot Date: Tue, 10 Aug 2021 11:09:49 -0700 Subject: [PATCH 180/235] Auto-update dependencies. (#215) --- analytics/package.json | 2 +- appcheck/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 78c425e7..9f18a1f0 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.1" + "firebase": "^8.9.1" } } diff --git a/appcheck/package.json b/appcheck/package.json index 7208eddf..d1f53982 100644 --- a/appcheck/package.json +++ b/appcheck/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.1" + "firebase": "^8.9.1" } } diff --git a/auth/package.json b/auth/package.json index 95ed84c2..d8178118 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.8.1", + "firebase": "^8.9.1", "firebaseui": "^4.8.1" } } diff --git a/database/package.json b/database/package.json index 356597c4..728b0f7a 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.8.1" + "firebase": "^8.9.1" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index 65e8ce77..dfe2745d 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.1" + "firebase": "^8.9.1" } } diff --git a/firestore/package.json b/firestore/package.json index b831157a..e91ee858 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.1", + "firebase": "^8.9.1", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index c2ad0aa1..9861def8 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.1" + "firebase": "^8.9.1" } } diff --git a/installations/package.json b/installations/package.json index 412aade6..c8cb6019 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.8.1" + "firebase": "^8.9.1" } } diff --git a/messaging/package.json b/messaging/package.json index 35a95be2..a20a9ff1 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.1" + "firebase": "^8.9.1" } } diff --git a/perf/package.json b/perf/package.json index d6f57401..c30e4855 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.1" + "firebase": "^8.9.1" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 8d5f02f8..1d1da529 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.1" + "firebase": "^8.9.1" } } diff --git a/storage/package.json b/storage/package.json index 18190f7a..76392f55 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.8.1" + "firebase": "^8.9.1" } } From 955170d907dab12502a8e50967a698f93caa1705 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Tue, 10 Aug 2021 11:12:51 -0700 Subject: [PATCH 181/235] Auto-update dependencies. (#216) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 107339fc..bc24d2b8 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 65f0aa01..9b768ff4 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.8.1/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.8.1/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.9.1/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.9.1/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 91b44d995445cbe69c0c38e78afcfa9f38a2db39 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 10 Aug 2021 19:16:48 +0100 Subject: [PATCH 182/235] Analytics screenView snippet (#191) --- analytics-next/index.js | 15 +++++++++++++++ analytics/index.js | 12 ++++++++++++ .../index/analytics_record_screen_view.js | 15 +++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 snippets/analytics-next/index/analytics_record_screen_view.js diff --git a/analytics-next/index.js b/analytics-next/index.js index a93de88a..510fa758 100644 --- a/analytics-next/index.js +++ b/analytics-next/index.js @@ -50,3 +50,18 @@ function setUserProperties() { setUserProperties(analytics, { favorite_food: 'apples' }); // [END analytics_set_user_properties] } + +function recordScreenView() { + const screenName = ''; + const screenClass = ''; + + // [START analytics_record_screen_view] + const { getAnalytics, logEvent } = require("firebase/analytics"); + + const analytics = getAnalytics(); + logEvent(analytics, 'screen_view', { + firebase_screen: screenName, + firebase_screen_class: screenClass + }); + // [END analytics_record_screen_view] +} diff --git a/analytics/index.js b/analytics/index.js index f8a0e856..76d2c289 100644 --- a/analytics/index.js +++ b/analytics/index.js @@ -38,3 +38,15 @@ function setUserProperties() { firebase.analytics().setUserProperties({favorite_food: 'apples'}); // [END analytics_set_user_properties] } + +function recordScreenView() { + const screenName = ''; + const screenClass = ''; + + // [START analytics_record_screen_view] + firebase.analytics().logEvent('screen_view', { + firebase_screen: screenName, + firebase_screen_class: screenClass + }); + // [END analytics_record_screen_view] +} diff --git a/snippets/analytics-next/index/analytics_record_screen_view.js b/snippets/analytics-next/index/analytics_record_screen_view.js new file mode 100644 index 00000000..2eef20b3 --- /dev/null +++ b/snippets/analytics-next/index/analytics_record_screen_view.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./analytics-next/index.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START analytics_record_screen_view_modular] +import { getAnalytics, logEvent } from "firebase/analytics"; + +const analytics = getAnalytics(); +logEvent(analytics, 'screen_view', { + firebase_screen: screenName, + firebase_screen_class: screenClass +}); +// [END analytics_record_screen_view_modular] \ No newline at end of file From c5bfca32e881d7a40002285384a784749f973c35 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Thu, 12 Aug 2021 17:57:59 +0100 Subject: [PATCH 183/235] Perf initialize snippets (#219) --- perf-next/index.js | 4 +++- perf/index.js | 2 ++ snippets/perf-next/index/perf_imports.js | 10 ++++++++++ snippets/perf-next/index/perf_initialize.js | 3 --- 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 snippets/perf-next/index/perf_imports.js diff --git a/perf-next/index.js b/perf-next/index.js index 20f9b4f4..892f2b7e 100644 --- a/perf-next/index.js +++ b/perf-next/index.js @@ -4,10 +4,12 @@ const perf = getInstance(); function intialize() { - // [START perf_initialize] + // [START perf_imports] const { initializeApp } = require("firebase/app"); const { getPerformance } = require("firebase/performance"); + // [END perf_imports] + // [START perf_initialize] // TODO: Replace the following with your app's Firebase project configuration // See: https://firebase.google.com/docs/web/setup#config-object const firebaseConfig = { diff --git a/perf/index.js b/perf/index.js index 6d512e32..e4b46286 100644 --- a/perf/index.js +++ b/perf/index.js @@ -1,5 +1,7 @@ +// [START perf_imports] import firebase from "firebase/app"; import "firebase/performance"; +// [END perf_imports] const perf = firebase.performance(); diff --git a/snippets/perf-next/index/perf_imports.js b/snippets/perf-next/index/perf_imports.js new file mode 100644 index 00000000..83e0205f --- /dev/null +++ b/snippets/perf-next/index/perf_imports.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./perf-next/index.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START perf_imports_modular] +import { initializeApp } from "firebase/app"; +import { getPerformance } from "firebase/performance"; +// [END perf_imports_modular] \ No newline at end of file diff --git a/snippets/perf-next/index/perf_initialize.js b/snippets/perf-next/index/perf_initialize.js index 3b87e9c8..6d0e6657 100644 --- a/snippets/perf-next/index/perf_initialize.js +++ b/snippets/perf-next/index/perf_initialize.js @@ -5,9 +5,6 @@ // 'npm run snippets'. // [START perf_initialize_modular] -import { initializeApp } from "firebase/app"; -import { getPerformance } from "firebase/performance"; - // TODO: Replace the following with your app's Firebase project configuration // See: https://firebase.google.com/docs/web/setup#config-object const firebaseConfig = { From 0f582bcff452ee6312a42127e1138153d0e351e8 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 17 Aug 2021 19:28:17 +0100 Subject: [PATCH 184/235] Granular perf initialization snippets (#223) --- perf-next/index.js | 16 ++++++++++------ perf/index.js | 16 ++++++++++------ .../index/{perf_imports.js => perf_import.js} | 5 ++--- snippets/perf-next/index/perf_import_app.js | 9 +++++++++ ...perf_initialize.js => perf_initialize_app.js} | 9 +++------ snippets/perf-next/index/perf_singleton.js | 10 ++++++++++ 6 files changed, 44 insertions(+), 21 deletions(-) rename snippets/perf-next/index/{perf_imports.js => perf_import.js} (69%) create mode 100644 snippets/perf-next/index/perf_import_app.js rename snippets/perf-next/index/{perf_initialize.js => perf_initialize_app.js} (64%) create mode 100644 snippets/perf-next/index/perf_singleton.js diff --git a/perf-next/index.js b/perf-next/index.js index 892f2b7e..83fce95c 100644 --- a/perf-next/index.js +++ b/perf-next/index.js @@ -4,12 +4,14 @@ const perf = getInstance(); function intialize() { - // [START perf_imports] + // [START perf_import_app] const { initializeApp } = require("firebase/app"); + // [END perf_import_app] + // [START perf_import] const { getPerformance } = require("firebase/performance"); - // [END perf_imports] + // [END perf_import] - // [START perf_initialize] + // [START perf_initialize_app] // TODO: Replace the following with your app's Firebase project configuration // See: https://firebase.google.com/docs/web/setup#config-object const firebaseConfig = { @@ -17,11 +19,13 @@ function intialize() { }; // Initialize Firebase - const app = initializeApp(firebaseConfig); + initializeApp(firebaseConfig); + // [END perf_initialize_app] + // [START perf_singleton] // Initialize Performance Monitoring and get a reference to the service - const perf = getPerformance(app); - // [END perf_initialize] + const perf = getPerformance(); + // [END perf_singleton] } export function getInstance() { diff --git a/perf/index.js b/perf/index.js index e4b46286..d1d61202 100644 --- a/perf/index.js +++ b/perf/index.js @@ -1,24 +1,28 @@ -// [START perf_imports] +// [START perf_import_app] import firebase from "firebase/app"; +// [END perf_import_app] +// [START perf_import] import "firebase/performance"; -// [END perf_imports] +// [END perf_import] const perf = firebase.performance(); function intialize() { - // [START perf_initialize] + // [START perf_initialize_app] // TODO: Replace the following with your app's Firebase project configuration // See: https://firebase.google.com/docs/web/setup#config-object - var firebaseConfig = { + const firebaseConfig = { // ... }; // Initialize Firebase firebase.initializeApp(firebaseConfig); + // [END perf_initialize_app] + // [START perf_singleton] // Initialize Performance Monitoring and get a reference to the service - var perf = firebase.performance(); - // [END perf_initialize] + const perf = firebase.performance(); + // [END perf_singleton] } function addCustomTrace() { diff --git a/snippets/perf-next/index/perf_imports.js b/snippets/perf-next/index/perf_import.js similarity index 69% rename from snippets/perf-next/index/perf_imports.js rename to snippets/perf-next/index/perf_import.js index 83e0205f..326afe91 100644 --- a/snippets/perf-next/index/perf_imports.js +++ b/snippets/perf-next/index/perf_import.js @@ -4,7 +4,6 @@ // To update the snippets in this file, edit the source and then run // 'npm run snippets'. -// [START perf_imports_modular] -import { initializeApp } from "firebase/app"; +// [START perf_import_modular] import { getPerformance } from "firebase/performance"; -// [END perf_imports_modular] \ No newline at end of file +// [END perf_import_modular] \ No newline at end of file diff --git a/snippets/perf-next/index/perf_import_app.js b/snippets/perf-next/index/perf_import_app.js new file mode 100644 index 00000000..c2b640b9 --- /dev/null +++ b/snippets/perf-next/index/perf_import_app.js @@ -0,0 +1,9 @@ +// This snippet file was generated by processing the source file: +// ./perf-next/index.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START perf_import_app_modular] +import { initializeApp } from "firebase/app"; +// [END perf_import_app_modular] \ No newline at end of file diff --git a/snippets/perf-next/index/perf_initialize.js b/snippets/perf-next/index/perf_initialize_app.js similarity index 64% rename from snippets/perf-next/index/perf_initialize.js rename to snippets/perf-next/index/perf_initialize_app.js index 6d0e6657..74f23a66 100644 --- a/snippets/perf-next/index/perf_initialize.js +++ b/snippets/perf-next/index/perf_initialize_app.js @@ -4,7 +4,7 @@ // To update the snippets in this file, edit the source and then run // 'npm run snippets'. -// [START perf_initialize_modular] +// [START perf_initialize_app_modular] // TODO: Replace the following with your app's Firebase project configuration // See: https://firebase.google.com/docs/web/setup#config-object const firebaseConfig = { @@ -12,8 +12,5 @@ const firebaseConfig = { }; // Initialize Firebase -const app = initializeApp(firebaseConfig); - -// Initialize Performance Monitoring and get a reference to the service -const perf = getPerformance(app); -// [END perf_initialize_modular] \ No newline at end of file +initializeApp(firebaseConfig); +// [END perf_initialize_app_modular] \ No newline at end of file diff --git a/snippets/perf-next/index/perf_singleton.js b/snippets/perf-next/index/perf_singleton.js new file mode 100644 index 00000000..38ccb439 --- /dev/null +++ b/snippets/perf-next/index/perf_singleton.js @@ -0,0 +1,10 @@ +// This snippet file was generated by processing the source file: +// ./perf-next/index.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START perf_singleton_modular] +// Initialize Performance Monitoring and get a reference to the service +const perf = getPerformance(); +// [END perf_singleton_modular] \ No newline at end of file From 3b929e7ac15a1cb6d363a7fe85f2ba2bb09fae87 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 19 Aug 2021 07:38:34 -0700 Subject: [PATCH 185/235] Auto-update dependencies. (#225) --- auth/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/package.json b/auth/package.json index d8178118..3dddb07e 100644 --- a/auth/package.json +++ b/auth/package.json @@ -7,6 +7,6 @@ "license": "Apache 2.0", "dependencies": { "firebase": "^8.9.1", - "firebaseui": "^4.8.1" + "firebaseui": "^5.0.0" } } From 17620db63cdef986b41b020fccc7bb98f9890858 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 20 Aug 2021 20:40:05 +0100 Subject: [PATCH 186/235] Multiproject snippets (#228) --- firebaseapp-next/firebaseapp.js | 58 +++++++++++++++++++ firebaseapp/firebaseapp.js | 54 ++++++++++++++++- .../firebaseapp/app_default_init_options.js | 24 ++++++++ .../app_multi_project_init_options.js | 28 +++++++++ 4 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 snippets/firebaseapp-next/firebaseapp/app_default_init_options.js create mode 100644 snippets/firebaseapp-next/firebaseapp/app_multi_project_init_options.js diff --git a/firebaseapp-next/firebaseapp.js b/firebaseapp-next/firebaseapp.js index 8bd6838f..54aa3137 100644 --- a/firebaseapp-next/firebaseapp.js +++ b/firebaseapp-next/firebaseapp.js @@ -25,3 +25,61 @@ function multpleFirebaseApps() { // getDatabase(secondaryApp) // [END firebase_secondary] } + +function defaultInitOptions() { + const firebaseConfig = { + // ... + }; + + // [START app_default_init_options] + const { initializeApp } = require("firebase/app"); + const { getStorage } = require("firebase/storage"); + const { getFirestore } = require("firebase/firestore"); + + // Initialize Firebase with a "default" Firebase project + const defaultProject = initializeApp(firebaseConfig); + + console.log(defaultProject.name); // "[DEFAULT]" + + // Option 1: Access Firebase services via the defaultProject variable + let defaultStorage = getStorage(defaultProject); + let defaultFirestore = getFirestore(defaultProject); + + // Option 2: Access Firebase services using shorthand notation + defaultStorage = getStorage(); + defaultFirestore = getFirestore(); + // [END app_default_init_options] +} + +function multiProjectInitOptions() { + const firebaseConfig = { + // ... + }; + + const otherProjectFirebaseConfig = { + // ... + }; + + // [START app_multi_project_init_options] + const { initializeApp, getApp } = require("firebase/app"); + const { getStorage } = require("firebase/storage"); + const { getFirestore } = require("firebase/firestore"); + + // Initialize Firebase with a default Firebase project + initializeApp(firebaseConfig); + + // Initialize Firebase with a second Firebase project + const otherProject = initializeApp(otherProjectFirebaseConfig, "other"); + + console.log(getApp().name); // "[DEFAULT]" + console.log(otherProject.name); // "otherProject" + + // Use the shorthand notation to access the default project's Firebase services + const defaultStorage = getStorage(); + const defaultFirestore = getFirestore(); + + // Use the otherProject variable to access the second project's Firebase services + const otherStorage = getStorage(otherProject); + const otherFirestore = getFirestore(otherProject); + // [END app_multi_project_init_options] +} diff --git a/firebaseapp/firebaseapp.js b/firebaseapp/firebaseapp.js index 88eedd46..e030583f 100644 --- a/firebaseapp/firebaseapp.js +++ b/firebaseapp/firebaseapp.js @@ -6,7 +6,7 @@ function multpleFirebaseApps() { // - Project ID // - App ID // - API Key - var secondaryAppConfig = { + const secondaryAppConfig = { projectId: "", appId: "", apiKey: "", @@ -17,8 +17,58 @@ function multpleFirebaseApps() { // [START firebase_secondary] // Initialize another app with a different config - var secondaryApp = firebase.initializeApp(secondaryAppConfig, "secondary"); + const secondaryApp = firebase.initializeApp(secondaryAppConfig, "secondary"); // Access services, such as the Realtime Database // secondaryApp.database(); // [END firebase_secondary] } + +function defaultInitOptions() { + const firebaseConfig = { + // ... + }; + + // [START app_default_init_options] + // Initialize Firebase with a "default" Firebase project + const defaultProject = firebase.initializeApp(firebaseConfig); + + console.log(defaultProject.name); // "[DEFAULT]" + + // Option 1: Access Firebase services via the defaultProject variable + let defaultStorage = defaultProject.storage(); + let defaultFirestore = defaultProject.firestore(); + + // Option 2: Access Firebase services using shorthand notation + defaultStorage = firebase.storage(); + defaultFirestore = firebase.firestore(); + // [END app_default_init_options] +} + +function multiProjectInitOptions() { + const firebaseConfig = { + // ... + }; + + const otherProjectFirebaseConfig = { + // ... + }; + + // [START app_multi_project_init_options] + // Initialize Firebase with a default Firebase project + firebase.initializeApp(firebaseConfig); + + // Initialize Firebase with a second Firebase project + const otherProject = firebase.initializeApp(otherProjectFirebaseConfig, "other"); + + console.log(firebase.app().name); // "[DEFAULT]" + console.log(otherProject.name); // "otherProject" + + // Use the shorthand notation to access the default project's Firebase services + const defaultStorage = firebase.storage(); + const defaultFirestore = firebase.firestore(); + + // Use the otherProject variable to access the second project's Firebase services + const otherStorage = otherProject.storage(); + const otherFirestore = otherProject.firestore(); + // [END app_multi_project_init_options] +} diff --git a/snippets/firebaseapp-next/firebaseapp/app_default_init_options.js b/snippets/firebaseapp-next/firebaseapp/app_default_init_options.js new file mode 100644 index 00000000..7cebaaf3 --- /dev/null +++ b/snippets/firebaseapp-next/firebaseapp/app_default_init_options.js @@ -0,0 +1,24 @@ +// This snippet file was generated by processing the source file: +// ./firebaseapp-next/firebaseapp.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START app_default_init_options_modular] +import { initializeApp } from "firebase/app"; +import { getStorage } from "firebase/storage"; +import { getFirestore } from "firebase/firestore"; + +// Initialize Firebase with a "default" Firebase project +const defaultProject = initializeApp(firebaseConfig); + +console.log(defaultProject.name); // "[DEFAULT]" + +// Option 1: Access Firebase services via the defaultProject variable +let defaultStorage = getStorage(defaultProject); +let defaultFirestore = getFirestore(defaultProject); + +// Option 2: Access Firebase services using shorthand notation +defaultStorage = getStorage(); +defaultFirestore = getFirestore(); +// [END app_default_init_options_modular] \ No newline at end of file diff --git a/snippets/firebaseapp-next/firebaseapp/app_multi_project_init_options.js b/snippets/firebaseapp-next/firebaseapp/app_multi_project_init_options.js new file mode 100644 index 00000000..415f8813 --- /dev/null +++ b/snippets/firebaseapp-next/firebaseapp/app_multi_project_init_options.js @@ -0,0 +1,28 @@ +// This snippet file was generated by processing the source file: +// ./firebaseapp-next/firebaseapp.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START app_multi_project_init_options_modular] +import { initializeApp, getApp } from "firebase/app"; +import { getStorage } from "firebase/storage"; +import { getFirestore } from "firebase/firestore"; + +// Initialize Firebase with a default Firebase project +initializeApp(firebaseConfig); + +// Initialize Firebase with a second Firebase project +const otherProject = initializeApp(otherProjectFirebaseConfig, "other"); + +console.log(getApp().name); // "[DEFAULT]" +console.log(otherProject.name); // "otherProject" + +// Use the shorthand notation to access the default project's Firebase services +const defaultStorage = getStorage(); +const defaultFirestore = getFirestore(); + +// Use the otherProject variable to access the second project's Firebase services +const otherStorage = getStorage(otherProject); +const otherFirestore = getFirestore(otherProject); +// [END app_multi_project_init_options_modular] \ No newline at end of file From c14985f96b28797b53c8b4ac09da9e34666b2279 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 23 Aug 2021 06:41:39 -0700 Subject: [PATCH 187/235] Auto-update dependencies. (#226) --- analytics/package.json | 2 +- appcheck/package.json | 2 +- auth/package.json | 2 +- database/package.json | 2 +- firebaseapp/package.json | 2 +- firestore/package.json | 2 +- functions/package.json | 2 +- installations/package.json | 2 +- messaging/package.json | 2 +- perf/package.json | 2 +- remoteconfig/package.json | 2 +- storage/package.json | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/analytics/package.json b/analytics/package.json index 9f18a1f0..b344a8a6 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.9.1" + "firebase": "^8.10.0" } } diff --git a/appcheck/package.json b/appcheck/package.json index d1f53982..d9d819fa 100644 --- a/appcheck/package.json +++ b/appcheck/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.9.1" + "firebase": "^8.10.0" } } diff --git a/auth/package.json b/auth/package.json index 3dddb07e..a6827027 100644 --- a/auth/package.json +++ b/auth/package.json @@ -6,7 +6,7 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.9.1", + "firebase": "^8.10.0", "firebaseui": "^5.0.0" } } diff --git a/database/package.json b/database/package.json index 728b0f7a..ea21b973 100644 --- a/database/package.json +++ b/database/package.json @@ -6,6 +6,6 @@ }, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.9.1" + "firebase": "^8.10.0" } } diff --git a/firebaseapp/package.json b/firebaseapp/package.json index dfe2745d..5226e2a0 100644 --- a/firebaseapp/package.json +++ b/firebaseapp/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.9.1" + "firebase": "^8.10.0" } } diff --git a/firestore/package.json b/firestore/package.json index e91ee858..73bbb88c 100644 --- a/firestore/package.json +++ b/firestore/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.9.1", + "firebase": "^8.10.0", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions/package.json b/functions/package.json index 9861def8..653086c9 100644 --- a/functions/package.json +++ b/functions/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.9.1" + "firebase": "^8.10.0" } } diff --git a/installations/package.json b/installations/package.json index c8cb6019..1395fca3 100644 --- a/installations/package.json +++ b/installations/package.json @@ -4,6 +4,6 @@ "scripts": {}, "license": "Apache 2.0", "dependencies": { - "firebase": "^8.9.1" + "firebase": "^8.10.0" } } diff --git a/messaging/package.json b/messaging/package.json index a20a9ff1..96a5720d 100644 --- a/messaging/package.json +++ b/messaging/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.9.1" + "firebase": "^8.10.0" } } diff --git a/perf/package.json b/perf/package.json index c30e4855..61906b8e 100644 --- a/perf/package.json +++ b/perf/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.9.1" + "firebase": "^8.10.0" } } diff --git a/remoteconfig/package.json b/remoteconfig/package.json index 1d1da529..8437cbd2 100644 --- a/remoteconfig/package.json +++ b/remoteconfig/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.9.1" + "firebase": "^8.10.0" } } diff --git a/storage/package.json b/storage/package.json index 76392f55..e27166e7 100644 --- a/storage/package.json +++ b/storage/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^8.9.1" + "firebase": "^8.10.0" } } From b9d79df57c4add61ad92995e6e73ba744280af28 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 23 Aug 2021 06:44:47 -0700 Subject: [PATCH 188/235] Auto-update dependencies. (#227) --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index bc24d2b8..ddc3c44d 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 9b768ff4..3b2f7de0 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.9.1/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.9.1/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 81fcf30888909936d4898421e858da809f8cf595 Mon Sep 17 00:00:00 2001 From: rachelsaunders <52258509+rachelsaunders@users.noreply.github.com> Date: Mon, 23 Aug 2021 17:07:10 -0400 Subject: [PATCH 189/235] [perf] make initialize & get singleton lines more explicit for vNext (#229) --- perf-next/index.js | 6 +++--- perf/index.js | 2 +- snippets/perf-next/index/perf_initialize_app.js | 4 ++-- snippets/perf-next/index/perf_singleton.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/perf-next/index.js b/perf-next/index.js index 83fce95c..e41aa1b0 100644 --- a/perf-next/index.js +++ b/perf-next/index.js @@ -13,18 +13,18 @@ function intialize() { // [START perf_initialize_app] // TODO: Replace the following with your app's Firebase project configuration - // See: https://firebase.google.com/docs/web/setup#config-object + // See: https://firebase.google.com/docs/web/learn-more#config-object const firebaseConfig = { // ... }; // Initialize Firebase - initializeApp(firebaseConfig); + const app = initializeApp(firebaseConfig); // [END perf_initialize_app] // [START perf_singleton] // Initialize Performance Monitoring and get a reference to the service - const perf = getPerformance(); + const perf = getPerformance(app); // [END perf_singleton] } diff --git a/perf/index.js b/perf/index.js index d1d61202..c5ae8b22 100644 --- a/perf/index.js +++ b/perf/index.js @@ -10,7 +10,7 @@ const perf = firebase.performance(); function intialize() { // [START perf_initialize_app] // TODO: Replace the following with your app's Firebase project configuration - // See: https://firebase.google.com/docs/web/setup#config-object + // See: https://firebase.google.com/docs/web/learn-more#config-object const firebaseConfig = { // ... }; diff --git a/snippets/perf-next/index/perf_initialize_app.js b/snippets/perf-next/index/perf_initialize_app.js index 74f23a66..94e0c966 100644 --- a/snippets/perf-next/index/perf_initialize_app.js +++ b/snippets/perf-next/index/perf_initialize_app.js @@ -6,11 +6,11 @@ // [START perf_initialize_app_modular] // TODO: Replace the following with your app's Firebase project configuration -// See: https://firebase.google.com/docs/web/setup#config-object +// See: https://firebase.google.com/docs/web/learn-more#config-object const firebaseConfig = { // ... }; // Initialize Firebase -initializeApp(firebaseConfig); +const app = initializeApp(firebaseConfig); // [END perf_initialize_app_modular] \ No newline at end of file diff --git a/snippets/perf-next/index/perf_singleton.js b/snippets/perf-next/index/perf_singleton.js index 38ccb439..e070b52b 100644 --- a/snippets/perf-next/index/perf_singleton.js +++ b/snippets/perf-next/index/perf_singleton.js @@ -6,5 +6,5 @@ // [START perf_singleton_modular] // Initialize Performance Monitoring and get a reference to the service -const perf = getPerformance(); +const perf = getPerformance(app); // [END perf_singleton_modular] \ No newline at end of file From 5371e900366afbd9fae7352f4be05250ab95966c Mon Sep 17 00:00:00 2001 From: Jeff <3759507+jhuleatt@users.noreply.github.com> Date: Tue, 7 Sep 2021 14:13:52 -0400 Subject: [PATCH 190/235] Update build tools and upgrade CI to node 14 (#237) --- .github/workflows/test.yml | 2 +- package.json | 10 +++++----- scripts/separate-snippets.ts | 7 +++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3eddc3bd..ee2c87f1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: node-version: - - 12.x + - 14.x steps: - uses: actions/checkout@v1 - uses: actions/setup-node@v1 diff --git a/package.json b/package.json index e7621ce2..cb7d9157 100644 --- a/package.json +++ b/package.json @@ -10,11 +10,11 @@ }, "license": "Apache-2.0", "devDependencies": { - "@types/node": "^15.12.2", - "eslint": "^7.16.0", - "pnpm": "^6.7.4", + "@types/node": "^16.7.10", + "eslint": "^7.32.0", + "pnpm": "^6.14.6", "rimraf": "^3.0.2", - "ts-node": "^9.0.0", - "typescript": "^3.8.3" + "ts-node": "^10.2.1", + "typescript": "^4.4.2" } } diff --git a/scripts/separate-snippets.ts b/scripts/separate-snippets.ts index 86821383..ff93a58f 100644 --- a/scripts/separate-snippets.ts +++ b/scripts/separate-snippets.ts @@ -171,12 +171,15 @@ function collectSnippets(filePath: string): SnippetsConfig { const suffixLine = lines.find((l) => !!l.match(RE_SNIPPETS_SUFFIX)); if (suffixLine) { const m = suffixLine.match(RE_SNIPPETS_SUFFIX); - config.suffix = m[1]; + + if (m && m[1]) { + config.suffix = m[1]; + } } // A temporary array holding the names of snippets we're currently within. // This allows for handling nested snippets. - let inSnippetNames = []; + let inSnippetNames: string[] = []; for (const line of lines) { const startMatch = line.match(RE_START_SNIPPET); From ea048bf1d3b845f9497fdddca82e4db8eee99d81 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Tue, 7 Sep 2021 19:17:08 +0100 Subject: [PATCH 191/235] Move to v9 stable release (#234) --- analytics-next/package.json | 2 +- appcheck-next/package.json | 2 +- auth-next/package.json | 2 +- database-next/package.json | 2 +- firebaseapp-next/package.json | 2 +- firestore-next/package.json | 2 +- functions-next/package.json | 2 +- messaging-next/package.json | 2 +- perf-next/package.json | 2 +- remoteconfig-next/package.json | 2 +- storage-next/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index 94d9a07e..6dd68b8a 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.8" + "firebase": "^9.0.0" } } diff --git a/appcheck-next/package.json b/appcheck-next/package.json index 9a7a71bb..ad511f74 100644 --- a/appcheck-next/package.json +++ b/appcheck-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.8" + "firebase": "^9.0.0" } } diff --git a/auth-next/package.json b/auth-next/package.json index 68d38869..4f5685b2 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.8" + "firebase": "^9.0.0" } } diff --git a/database-next/package.json b/database-next/package.json index 1c21a0e6..47fb5f09 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.8" + "firebase": "^9.0.0" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index 4eec0161..d4426033 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.8" + "firebase": "^9.0.0" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index f15f2ed0..38b07b6d 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.8", + "firebase": "^9.0.0", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/package.json b/functions-next/package.json index 8e0e6422..73194f1c 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.8" + "firebase": "^9.0.0" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index 2137e3e2..b4ad1c0f 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.8" + "firebase": "^9.0.0" } } diff --git a/perf-next/package.json b/perf-next/package.json index 9321e3c8..70f81332 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.8" + "firebase": "^9.0.0" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index 6f8e1636..2f3e3350 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.8" + "firebase": "^9.0.0" } } diff --git a/storage-next/package.json b/storage-next/package.json index 6aca1112..3032a7e9 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0-beta.8" + "firebase": "^9.0.0" } } From 2b9c3212d3844d394f8d98f30cadc03fdef8c2f5 Mon Sep 17 00:00:00 2001 From: Jeff <3759507+jhuleatt@users.noreply.github.com> Date: Tue, 7 Sep 2021 14:23:21 -0400 Subject: [PATCH 192/235] [messaging] Change import in service worker (#224) --- messaging-next/service-worker.js | 2 +- snippets/messaging-next/service-worker/messaging_init_in_sw.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/messaging-next/service-worker.js b/messaging-next/service-worker.js index ce0ac6b8..a81a7c18 100644 --- a/messaging-next/service-worker.js +++ b/messaging-next/service-worker.js @@ -16,7 +16,7 @@ let self; function initInSw() { // [START messaging_init_in_sw] const { initializeApp } = require("firebase/app"); - const { getMessaging } = require("firebase/messaging"); + const { getMessaging } = require("firebase/messaging/sw"); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. diff --git a/snippets/messaging-next/service-worker/messaging_init_in_sw.js b/snippets/messaging-next/service-worker/messaging_init_in_sw.js index abce8e1d..42f0f526 100644 --- a/snippets/messaging-next/service-worker/messaging_init_in_sw.js +++ b/snippets/messaging-next/service-worker/messaging_init_in_sw.js @@ -6,7 +6,7 @@ // [START messaging_init_in_sw_modular] import { initializeApp } from "firebase/app"; -import { getMessaging } from "firebase/messaging"; +import { getMessaging } from "firebase/messaging/sw"; // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 1e8f41c904d557f486cdab2a1401ec5f6033dc39 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Wed, 22 Sep 2021 05:19:15 -0700 Subject: [PATCH 193/235] Auto-update dependencies. (#232) * Auto-update dependencies. * switch to compat Co-authored-by: Jeff <3759507+jhuleatt@users.noreply.github.com> --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index ddc3c44d..34d7708d 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 3b2f7de0..38628112 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/9.0.2/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From d5241e7ae8b9c015a03f2822c490bfe8b107d2f2 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 30 Sep 2021 13:00:16 -0700 Subject: [PATCH 194/235] Auto-update dependencies. (#239) * Auto-update dependencies. * move legacy back to v8 Co-authored-by: Jeff <3759507+jhuleatt@users.noreply.github.com> --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index 34d7708d..ddc3c44d 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 38628112..3b2f7de0 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/9.0.2/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 50d5bdce71c1495104199f18d83a03c13f4bf190 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 30 Sep 2021 13:06:16 -0700 Subject: [PATCH 195/235] Auto-update dependencies. (#231) * Auto-update dependencies. * keep all non-next folders on 8 Co-authored-by: Jeff <3759507+jhuleatt@users.noreply.github.com> --- analytics-next/package.json | 2 +- appcheck-next/package.json | 2 +- auth-next/package.json | 2 +- database-next/package.json | 2 +- firebaseapp-next/package.json | 2 +- firestore-next/package.json | 2 +- functions-next/package.json | 2 +- messaging-next/package.json | 2 +- perf-next/package.json | 2 +- remoteconfig-next/package.json | 2 +- storage-next/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index 6dd68b8a..d0955d16 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0" + "firebase": "^9.1.0" } } diff --git a/appcheck-next/package.json b/appcheck-next/package.json index ad511f74..7c84b7df 100644 --- a/appcheck-next/package.json +++ b/appcheck-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0" + "firebase": "^9.1.0" } } diff --git a/auth-next/package.json b/auth-next/package.json index 4f5685b2..53d964a2 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0" + "firebase": "^9.1.0" } } diff --git a/database-next/package.json b/database-next/package.json index 47fb5f09..175d6c63 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0" + "firebase": "^9.1.0" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index d4426033..88dd8954 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0" + "firebase": "^9.1.0" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 38b07b6d..2c95f580 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0", + "firebase": "^9.1.0", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/package.json b/functions-next/package.json index 73194f1c..4ddfe8c3 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0" + "firebase": "^9.1.0" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index b4ad1c0f..fe28f50e 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0" + "firebase": "^9.1.0" } } diff --git a/perf-next/package.json b/perf-next/package.json index 70f81332..69cf753b 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0" + "firebase": "^9.1.0" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index 2f3e3350..8a072847 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0" + "firebase": "^9.1.0" } } diff --git a/storage-next/package.json b/storage-next/package.json index 3032a7e9..fbce56ec 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.0.0" + "firebase": "^9.1.0" } } From dc8dcdd5148aa14cf59c8fbcb3c1c2476f7a3643 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 1 Oct 2021 12:27:04 -0700 Subject: [PATCH 196/235] Add snippets for custom dependencies doc (#243) * Snippets for custom dependencies doc * Add app dependency --- auth-next/custom-dependencies.js | 58 +++++++++++++++++++ .../auth_get_auth_equivalent.js | 16 +++++ .../auth_only_browser_local.js | 16 +++++ .../auth_only_indexed_db.js | 16 +++++ .../auth_sign_in_redirect_manual_deps.js | 18 ++++++ 5 files changed, 124 insertions(+) create mode 100644 auth-next/custom-dependencies.js create mode 100644 snippets/auth-next/custom-dependencies/auth_get_auth_equivalent.js create mode 100644 snippets/auth-next/custom-dependencies/auth_only_browser_local.js create mode 100644 snippets/auth-next/custom-dependencies/auth_only_indexed_db.js create mode 100644 snippets/auth-next/custom-dependencies/auth_sign_in_redirect_manual_deps.js diff --git a/auth-next/custom-dependencies.js b/auth-next/custom-dependencies.js new file mode 100644 index 00000000..209b6767 --- /dev/null +++ b/auth-next/custom-dependencies.js @@ -0,0 +1,58 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/custom-dependencies.md + +function getAuthEquivalent() { + // [START auth_get_auth_equivalent] + const {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, browserSessionPersistence, indexedDBLocalPersistence} = require("firebase/auth"); + const {initializeApp} = require("firebase/app"); + + const app = initializeApp({/** Your app config */}); + const auth = initializeAuth(app, { + persistence: [indexedDBLocalPersistence, browserLocalPersistence, browserSessionPersistence], + popupRedirectResolver: browserPopupRedirectResolver, + }); + // [END auth_get_auth_equivalent] +} + +function onlyBrowserLocal() { + // [START auth_only_browser_local] + const {initializeAuth, browserLocalPersistence} = require("firebase/auth"); + const {initializeApp} = require("firebase/app"); + + const app = initializeApp({/** Your app config */}); + const auth = initializeAuth(app, { + persistence: browserLocalPersistence, + // No popupRedirectResolver defined + }); + // [END auth_only_browser_local] +} + +function onlyIndexedDB() { + // [START auth_only_indexed_db] + const {initializeAuth, indexedDBLocalPersistence} = require("firebase/auth"); + const {initializeApp} = require("firebase/app"); + + const app = initializeApp({/** Your app config */}); + const auth = initializeAuth(app, { + persistence: indexedDBLocalPersistence, + // No popupRedirectResolver defined + }); + // [END auth_only_indexed_db] +} + +function signInRedirectManualDeps() { + // [START auth_sign_in_redirect_manual_deps] + const {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, indexedDBLocalPersistence, signInWithRedirect, GoogleAuthProvider} = require("firebase/auth"); + const {initializeApp} = require("firebase/app"); + + const app = initializeApp({/** Your app config */}); + const auth = initializeAuth(app, { + persistence: [indexedDBLocalPersistence, browserLocalPersistence], + }); + + // Later + signInWithRedirect(auth, new GoogleAuthProvider(), browserPopupRedirectResolver); + // [END auth_sign_in_redirect_manual_deps] +} \ No newline at end of file diff --git a/snippets/auth-next/custom-dependencies/auth_get_auth_equivalent.js b/snippets/auth-next/custom-dependencies/auth_get_auth_equivalent.js new file mode 100644 index 00000000..37292487 --- /dev/null +++ b/snippets/auth-next/custom-dependencies/auth_get_auth_equivalent.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/custom-dependencies.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_get_auth_equivalent_modular] +import {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, browserSessionPersistence, indexedDBLocalPersistence} from "firebase/auth"; +import {initializeApp} from "firebase/app"; + +const app = initializeApp({/** Your app config */}); +const auth = initializeAuth(app, { + persistence: [indexedDBLocalPersistence, browserLocalPersistence, browserSessionPersistence], + popupRedirectResolver: browserPopupRedirectResolver, +}); +// [END auth_get_auth_equivalent_modular] \ No newline at end of file diff --git a/snippets/auth-next/custom-dependencies/auth_only_browser_local.js b/snippets/auth-next/custom-dependencies/auth_only_browser_local.js new file mode 100644 index 00000000..549307ac --- /dev/null +++ b/snippets/auth-next/custom-dependencies/auth_only_browser_local.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/custom-dependencies.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_only_browser_local_modular] +import {initializeAuth, browserLocalPersistence} from "firebase/auth"; +import {initializeApp} from "firebase/app"; + +const app = initializeApp({/** Your app config */}); +const auth = initializeAuth(app, { + persistence: browserLocalPersistence, + // No popupRedirectResolver defined +}); +// [END auth_only_browser_local_modular] \ No newline at end of file diff --git a/snippets/auth-next/custom-dependencies/auth_only_indexed_db.js b/snippets/auth-next/custom-dependencies/auth_only_indexed_db.js new file mode 100644 index 00000000..1427ae6b --- /dev/null +++ b/snippets/auth-next/custom-dependencies/auth_only_indexed_db.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/custom-dependencies.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_only_indexed_db_modular] +import {initializeAuth, indexedDBLocalPersistence} from "firebase/auth"; +import {initializeApp} from "firebase/app"; + +const app = initializeApp({/** Your app config */}); +const auth = initializeAuth(app, { + persistence: indexedDBLocalPersistence, + // No popupRedirectResolver defined +}); +// [END auth_only_indexed_db_modular] \ No newline at end of file diff --git a/snippets/auth-next/custom-dependencies/auth_sign_in_redirect_manual_deps.js b/snippets/auth-next/custom-dependencies/auth_sign_in_redirect_manual_deps.js new file mode 100644 index 00000000..75fd0d5d --- /dev/null +++ b/snippets/auth-next/custom-dependencies/auth_sign_in_redirect_manual_deps.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/custom-dependencies.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_sign_in_redirect_manual_deps_modular] +import {initializeAuth, browserLocalPersistence, browserPopupRedirectResolver, indexedDBLocalPersistence, signInWithRedirect, GoogleAuthProvider} from "firebase/auth"; +import {initializeApp} from "firebase/app"; + +const app = initializeApp({/** Your app config */}); +const auth = initializeAuth(app, { + persistence: [indexedDBLocalPersistence, browserLocalPersistence], +}); + +// Later +signInWithRedirect(auth, new GoogleAuthProvider(), browserPopupRedirectResolver); +// [END auth_sign_in_redirect_manual_deps_modular] \ No newline at end of file From fdc51dd76f7c8f31d107b2dc27100c28e0318431 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 5 Oct 2021 10:51:03 -0700 Subject: [PATCH 197/235] Fix import path for Cordova (#240) --- auth-next/cordova.js | 6 +++--- snippets/auth-next/cordova/auth_cordova_redirect_result.js | 2 +- snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js | 2 +- snippets/auth-next/cordova/auth_create_google_provider.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/auth-next/cordova.js b/auth-next/cordova.js index 1823b33c..ff91dfcc 100644 --- a/auth-next/cordova.js +++ b/auth-next/cordova.js @@ -5,7 +5,7 @@ function createGoogleProvider() { // [START auth_create_google_provider] - const { GoogleAuthProvider } = require("firebase/auth"); + const { GoogleAuthProvider } = require("firebase/auth/cordova"); const provider = new GoogleAuthProvider(); // [END auth_create_google_provider] @@ -13,7 +13,7 @@ function createGoogleProvider() { function cordovaSignInRedirect() { // [START auth_cordova_sign_in_redirect] - const { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } = require("firebase/auth"); + const { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } = require("firebase/auth/cordova"); const auth = getAuth(); signInWithRedirect(auth, new GoogleAuthProvider()) @@ -40,7 +40,7 @@ function cordovaSignInRedirect() { function cordovaRedirectResult() { // [START auth_cordova_redirect_result] - const { getAuth, getRedirectResult, GoogleAuthProvider } = require("firebase/auth"); + const { getAuth, getRedirectResult, GoogleAuthProvider } = require("firebase/auth/cordova"); const auth = getAuth(); getRedirectResult(auth) diff --git a/snippets/auth-next/cordova/auth_cordova_redirect_result.js b/snippets/auth-next/cordova/auth_cordova_redirect_result.js index 7bcc69a3..f1c87596 100644 --- a/snippets/auth-next/cordova/auth_cordova_redirect_result.js +++ b/snippets/auth-next/cordova/auth_cordova_redirect_result.js @@ -5,7 +5,7 @@ // 'npm run snippets'. // [START auth_cordova_redirect_result_modular] -import { getAuth, getRedirectResult, GoogleAuthProvider } from "firebase/auth"; +import { getAuth, getRedirectResult, GoogleAuthProvider } from "firebase/auth/cordova"; const auth = getAuth(); getRedirectResult(auth) diff --git a/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js b/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js index 5aaee22d..ed3cc8d1 100644 --- a/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js +++ b/snippets/auth-next/cordova/auth_cordova_sign_in_redirect.js @@ -5,7 +5,7 @@ // 'npm run snippets'. // [START auth_cordova_sign_in_redirect_modular] -import { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } from "firebase/auth"; +import { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } from "firebase/auth/cordova"; const auth = getAuth(); signInWithRedirect(auth, new GoogleAuthProvider()) diff --git a/snippets/auth-next/cordova/auth_create_google_provider.js b/snippets/auth-next/cordova/auth_create_google_provider.js index aab60312..fcf96401 100644 --- a/snippets/auth-next/cordova/auth_create_google_provider.js +++ b/snippets/auth-next/cordova/auth_create_google_provider.js @@ -5,7 +5,7 @@ // 'npm run snippets'. // [START auth_create_google_provider_modular] -import { GoogleAuthProvider } from "firebase/auth"; +import { GoogleAuthProvider } from "firebase/auth/cordova"; const provider = new GoogleAuthProvider(); // [END auth_create_google_provider_modular] \ No newline at end of file From 5062c76ac28473ed47e87abf9369590c979ef088 Mon Sep 17 00:00:00 2001 From: Ian Tay Date: Fri, 15 Oct 2021 12:01:07 -0700 Subject: [PATCH 198/235] Add SAML provider snippets. (#246) * Add SAML provider snippets. This is a Google Cloud Identity Platform provider. * Add OIDC provider snippets. This is a Google Cloud Identity Platform provider. * add generated snippets --- auth-next/oidc.js | 96 +++++++++++++++++++ auth-next/saml.js | 68 +++++++++++++ auth/oidc.js | 71 ++++++++++++++ auth/saml.js | 56 +++++++++++ .../oidc/auth_oidc_direct_sign_in.js | 31 ++++++ .../oidc/auth_oidc_provider_create.js | 11 +++ .../auth-next/oidc/auth_oidc_signin_popup.js | 27 ++++++ .../oidc/auth_oidc_signin_redirect.js | 12 +++ .../oidc/auth_oidc_signin_redirect_result.js | 28 ++++++ .../saml/auth_saml_provider_create.js | 11 +++ .../auth-next/saml/auth_saml_signin_popup.js | 27 ++++++ .../saml/auth_saml_signin_redirect.js | 12 +++ .../saml/auth_saml_signin_redirect_result.js | 28 ++++++ .../auth/oidc/auth_oidc_direct_sign_in.js | 19 ++++ .../auth/oidc/auth_oidc_provider_create.js | 9 ++ snippets/auth/oidc/auth_oidc_signin_popup.js | 18 ++++ .../auth/oidc/auth_oidc_signin_redirect.js | 11 +++ .../oidc/auth_oidc_signin_redirect_result.js | 20 ++++ .../auth/saml/auth_saml_provider_create.js | 9 ++ snippets/auth/saml/auth_saml_signin_popup.js | 21 ++++ .../auth/saml/auth_saml_signin_redirect.js | 9 ++ .../saml/auth_saml_signin_redirect_result.js | 20 ++++ 22 files changed, 614 insertions(+) create mode 100644 auth-next/oidc.js create mode 100644 auth-next/saml.js create mode 100644 auth/oidc.js create mode 100644 auth/saml.js create mode 100644 snippets/auth-next/oidc/auth_oidc_direct_sign_in.js create mode 100644 snippets/auth-next/oidc/auth_oidc_provider_create.js create mode 100644 snippets/auth-next/oidc/auth_oidc_signin_popup.js create mode 100644 snippets/auth-next/oidc/auth_oidc_signin_redirect.js create mode 100644 snippets/auth-next/oidc/auth_oidc_signin_redirect_result.js create mode 100644 snippets/auth-next/saml/auth_saml_provider_create.js create mode 100644 snippets/auth-next/saml/auth_saml_signin_popup.js create mode 100644 snippets/auth-next/saml/auth_saml_signin_redirect.js create mode 100644 snippets/auth-next/saml/auth_saml_signin_redirect_result.js create mode 100644 snippets/auth/oidc/auth_oidc_direct_sign_in.js create mode 100644 snippets/auth/oidc/auth_oidc_provider_create.js create mode 100644 snippets/auth/oidc/auth_oidc_signin_popup.js create mode 100644 snippets/auth/oidc/auth_oidc_signin_redirect.js create mode 100644 snippets/auth/oidc/auth_oidc_signin_redirect_result.js create mode 100644 snippets/auth/saml/auth_saml_provider_create.js create mode 100644 snippets/auth/saml/auth_saml_signin_popup.js create mode 100644 snippets/auth/saml/auth_saml_signin_redirect.js create mode 100644 snippets/auth/saml/auth_saml_signin_redirect_result.js diff --git a/auth-next/oidc.js b/auth-next/oidc.js new file mode 100644 index 00000000..5dc20e81 --- /dev/null +++ b/auth-next/oidc.js @@ -0,0 +1,96 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +function oidcProvider() { + // [START auth_oidc_provider_create] + const { OAuthProvider } = require("firebase/auth"); + + const provider = new OAuthProvider("oidc.myProvider"); + // [END auth_oidc_provider_create] +} + +function oidcSignInPopup(provider) { + // [START auth_oidc_signin_popup] + const { getAuth, signInWithPopup, OAuthProvider } = require("firebase/auth"); + + const auth = getAuth(); + signInWithPopup(auth, provider) + .then((result) => { + // User is signed in. + const credential = OAuthProvider.credentialFromResult(result); + // This gives you an access token for the OIDC provider. You can use it to directly interact with that provider + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = OAuthProvider.credentialFromError(error); + // Handle / display error. + // ... + }); + // [END auth_oidc_signin_popup] +} + +function oidcSignInRedirect(provider) { + // [START auth_oidc_signin_redirect] + const { getAuth, signInWithRedirect } = require("firebase/auth"); + + const auth = getAuth(); + signInWithRedirect(auth, provider); + // [END auth_oidc_signin_redirect] +} + +function oidcSignInRedirectResult(provider) { + // [START auth_oidc_signin_redirect_result] + const { getAuth, getRedirectResult, OAuthProvider } = require("firebase/auth"); + + const auth = getAuth(); + getRedirectResult(auth) + .then((result) => { + // User is signed in. + const credential = OAuthProvider.credentialFromResult(result); + // This gives you an access token for the OIDC provider. You can use it to directly interact with that provider + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = OAuthProvider.credentialFromError(error); + // Handle / display error. + // ... + }); + // [END auth_oidc_signin_redirect_result] +} + +function oidcDirectSignIn(provider, oidcIdToken) { + // [START auth_oidc_direct_sign_in] + const { getAuth, OAuthProvider, signInWithCredential } = require("firebase/auth"); + + const auth = getAuth(); + const credential = provider.credential({ + idToken: oidcIdToken, + }); + signInWithCredential(auth, credential) + .then((result) => { + // User is signed in. + const newCredential = OAuthProvider.credentialFromResult(result); + // This gives you a new access token for the OIDC provider. You can use it to directly interact with that provider. + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = OAuthProvider.credentialFromError(error); + // Handle / display error. + // ... + }); + // [END auth_oidc_direct_sign_in] +} \ No newline at end of file diff --git a/auth-next/saml.js b/auth-next/saml.js new file mode 100644 index 00000000..9a5683d9 --- /dev/null +++ b/auth-next/saml.js @@ -0,0 +1,68 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +function samlProvider() { + // [START auth_saml_provider_create] + const { SAMLAuthProvider } = require("firebase/auth"); + + const provider = new SAMLAuthProvider("saml.myProvider"); + // [END auth_saml_provider_create] +} + +function samlSignInPopup(provider) { + // [START auth_saml_signin_popup] + const { getAuth, signInWithPopup, SAMLAuthProvider } = require("firebase/auth"); + + const auth = getAuth(); + signInWithPopup(auth, provider) + .then((result) => { + // User is signed in. + // Provider data available from the result.user.getIdToken() + // or from result.user.providerData + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = SAMLAuthProvider.credentialFromError(error); + // Handle / display error. + // ... + }); + // [END auth_saml_signin_popup] +} + +function samlSignInRedirect(provider) { + // [START auth_saml_signin_redirect] + const { getAuth, signInWithRedirect } = require("firebase/auth"); + + const auth = getAuth(); + signInWithRedirect(auth, provider); + // [END auth_saml_signin_redirect] +} + +function samlSignInRedirectResult(provider) { + // [START auth_saml_signin_redirect_result] + const { getAuth, getRedirectResult, SAMLAuthProvider } = require("firebase/auth"); + + const auth = getAuth(); + getRedirectResult(auth) + .then((result) => { + // User is signed in. + // Provider data available from the result.user.getIdToken() + // or from result.user.providerData + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = SAMLAuthProvider.credentialFromError(error); + // Handle / display error. + // ... + }); + // [END auth_saml_signin_redirect_result] +} \ No newline at end of file diff --git a/auth/oidc.js b/auth/oidc.js new file mode 100644 index 00000000..4c056e52 --- /dev/null +++ b/auth/oidc.js @@ -0,0 +1,71 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +function oidcProvider() { + // [START auth_oidc_provider_create] + const provider = new firebase.auth.OAuthProvider('oidc.myProvider'); + // [END auth_oidc_provider_create] +} + +function oidcSignInPopup(provider) { + // [START auth_oidc_signin_popup] + firebase.auth().signInWithPopup(provider) + .then((result) => { + // User is signed in. + // result.credential is a firebase.auth().OAuthCredential object. + // result.credential.providerId is equal to 'oidc.myProvider'. + // result.credential.idToken is the OIDC provider's ID token. + }) + .catch((error) => { + // Handle error. + }); + // [END auth_oidc_signin_popup] +} + +function oidcSignInRedirect(provider) { + // [START auth_oidc_signin_redirect] + firebase.auth().signInWithRedirect(provider).catch((error) => { + // Handle error. + }); + // [END auth_oidc_signin_redirect] +} + +function oidcSignInRedirectResult(provider) { + // [START auth_oidc_signin_redirect_result] + // On return. + firebase.auth().getRedirectResult() + .then((result) => { + // User is signed in. + // result.credential is a firebase.auth().OAuthCredential object. + // result.credential.providerId is equal to 'oidc.myProvider'. + // result.credential.idToken is the OIDC provider's ID token. + }) + .catch((error) => { + // Handle / display error. + // ... + }); + // [END auth_oidc_signin_redirect_result] +} + +function oidcDirectSignIn(provider, oidcIdToken) { + // [START auth_oidc_direct_sign_in] + const credential = provider.credential(oidcIdToken, null); + + firebase.auth().signInWithCredential(credential) + .then((result) => { + // User is signed in. + // User now has a odic.myProvider UserInfo in providerData. + }) + .catch((error) => { + // Handle / display error. + // ... + }); + // [END auth_oidc_direct_sign_in] +} + diff --git a/auth/saml.js b/auth/saml.js new file mode 100644 index 00000000..a55b691c --- /dev/null +++ b/auth/saml.js @@ -0,0 +1,56 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +function samlProvider() { + // [START auth_saml_provider_create] + const provider = new firebase.auth.SAMLAuthProvider('saml.myProvider'); + // [END auth_saml_provider_create] +} + +function samlSignInPopup(provider) { + // [START auth_saml_signin_popup] + firebase.auth().signInWithPopup(provider) + .then((result) => { + // User is signed in. + // Identity provider data available in result.additionalUserInfo.profile, + // or from the user's ID token obtained from result.user.getIdToken() + // as an object in the firebase.sign_in_attributes custom claim + // This is also available from result.user.getIdTokenResult() + // idTokenResult.claims.firebase.sign_in_attributes. + }) + .catch((error) => { + // Handle / display error. + // ... + }); + // [END auth_saml_signin_popup] +} + +function samlSignInRedirect(provider) { + // [START auth_saml_signin_redirect] + firebase.auth().signInWithRedirect(provider); + // [END auth_saml_signin_redirect] +} + +function samlSignInRedirectResult(provider) { + // [START auth_saml_signin_redirect_result] + firebase.auth().getRedirectResult() + .then((result) => { + // User is signed in. + // Provider data available in result.additionalUserInfo.profile, + // or from the user's ID token obtained from result.user.getIdToken() + // as an object in the firebase.sign_in_attributes custom claim + // This is also available from result.user.getIdTokenResult() + // idTokenResult.claims.firebase.sign_in_attributes. + }).catch((error) => { + // Handle / display error. + // ... + }); + // [END auth_saml_signin_redirect_result] +} + diff --git a/snippets/auth-next/oidc/auth_oidc_direct_sign_in.js b/snippets/auth-next/oidc/auth_oidc_direct_sign_in.js new file mode 100644 index 00000000..65f693a6 --- /dev/null +++ b/snippets/auth-next/oidc/auth_oidc_direct_sign_in.js @@ -0,0 +1,31 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/oidc.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_oidc_direct_sign_in_modular] +import { getAuth, OAuthProvider, signInWithCredential } from "firebase/auth"; + +const auth = getAuth(); +const credential = provider.credential({ + idToken: oidcIdToken, +}); +signInWithCredential(auth, credential) + .then((result) => { + // User is signed in. + const newCredential = OAuthProvider.credentialFromResult(result); + // This gives you a new access token for the OIDC provider. You can use it to directly interact with that provider. + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = OAuthProvider.credentialFromError(error); + // Handle / display error. + // ... + }); +// [END auth_oidc_direct_sign_in_modular] \ No newline at end of file diff --git a/snippets/auth-next/oidc/auth_oidc_provider_create.js b/snippets/auth-next/oidc/auth_oidc_provider_create.js new file mode 100644 index 00000000..ce1846b9 --- /dev/null +++ b/snippets/auth-next/oidc/auth_oidc_provider_create.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/oidc.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_oidc_provider_create_modular] +import { OAuthProvider } from "firebase/auth"; + +const provider = new OAuthProvider("oidc.myProvider"); +// [END auth_oidc_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth-next/oidc/auth_oidc_signin_popup.js b/snippets/auth-next/oidc/auth_oidc_signin_popup.js new file mode 100644 index 00000000..76b01b1d --- /dev/null +++ b/snippets/auth-next/oidc/auth_oidc_signin_popup.js @@ -0,0 +1,27 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/oidc.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_oidc_signin_popup_modular] +import { getAuth, signInWithPopup, OAuthProvider } from "firebase/auth"; + +const auth = getAuth(); +signInWithPopup(auth, provider) + .then((result) => { + // User is signed in. + const credential = OAuthProvider.credentialFromResult(result); + // This gives you an access token for the OIDC provider. You can use it to directly interact with that provider + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = OAuthProvider.credentialFromError(error); + // Handle / display error. + // ... + }); +// [END auth_oidc_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/oidc/auth_oidc_signin_redirect.js b/snippets/auth-next/oidc/auth_oidc_signin_redirect.js new file mode 100644 index 00000000..2038d116 --- /dev/null +++ b/snippets/auth-next/oidc/auth_oidc_signin_redirect.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/oidc.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_oidc_signin_redirect_modular] +import { getAuth, signInWithRedirect } from "firebase/auth"; + +const auth = getAuth(); +signInWithRedirect(auth, provider); +// [END auth_oidc_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/oidc/auth_oidc_signin_redirect_result.js b/snippets/auth-next/oidc/auth_oidc_signin_redirect_result.js new file mode 100644 index 00000000..ae5a441d --- /dev/null +++ b/snippets/auth-next/oidc/auth_oidc_signin_redirect_result.js @@ -0,0 +1,28 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/oidc.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_oidc_signin_redirect_result_modular] +import { getAuth, getRedirectResult, OAuthProvider } from "firebase/auth"; + +const auth = getAuth(); +getRedirectResult(auth) + .then((result) => { + // User is signed in. + const credential = OAuthProvider.credentialFromResult(result); + // This gives you an access token for the OIDC provider. You can use it to directly interact with that provider + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = OAuthProvider.credentialFromError(error); + // Handle / display error. + // ... + }); +// [END auth_oidc_signin_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth-next/saml/auth_saml_provider_create.js b/snippets/auth-next/saml/auth_saml_provider_create.js new file mode 100644 index 00000000..e492d490 --- /dev/null +++ b/snippets/auth-next/saml/auth_saml_provider_create.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/saml.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_saml_provider_create_modular] +import { SAMLAuthProvider } from "firebase/auth"; + +const provider = new SAMLAuthProvider("saml.myProvider"); +// [END auth_saml_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth-next/saml/auth_saml_signin_popup.js b/snippets/auth-next/saml/auth_saml_signin_popup.js new file mode 100644 index 00000000..8010a17b --- /dev/null +++ b/snippets/auth-next/saml/auth_saml_signin_popup.js @@ -0,0 +1,27 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/saml.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_saml_signin_popup_modular] +import { getAuth, signInWithPopup, SAMLAuthProvider } from "firebase/auth"; + +const auth = getAuth(); +signInWithPopup(auth, provider) + .then((result) => { + // User is signed in. + // Provider data available from the result.user.getIdToken() + // or from result.user.providerData + }).catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = SAMLAuthProvider.credentialFromError(error); + // Handle / display error. + // ... + }); +// [END auth_saml_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/saml/auth_saml_signin_redirect.js b/snippets/auth-next/saml/auth_saml_signin_redirect.js new file mode 100644 index 00000000..619af67f --- /dev/null +++ b/snippets/auth-next/saml/auth_saml_signin_redirect.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/saml.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_saml_signin_redirect_modular] +import { getAuth, signInWithRedirect } from "firebase/auth"; + +const auth = getAuth(); +signInWithRedirect(auth, provider); +// [END auth_saml_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/saml/auth_saml_signin_redirect_result.js b/snippets/auth-next/saml/auth_saml_signin_redirect_result.js new file mode 100644 index 00000000..4e4d4260 --- /dev/null +++ b/snippets/auth-next/saml/auth_saml_signin_redirect_result.js @@ -0,0 +1,28 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/saml.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_saml_signin_redirect_result_modular] +import { getAuth, getRedirectResult, SAMLAuthProvider } from "firebase/auth"; + +const auth = getAuth(); +getRedirectResult(auth) + .then((result) => { + // User is signed in. + // Provider data available from the result.user.getIdToken() + // or from result.user.providerData + }) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // The email of the user's account used. + const email = error.email; + // The AuthCredential type that was used. + const credential = SAMLAuthProvider.credentialFromError(error); + // Handle / display error. + // ... + }); +// [END auth_saml_signin_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth/oidc/auth_oidc_direct_sign_in.js b/snippets/auth/oidc/auth_oidc_direct_sign_in.js new file mode 100644 index 00000000..5a0c629d --- /dev/null +++ b/snippets/auth/oidc/auth_oidc_direct_sign_in.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./auth/oidc.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_oidc_direct_sign_in_modular] +const credential = provider.credential(oidcIdToken, null); + +firebase.auth().signInWithCredential(credential) + .then((result) => { + // User is signed in. + // User now has a odic.myProvider UserInfo in providerData. + }) + .catch((error) => { + // Handle / display error. + // ... + }); +// [END auth_oidc_direct_sign_in_modular] \ No newline at end of file diff --git a/snippets/auth/oidc/auth_oidc_provider_create.js b/snippets/auth/oidc/auth_oidc_provider_create.js new file mode 100644 index 00000000..09e08ad8 --- /dev/null +++ b/snippets/auth/oidc/auth_oidc_provider_create.js @@ -0,0 +1,9 @@ +// This snippet file was generated by processing the source file: +// ./auth/oidc.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_oidc_provider_create_modular] +const provider = new firebase.auth.OAuthProvider('oidc.myProvider'); +// [END auth_oidc_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth/oidc/auth_oidc_signin_popup.js b/snippets/auth/oidc/auth_oidc_signin_popup.js new file mode 100644 index 00000000..c5ff4afa --- /dev/null +++ b/snippets/auth/oidc/auth_oidc_signin_popup.js @@ -0,0 +1,18 @@ +// This snippet file was generated by processing the source file: +// ./auth/oidc.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_oidc_signin_popup_modular] +firebase.auth().signInWithPopup(provider) + .then((result) => { + // User is signed in. + // result.credential is a firebase.auth().OAuthCredential object. + // result.credential.providerId is equal to 'oidc.myProvider'. + // result.credential.idToken is the OIDC provider's ID token. + }) + .catch((error) => { + // Handle error. + }); +// [END auth_oidc_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth/oidc/auth_oidc_signin_redirect.js b/snippets/auth/oidc/auth_oidc_signin_redirect.js new file mode 100644 index 00000000..4951c4bf --- /dev/null +++ b/snippets/auth/oidc/auth_oidc_signin_redirect.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth/oidc.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_oidc_signin_redirect_modular] +firebase.auth().signInWithRedirect(provider).catch((error) => { + // Handle error. +}); +// [END auth_oidc_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth/oidc/auth_oidc_signin_redirect_result.js b/snippets/auth/oidc/auth_oidc_signin_redirect_result.js new file mode 100644 index 00000000..2cd0eaa7 --- /dev/null +++ b/snippets/auth/oidc/auth_oidc_signin_redirect_result.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./auth/oidc.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_oidc_signin_redirect_result_modular] +// On return. +firebase.auth().getRedirectResult() + .then((result) => { + // User is signed in. + // result.credential is a firebase.auth().OAuthCredential object. + // result.credential.providerId is equal to 'oidc.myProvider'. + // result.credential.idToken is the OIDC provider's ID token. + }) + .catch((error) => { + // Handle / display error. + // ... + }); +// [END auth_oidc_signin_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth/saml/auth_saml_provider_create.js b/snippets/auth/saml/auth_saml_provider_create.js new file mode 100644 index 00000000..a9765e5e --- /dev/null +++ b/snippets/auth/saml/auth_saml_provider_create.js @@ -0,0 +1,9 @@ +// This snippet file was generated by processing the source file: +// ./auth/saml.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_saml_provider_create_modular] +const provider = new firebase.auth.SAMLAuthProvider('saml.myProvider'); +// [END auth_saml_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth/saml/auth_saml_signin_popup.js b/snippets/auth/saml/auth_saml_signin_popup.js new file mode 100644 index 00000000..1fb3b4f6 --- /dev/null +++ b/snippets/auth/saml/auth_saml_signin_popup.js @@ -0,0 +1,21 @@ +// This snippet file was generated by processing the source file: +// ./auth/saml.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_saml_signin_popup_modular] +firebase.auth().signInWithPopup(provider) + .then((result) => { + // User is signed in. + // Identity provider data available in result.additionalUserInfo.profile, + // or from the user's ID token obtained from result.user.getIdToken() + // as an object in the firebase.sign_in_attributes custom claim + // This is also available from result.user.getIdTokenResult() + // idTokenResult.claims.firebase.sign_in_attributes. + }) + .catch((error) => { + // Handle / display error. + // ... + }); +// [END auth_saml_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth/saml/auth_saml_signin_redirect.js b/snippets/auth/saml/auth_saml_signin_redirect.js new file mode 100644 index 00000000..bd328a57 --- /dev/null +++ b/snippets/auth/saml/auth_saml_signin_redirect.js @@ -0,0 +1,9 @@ +// This snippet file was generated by processing the source file: +// ./auth/saml.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_saml_signin_redirect_modular] +firebase.auth().signInWithRedirect(provider); +// [END auth_saml_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth/saml/auth_saml_signin_redirect_result.js b/snippets/auth/saml/auth_saml_signin_redirect_result.js new file mode 100644 index 00000000..65a9f38b --- /dev/null +++ b/snippets/auth/saml/auth_saml_signin_redirect_result.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./auth/saml.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_saml_signin_redirect_result_modular] +firebase.auth().getRedirectResult() + .then((result) => { + // User is signed in. + // Provider data available in result.additionalUserInfo.profile, + // or from the user's ID token obtained from result.user.getIdToken() + // as an object in the firebase.sign_in_attributes custom claim + // This is also available from result.user.getIdTokenResult() + // idTokenResult.claims.firebase.sign_in_attributes. + }).catch((error) => { + // Handle / display error. + // ... + }); +// [END auth_saml_signin_redirect_result_modular] \ No newline at end of file From 20d5d980c84eb7f59547b3007dfb518098877248 Mon Sep 17 00:00:00 2001 From: Ian Tay Date: Fri, 15 Oct 2021 13:33:07 -0700 Subject: [PATCH 199/235] add initialization with custom domain code (#247) remove wrong tags (supposed to be for auth-next) --- auth-next/index.js | 16 +++++++++++++- auth/index.js | 11 ++++++++++ auth/oidc.js | 3 --- auth/saml.js | 3 --- .../index/auth_init_custom_domain.js | 17 +++++++++++++++ .../auth/oidc/auth_oidc_direct_sign_in.js | 19 ----------------- .../auth/oidc/auth_oidc_provider_create.js | 9 -------- snippets/auth/oidc/auth_oidc_signin_popup.js | 18 ---------------- .../auth/oidc/auth_oidc_signin_redirect.js | 11 ---------- .../oidc/auth_oidc_signin_redirect_result.js | 20 ------------------ .../auth/saml/auth_saml_provider_create.js | 9 -------- snippets/auth/saml/auth_saml_signin_popup.js | 21 ------------------- .../auth/saml/auth_saml_signin_redirect.js | 9 -------- .../saml/auth_saml_signin_redirect_result.js | 20 ------------------ 14 files changed, 43 insertions(+), 143 deletions(-) create mode 100644 snippets/auth-next/index/auth_init_custom_domain.js delete mode 100644 snippets/auth/oidc/auth_oidc_direct_sign_in.js delete mode 100644 snippets/auth/oidc/auth_oidc_provider_create.js delete mode 100644 snippets/auth/oidc/auth_oidc_signin_popup.js delete mode 100644 snippets/auth/oidc/auth_oidc_signin_redirect.js delete mode 100644 snippets/auth/oidc/auth_oidc_signin_redirect_result.js delete mode 100644 snippets/auth/saml/auth_saml_provider_create.js delete mode 100644 snippets/auth/saml/auth_saml_signin_popup.js delete mode 100644 snippets/auth/saml/auth_saml_signin_redirect.js delete mode 100644 snippets/auth/saml/auth_saml_signin_redirect_result.js diff --git a/auth-next/index.js b/auth-next/index.js index 73d33219..c4dadfe0 100644 --- a/auth-next/index.js +++ b/auth-next/index.js @@ -26,7 +26,7 @@ function makeFacebookCredential(response) { function makeEmailCredential(email, password) { // [START auth_make_email_credential] const { EmailAuthProvider } = require("firebase/auth"); - + const credential = EmailAuthProvider.credential(email, password); // [END auth_make_email_credential] } @@ -121,3 +121,17 @@ function signInRedirect(provider) { signInWithRedirect(auth, provider); // [END auth_signin_redirect] } + +function initializeWithCustomDomain() { + // [START auth_init_custom_domain] + const { initializeApp } = require("firebase/app"); + + const firebaseConfig = { + apiKey: "...", + // By default, authDomain is '[YOUR_APP].firebaseapp.com'. + // You may replace it with a custom domain. + authDomain: '[YOUR_CUSTOM_DOMAIN]' + }; + const firebaseApp = initializeApp(firebaseConfig); + // [END auth_init_custom_domain] +} diff --git a/auth/index.js b/auth/index.js index 6ea5d587..6567c030 100644 --- a/auth/index.js +++ b/auth/index.js @@ -101,3 +101,14 @@ function signInRedirect(provider) { firebase.auth().signInWithRedirect(provider); // [END auth_signin_redirect] } + +function initializeWithCustomDomain() { + // [START auth_init_custom_domain] + firebase.initializeApp({ + apiKey: '...', + // By default, authDomain is '[YOUR_APP].firebaseapp.com'. + // You may replace it with a custom domain. + authDomain: '[YOUR_CUSTOM_DOMAIN]' + }); + // [END auth_init_custom_domain] +} diff --git a/auth/oidc.js b/auth/oidc.js index 4c056e52..e3a3e01e 100644 --- a/auth/oidc.js +++ b/auth/oidc.js @@ -4,9 +4,6 @@ import firebase from "firebase/app"; import "firebase/auth"; -// [SNIPPET_REGISTRY disabled] -// [SNIPPETS_SEPARATION enabled] - function oidcProvider() { // [START auth_oidc_provider_create] const provider = new firebase.auth.OAuthProvider('oidc.myProvider'); diff --git a/auth/saml.js b/auth/saml.js index a55b691c..e3a99cde 100644 --- a/auth/saml.js +++ b/auth/saml.js @@ -4,9 +4,6 @@ import firebase from "firebase/app"; import "firebase/auth"; -// [SNIPPET_REGISTRY disabled] -// [SNIPPETS_SEPARATION enabled] - function samlProvider() { // [START auth_saml_provider_create] const provider = new firebase.auth.SAMLAuthProvider('saml.myProvider'); diff --git a/snippets/auth-next/index/auth_init_custom_domain.js b/snippets/auth-next/index/auth_init_custom_domain.js new file mode 100644 index 00000000..971e5c56 --- /dev/null +++ b/snippets/auth-next/index/auth_init_custom_domain.js @@ -0,0 +1,17 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/index.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_init_custom_domain_modular] +import { initializeApp } from "firebase/app"; + +const firebaseConfig = { + apiKey: "...", + // By default, authDomain is '[YOUR_APP].firebaseapp.com'. + // You may replace it with a custom domain. + authDomain: '[YOUR_CUSTOM_DOMAIN]' +}; +const firebaseApp = initializeApp(firebaseConfig); +// [END auth_init_custom_domain_modular] \ No newline at end of file diff --git a/snippets/auth/oidc/auth_oidc_direct_sign_in.js b/snippets/auth/oidc/auth_oidc_direct_sign_in.js deleted file mode 100644 index 5a0c629d..00000000 --- a/snippets/auth/oidc/auth_oidc_direct_sign_in.js +++ /dev/null @@ -1,19 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth/oidc.js -// -// To update the snippets in this file, edit the source and then run -// 'npm run snippets'. - -// [START auth_oidc_direct_sign_in_modular] -const credential = provider.credential(oidcIdToken, null); - -firebase.auth().signInWithCredential(credential) - .then((result) => { - // User is signed in. - // User now has a odic.myProvider UserInfo in providerData. - }) - .catch((error) => { - // Handle / display error. - // ... - }); -// [END auth_oidc_direct_sign_in_modular] \ No newline at end of file diff --git a/snippets/auth/oidc/auth_oidc_provider_create.js b/snippets/auth/oidc/auth_oidc_provider_create.js deleted file mode 100644 index 09e08ad8..00000000 --- a/snippets/auth/oidc/auth_oidc_provider_create.js +++ /dev/null @@ -1,9 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth/oidc.js -// -// To update the snippets in this file, edit the source and then run -// 'npm run snippets'. - -// [START auth_oidc_provider_create_modular] -const provider = new firebase.auth.OAuthProvider('oidc.myProvider'); -// [END auth_oidc_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth/oidc/auth_oidc_signin_popup.js b/snippets/auth/oidc/auth_oidc_signin_popup.js deleted file mode 100644 index c5ff4afa..00000000 --- a/snippets/auth/oidc/auth_oidc_signin_popup.js +++ /dev/null @@ -1,18 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth/oidc.js -// -// To update the snippets in this file, edit the source and then run -// 'npm run snippets'. - -// [START auth_oidc_signin_popup_modular] -firebase.auth().signInWithPopup(provider) - .then((result) => { - // User is signed in. - // result.credential is a firebase.auth().OAuthCredential object. - // result.credential.providerId is equal to 'oidc.myProvider'. - // result.credential.idToken is the OIDC provider's ID token. - }) - .catch((error) => { - // Handle error. - }); -// [END auth_oidc_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth/oidc/auth_oidc_signin_redirect.js b/snippets/auth/oidc/auth_oidc_signin_redirect.js deleted file mode 100644 index 4951c4bf..00000000 --- a/snippets/auth/oidc/auth_oidc_signin_redirect.js +++ /dev/null @@ -1,11 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth/oidc.js -// -// To update the snippets in this file, edit the source and then run -// 'npm run snippets'. - -// [START auth_oidc_signin_redirect_modular] -firebase.auth().signInWithRedirect(provider).catch((error) => { - // Handle error. -}); -// [END auth_oidc_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth/oidc/auth_oidc_signin_redirect_result.js b/snippets/auth/oidc/auth_oidc_signin_redirect_result.js deleted file mode 100644 index 2cd0eaa7..00000000 --- a/snippets/auth/oidc/auth_oidc_signin_redirect_result.js +++ /dev/null @@ -1,20 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth/oidc.js -// -// To update the snippets in this file, edit the source and then run -// 'npm run snippets'. - -// [START auth_oidc_signin_redirect_result_modular] -// On return. -firebase.auth().getRedirectResult() - .then((result) => { - // User is signed in. - // result.credential is a firebase.auth().OAuthCredential object. - // result.credential.providerId is equal to 'oidc.myProvider'. - // result.credential.idToken is the OIDC provider's ID token. - }) - .catch((error) => { - // Handle / display error. - // ... - }); -// [END auth_oidc_signin_redirect_result_modular] \ No newline at end of file diff --git a/snippets/auth/saml/auth_saml_provider_create.js b/snippets/auth/saml/auth_saml_provider_create.js deleted file mode 100644 index a9765e5e..00000000 --- a/snippets/auth/saml/auth_saml_provider_create.js +++ /dev/null @@ -1,9 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth/saml.js -// -// To update the snippets in this file, edit the source and then run -// 'npm run snippets'. - -// [START auth_saml_provider_create_modular] -const provider = new firebase.auth.SAMLAuthProvider('saml.myProvider'); -// [END auth_saml_provider_create_modular] \ No newline at end of file diff --git a/snippets/auth/saml/auth_saml_signin_popup.js b/snippets/auth/saml/auth_saml_signin_popup.js deleted file mode 100644 index 1fb3b4f6..00000000 --- a/snippets/auth/saml/auth_saml_signin_popup.js +++ /dev/null @@ -1,21 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth/saml.js -// -// To update the snippets in this file, edit the source and then run -// 'npm run snippets'. - -// [START auth_saml_signin_popup_modular] -firebase.auth().signInWithPopup(provider) - .then((result) => { - // User is signed in. - // Identity provider data available in result.additionalUserInfo.profile, - // or from the user's ID token obtained from result.user.getIdToken() - // as an object in the firebase.sign_in_attributes custom claim - // This is also available from result.user.getIdTokenResult() - // idTokenResult.claims.firebase.sign_in_attributes. - }) - .catch((error) => { - // Handle / display error. - // ... - }); -// [END auth_saml_signin_popup_modular] \ No newline at end of file diff --git a/snippets/auth/saml/auth_saml_signin_redirect.js b/snippets/auth/saml/auth_saml_signin_redirect.js deleted file mode 100644 index bd328a57..00000000 --- a/snippets/auth/saml/auth_saml_signin_redirect.js +++ /dev/null @@ -1,9 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth/saml.js -// -// To update the snippets in this file, edit the source and then run -// 'npm run snippets'. - -// [START auth_saml_signin_redirect_modular] -firebase.auth().signInWithRedirect(provider); -// [END auth_saml_signin_redirect_modular] \ No newline at end of file diff --git a/snippets/auth/saml/auth_saml_signin_redirect_result.js b/snippets/auth/saml/auth_saml_signin_redirect_result.js deleted file mode 100644 index 65a9f38b..00000000 --- a/snippets/auth/saml/auth_saml_signin_redirect_result.js +++ /dev/null @@ -1,20 +0,0 @@ -// This snippet file was generated by processing the source file: -// ./auth/saml.js -// -// To update the snippets in this file, edit the source and then run -// 'npm run snippets'. - -// [START auth_saml_signin_redirect_result_modular] -firebase.auth().getRedirectResult() - .then((result) => { - // User is signed in. - // Provider data available in result.additionalUserInfo.profile, - // or from the user's ID token obtained from result.user.getIdToken() - // as an object in the firebase.sign_in_attributes custom claim - // This is also available from result.user.getIdTokenResult() - // idTokenResult.claims.firebase.sign_in_attributes. - }).catch((error) => { - // Handle / display error. - // ... - }); -// [END auth_saml_signin_redirect_result_modular] \ No newline at end of file From e2a9d336d42add89bc3f504e4143300adea25685 Mon Sep 17 00:00:00 2001 From: Ian Tay Date: Mon, 18 Oct 2021 16:51:42 -0700 Subject: [PATCH 200/235] add multi-tenancy snippets (#250) --- auth-next/multi-tenancy.js | 347 ++++++++++++++++++ auth/multi-tenancy.js | 312 ++++++++++++++++ .../multitenant_account_exists_popup.js | 44 +++ .../multitenant_account_exists_redirect.js | 51 +++ .../multitenant_account_linking.js | 34 ++ .../multitenant_create_custom_token.js | 20 + .../multitenant_send_emaillink.js | 23 ++ .../multi-tenancy/multitenant_set_tenant.js | 12 + .../multitenant_signin_custom_token.js | 16 + .../multitenant_signin_emaillink.js | 29 ++ .../multitenant_signin_password.js | 19 + .../multitenant_signin_password_demo.js | 33 ++ .../multitenant_signin_saml_popup.js | 25 ++ .../multitenant_signin_saml_redirect.js | 29 ++ .../multitenant_signup_password.js | 19 + .../multitenant_switch_tenant.js | 15 + ...multitenant_switch_tenant_multiinstance.js | 19 + 17 files changed, 1047 insertions(+) create mode 100644 auth-next/multi-tenancy.js create mode 100644 auth/multi-tenancy.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_account_exists_popup.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_account_exists_redirect.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_account_linking.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_create_custom_token.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_send_emaillink.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_set_tenant.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_signin_custom_token.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_signin_emaillink.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_signin_password.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_signin_password_demo.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_signin_saml_popup.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_signin_saml_redirect.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_signup_password.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_switch_tenant.js create mode 100644 snippets/auth-next/multi-tenancy/multitenant_switch_tenant_multiinstance.js diff --git a/auth-next/multi-tenancy.js b/auth-next/multi-tenancy.js new file mode 100644 index 00000000..c0c86662 --- /dev/null +++ b/auth-next/multi-tenancy.js @@ -0,0 +1,347 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +function setTenant() { + // [START multitenant_set_tenant] + const { getAuth } = require("firebase/auth"); + const auth = getAuth(); + const tenantId = "TENANT_ID1"; + auth.tenantId = tenantId; + // [END multitenant_set_tenant] +} + +function switchTenantSingleAuth(auth) { + // [START multitenant_switch_tenant] + // One Auth instance + // Switch to tenant1 + auth.tenantId = "TENANT_ID1"; + // Switch to tenant2 + auth.tenantId = "TENANT_ID2"; + // Switch back to project level IdPs + auth.tenantId = null; + // [END multitenant_switch_tenant] +} + +function switchTenantMultiAuth(firebaseConfig1, firebaseConfig2) { + // [START multitenant_switch_tenant_multiinstance] + // Multiple Auth instances + const { initializeApp } = require("firebase/app"); + const { getAuth } = require("firebase/auth"); + const firebaseApp1 = initializeApp(firebaseConfig1, 'app1_for_tenantId1'); + const firebaseApp2 = initializeApp(firebaseConfig2, 'app2_for_tenantId2'); + + const auth1 = getAuth(firebaseApp1); + const auth2 = getAuth(firebaseApp2); + + auth1.tenantId = "TENANT_ID1"; + auth2.tenantId = "TENANT_ID2"; + // [END multitenant_switch_tenant_multiinstance] +} + +function passwordSignInWithTenantDemo(auth, email, password) { + // [START multitenant_signin_password_demo] + const { signInWithEmailAndPassword, onAuthStateChanged } = require("firebase/auth"); + // Switch to TENANT_ID1 + auth.tenantId = 'TENANT_ID1'; + + // Sign in with tenant + signInWithEmailAndPassword(auth, email, password) + .then((userCredential) => { + // User is signed in. + const user = userCredential.user; + // user.tenantId is set to 'TENANT_ID1'. + // Switch to 'TENANT_ID2'. + auth.tenantId = 'TENANT_ID2'; + // auth.currentUser still points to the user. + // auth.currentUser.tenantId is 'TENANT_ID1'. + }); + + // You could also get the current user from Auth state observer. + onAuthStateChanged(auth, (user) => { + if (user) { + // User is signed in. + // user.tenantId is set to 'TENANT_ID1'. + } else { + // No user is signed in. + } + }); + // [END multitenant_signin_password_demo] +} + +function signUpWithTenant(auth, email, password) { + // [START multitenant_signup_password] + const { createUserWithEmailAndPassword } = require("firebase/auth"); + auth.tenantId = 'TENANT_ID'; + + createUserWithEmailAndPassword(auth, email, password) + .then((userCredential) => { + // User is signed in. + // userCredential.user.tenantId is 'TENANT_ID'. + }).catch((error) => { + // Handle / display error. + // ... + }); + // [END multitenant_signup_password] +} + + +function passwordSignInWithTenant(auth, email, password) { + // [START multitenant_signin_password] + const { signInWithEmailAndPassword } = require("firebase/auth"); + auth.tenantId = 'TENANT_ID'; + + signInWithEmailAndPassword(auth, email, password) + .then((userCredential) => { + // User is signed in. + // userCredential.user.tenantId is 'TENANT_ID'. + }).catch((error) => { + // Handle / display error. + // ... + }); + // [END multitenant_signin_password] +} + +function samlSignInPopupTenant(auth, provider) { + // [START multitenant_signin_saml_popup] + const { signInWithPopup } = require("firebase/auth"); + // Switch to TENANT_ID1. + auth.tenantId = 'TENANT_ID1'; + + // Sign-in with popup. + signInWithPopup(auth, provider) + .then((userCredential) => { + // User is signed in. + const user = userCredential.user; + // user.tenantId is set to 'TENANT_ID1'. + // Provider data available from the result.user.getIdToken() + // or from result.user.providerData + }) + .catch((error) => { + // Handle / display error. + // ... + }); + // [END multitenant_signin_saml_popup] +} + +function samlSignInRedirectTenant(auth, provider) { + // [START multitenant_signin_saml_redirect] + const { signInWithRedirect, getRedirectResult } = require("firebase/auth"); + // Switch to TENANT_ID1. + auth.tenantId = 'TENANT_ID1'; + + // Sign-in with redirect. + signInWithRedirect(auth, provider); + + // After the user completes sign-in and returns to the app, you can get + // the sign-in result by calling getRedirectResult. However, if they sign out + // and sign in again with an IdP, no tenant is used. + getRedirectResult(auth) + .then((result) => { + // User is signed in. + // The tenant ID available in result.user.tenantId. + // Provider data available from the result.user.getIdToken() + // or from result.user.providerData + }) + .catch((error) => { + // Handle / display error. + // ... + }); + // [END multitenant_signin_saml_redirect] +} + +function sendSignInLinkToEmailTenant(auth, email, actionCodeSettings) { + // [START multitenant_send_emaillink] + const { sendSignInLinkToEmail } = require("firebase/auth"); + // Switch to TENANT_ID1 + auth.tenantId = 'TENANT_ID1'; + + sendSignInLinkToEmail(auth, email, actionCodeSettings) + .then(() => { + // The link was successfully sent. Inform the user. + // Save the email locally so you don't need to ask the user for it again + // if they open the link on the same device. + window.localStorage.setItem('emailForSignIn', email); + }) + .catch((error) => { + // Handle / display error. + // ... + }); + // [END multitenant_send_emaillink] +} + +function signInWithEmailLinkTenant(auth) { + // [START multitenant_signin_emaillink] + const { isSignInWithEmailLink, parseActionCodeURL, signInWithEmailLink } = require("firebase/auth"); + if (isSignInWithEmailLink(auth, window.location.href)) { + const actionCodeUrl = parseActionCodeURL(window.location.href); + if (actionCodeUrl.tenantId) { + auth.tenantId = actionCodeUrl.tenantId; + } + let email = window.localStorage.getItem('emailForSignIn'); + if (!email) { + // User opened the link on a different device. To prevent session fixation + // attacks, ask the user to provide the associated email again. For example: + email = window.prompt('Please provide your email for confirmation'); + } + // The client SDK will parse the code from the link for you. + signInWithEmailLink(auth, email, window.location.href) + .then((result) => { + // User is signed in. + // tenant ID available in result.user.tenantId. + // Clear email from storage. + window.localStorage.removeItem('emailForSignIn'); + }); + } + // [END multitenant_signin_emaillink] +} + +// Same as the code in auth/ since this is the admin SDK. +function createCustomTokenTenant(admin, uid) { + // [START multitenant_create_custom_token] + // Ensure you're using a tenant-aware auth instance + const tenantManager = admin.auth().tenantManager(); + const tenantAuth = tenantManager.authForTenant('TENANT_ID1'); + + // Create a custom token in the usual manner + tenantAuth.createCustomToken(uid) + .then((customToken) => { + // Send token back to client + }) + .catch((error) => { + console.log('Error creating custom token:', error); + }); + // [END multitenant_create_custom_token] +} + +function signInWithCustomTokenTenant(auth, token) { + // [START multitenant_signin_custom_token] + const { signInWithCustomToken } = require("firebase/auth"); + auth.tenantId = 'TENANT_ID1'; + + signInWithCustomToken(auth, token) + .catch((error) => { + // Handle / display error. + // ... + }); + // [END multitenant_signin_custom_token] +} + +function linkAccountTenant(auth, provider, email, password) { + // [START multitenant_account_linking] + const { signInWithPopup, EmailAuthProvider, linkWithCredential, SAMLAuthProvider, signInWithCredential } = require("firebase/auth"); + // Switch to TENANT_ID1 + auth.tenantId = 'TENANT_ID1'; + + // Sign-in with popup + signInWithPopup(auth, provider) + .then((userCredential) => { + // Existing user with e.g. SAML provider. + const prevUser = userCredential.user; + const emailCredential = + EmailAuthProvider.credential(email, password); + return linkWithCredential(prevUser, emailCredential) + .then((linkResult) => { + // Sign in with the newly linked credential + const linkCredential = SAMLAuthProvider.credentialFromResult(linkResult); + return signInWithCredential(auth, linkCredential); + }) + .then((signInResult) => { + // Handle sign in of merged user + // ... + }); + }) + .catch((error) => { + // Handle / display error. + // ... + }); + // [END multitenant_account_linking] +} + +function accountExistsPopupTenant(auth, samlProvider, googleProvider, goToApp) { + // [START multitenant_account_exists_popup] + const { signInWithPopup, fetchSignInMethodsForEmail, linkWithCredential } = require("firebase/auth"); + // Step 1. + // User tries to sign in to the SAML provider in that tenant. + auth.tenantId = 'TENANT_ID'; + signInWithPopup(auth, samlProvider) + .catch((error) => { + // An error happened. + if (error.code === 'auth/account-exists-with-different-credential') { + // Step 2. + // User's email already exists. + // The pending SAML credential. + const pendingCred = error.credential; + // The credential's tenantId if needed: error.tenantId + // The provider account's email address. + const email = error.email; + // Get sign-in methods for this email. + fetchSignInMethodsForEmail(email, auth) + .then((methods) => { + // Step 3. + // Ask the user to sign in with existing Google account. + if (methods[0] == 'google.com') { + signInWithPopup(auth, googleProvider) + .then((result) => { + // Step 4 + // Link the SAML AuthCredential to the existing user. + linkWithCredential(result.user, pendingCred) + .then((linkResult) => { + // SAML account successfully linked to the existing + // user. + goToApp(); + }); + }); + } + }); + } + }); + // [END multitenant_account_exists_popup] +} + +function accountExistsRedirectTenant(auth, samlProvider, googleProvider, goToApp) { + // [START multitenant_account_exists_redirect] + const { signInWithRedirect, getRedirectResult, fetchSignInMethodsForEmail, linkWithCredential } = require("firebase/auth"); + // Step 1. + // User tries to sign in to SAML provider. + auth.tenantId = 'TENANT_ID'; + signInWithRedirect(auth, samlProvider); + var pendingCred; + // Redirect back from SAML IDP. auth.tenantId is null after redirecting. + getRedirectResult(auth).catch((error) => { + if (error.code === 'auth/account-exists-with-different-credential') { + // Step 2. + // User's email already exists. + const tenantId = error.tenantId; + // The pending SAML credential. + pendingCred = error.credential; + // The provider account's email address. + const email = error.email; + // Need to set the tenant ID again as the page was reloaded and the + // previous setting was reset. + auth.tenantId = tenantId; + // Get sign-in methods for this email. + fetchSignInMethodsForEmail(auth, email) + .then((methods) => { + // Step 3. + // Ask the user to sign in with existing Google account. + if (methods[0] == 'google.com') { + signInWithRedirect(auth, googleProvider); + } + }); + } + }); + + // Redirect back from Google. auth.tenantId is null after redirecting. + getRedirectResult(auth).then((result) => { + // Step 4 + // Link the SAML AuthCredential to the existing user. + // result.user.tenantId is 'TENANT_ID'. + linkWithCredential(result.user, pendingCred) + .then((linkResult) => { + // SAML account successfully linked to the existing + // user. + goToApp(); + }); + }); + // [END multitenant_account_exists_redirect] +} \ No newline at end of file diff --git a/auth/multi-tenancy.js b/auth/multi-tenancy.js new file mode 100644 index 00000000..8afc1a5c --- /dev/null +++ b/auth/multi-tenancy.js @@ -0,0 +1,312 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/auth"; + +function setTenant() { + // [START multitenant_set_tenant] + const tenantId = "TENANT_ID1"; + firebase.auth().tenantId = tenantId; + // [END multitenant_set_tenant] +} + +function switchTenantSingleAuth() { + // [START multitenant_switch_tenant] + // One Auth instance + // Switch to tenant1 + firebase.auth().tenantId = "TENANT_ID1"; + // Switch to tenant2 + firebase.auth().tenantId = "TENANT_ID2"; + // Switch back to project level IdPs + firebase.auth().tenantId = null; + // [END multitenant_switch_tenant] +} + +function switchTenantMultiAuthInstance(config) { + // [START multitenant_switch_tenant_multiinstance] + // Multiple Auth instances + firebase.initializeApp(config, 'app1_for_tenantId1'); + firebase.initializeApp(config, 'app2_for_tenantId2'); + + const auth1 = firebase.app('app1').auth(); + const auth2 = firebase.app('app2').auth(); + + auth1.tenantId = "TENANT_ID1"; + auth2.tenantId = "TENANT_ID2"; + // [END multitenant_switch_tenant_multiinstance] +} + +function passwordSignInWithTenantDemo(email, password) { + // [START multitenant_signin_password_demo] + // Switch to TENANT_ID1 + firebase.auth().tenantId = 'TENANT_ID1'; + + // Sign in with tenant + firebase.auth().signInWithEmailAndPassword(email, password) + .then((result) => { + const user = result.user; + // user.tenantId is set to 'TENANT_ID1'. + // Switch to 'TENANT_ID2'. + firebase.auth().tenantId = 'TENANT_ID2'; + // firebase.auth().currentUser still point to the user. + // firebase.auth().currentUser.tenantId is 'TENANT_ID1'. + }); + + // You could also get the current user from Auth state observer. + firebase.auth().onAuthStateChanged((user) => { + if (user) { + // User is signed in. + // user.tenantId is set to 'TENANT_ID1'. + } else { + // No user is signed in. + } + }); + // [END multitenant_signin_password_demo] +} + +function signUpWithTenant(email, password) { + // [START multitenant_signup_password] + firebase.auth().tenantId = 'TENANT_ID'; + + firebase.auth().createUserWithEmailAndPassword(email, password) + .then((result) => { + // result.user.tenantId is 'TENANT_ID'. + }).catch((error) => { + // Handle error. + }); + // [END multitenant_signup_password] +} + + +function passwordSignInWithTenant(email, password) { + // [START multitenant_signin_password] + firebase.auth().tenantId = 'TENANT_ID'; + + firebase.auth().signInWithEmailAndPassword(email, password) + .then((result) => { + // result.user.tenantId is 'TENANT_ID'. + }).catch((error) => { + // Handle error. + }); + // [END multitenant_signin_password] +} + +function samlSignInPopupTenant(provider) { + // [START multitenant_signin_saml_popup] + // Switch to TENANT_ID1. + firebase.auth().tenantId = 'TENANT_ID1'; + + // Sign-in with popup. + firebase.auth().signInWithPopup(provider) + .then((result) => { + // User is signed in. + // tenant ID is available in result.user.tenantId. + // Identity provider data is available in result.additionalUserInfo.profile. + }) + .catch((error) => { + // Handle error. + }); + // [END multitenant_signin_saml_popup] +} + +function samlSignInRedirectTenant(provider) { + // [START multitenant_signin_saml_redirect] + // Switch to TENANT_ID1. + firebase.auth().tenantId = 'TENANT_ID1'; + + // Sign-in with redirect. + firebase.auth().signInWithRedirect(provider); + + // After the user completes sign-in and returns to the app, you can get + // the sign-in result by calling getRedirectResult. However, if they sign out + // and sign in again with an IdP, no tenant is used. + firebase.auth().getRedirectResult() + .then((result) => { + // User is signed in. + // The tenant ID available in result.user.tenantId. + // Identity provider data is available in result.additionalUserInfo.profile. + }) + .catch((error) => { + // Handle error. + }); + // [END multitenant_signin_saml_redirect] +} + +function sendSignInLinkToEmailTenant(email, actionCodeSettings) { + // [START multitenant_send_emaillink] + // Switch to TENANT_ID1 + firebase.auth().tenantId = 'TENANT_ID1'; + + firebase.auth().sendSignInLinkToEmail(email, actionCodeSettings) + .then(() => { + // The link was successfully sent. Inform the user. + // Save the email locally so you don't need to ask the user for it again + // if they open the link on the same device. + window.localStorage.setItem('emailForSignIn', email); + }) + .catch((error) => { + // Some error occurred, you can inspect the code: error.code + }); + // [END multitenant_send_emaillink] +} + +function signInWithEmailLinkTenant() { + // [START multitenant_signin_emaillink] + if (firebase.auth().isSignInWithEmailLink(window.location.href)) { + const actionCodeUrl = firebase.auth.ActionCodeURL.parseLink(window.location.href); + if (actionCodeUrl.tenantId) { + firebase.auth().tenantId = actionCodeUrl.tenantId; + } + let email = window.localStorage.getItem('emailForSignIn'); + if (!email) { + // User opened the link on a different device. To prevent session fixation + // attacks, ask the user to provide the associated email again. For example: + email = window.prompt('Please provide your email for confirmation'); + } + firebase.auth().signInWithEmailLink(email, window.location.href) + .then((result) => { + // User is signed in. + // tenant ID available in result.user.tenantId. + }); + } + // [END multitenant_signin_emaillink] +} + +function createCustomTokenTenant(admin, uid) { + // [START multitenant_create_custom_token] + // Ensure you're using a tenant-aware auth instance + const tenantManager = admin.auth().tenantManager(); + const tenantAuth = tenantManager.authForTenant('TENANT_ID1'); + + // Create a custom token in the usual manner + tenantAuth.createCustomToken(uid) + .then((customToken) => { + // Send token back to client + }) + .catch((error) => { + console.log('Error creating custom token:', error); + }); + // [END multitenant_create_custom_token] +} + +function signInWithCustomTokenTenant(token) { + // [START multitenant_signin_custom_token] + firebase.auth().tenantId = 'TENANT_ID1'; + + firebase.auth().signInWithCustomToken(token) + .catch((error) => { + // Handle Errors here. + const errorCode = error.code; + const errorMessage = error.message; + // ... + }); + // [END multitenant_signin_custom_token] +} + +function linkAccountTenant(provider, email, password) { + // [START multitenant_account_linking] + // Switch to TENANT_ID1 + firebase.auth().tenantId = 'TENANT_ID1'; + + // Sign-in with popup + firebase.auth().signInWithPopup(provider) + .then((result) => { + // Existing user with e.g. SAML provider. + const user = result.user; + const emailCredential = + firebase.auth.EmailAuthProvider.credential(email, password); + return user.linkWithCredential(emailCredential); + }) + .then((linkResult) => { + // The user can sign in with both SAML and email/password now. + }); + // [END multitenant_account_linking] +} + +function accountExistsPopupTenant(samlProvider, googleProvider, goToApp) { + // [START multitenant_account_exists_popup] + // Step 1. + // User tries to sign in to the SAML provider in that tenant. + firebase.auth().tenantId = 'TENANT_ID'; + firebase.auth().signInWithPopup(samlProvider) + .catch((error) => { + // An error happened. + if (error.code === 'auth/account-exists-with-different-credential') { + // Step 2. + // User's email already exists. + // The pending SAML credential. + const pendingCred = error.credential; + // The credential's tenantId if needed: error.tenantId + // The provider account's email address. + const email = error.email; + // Get sign-in methods for this email. + firebase.auth().fetchSignInMethodsForEmail(email) + .then((methods) => { + // Step 3. + // Ask the user to sign in with existing Google account. + if (methods[0] == 'google.com') { + firebase.auth().signInWithPopup(googleProvider) + .then((result) => { + // Step 4 + // Link the SAML AuthCredential to the existing user. + result.user.linkWithCredential(pendingCred) + .then((linkResult) => { + // SAML account successfully linked to the existing + // user. + goToApp(); + }); + }); + } + }); + } + }); + // [END multitenant_account_exists_popup] +} + +function accountExistsRedirectTenant(samlProvider, googleProvider, goToApp) { + // [START multitenant_account_exists_redirect] + // Step 1. + // User tries to sign in to SAML provider. + firebase.auth().tenantId = 'TENANT_ID'; + firebase.auth().signInWithRedirect(samlProvider); + var pendingCred; + // Redirect back from SAML IDP. auth.tenantId is null after redirecting. + firebase.auth().getRedirectResult().catch((error) => { + if (error.code === 'auth/account-exists-with-different-credential') { + // Step 2. + // User's email already exists. + const tenantId = error.tenantId; + // The pending SAML credential. + pendingCred = error.credential; + // The provider account's email address. + const email = error.email; + // Need to set the tenant ID again as the page was reloaded and the + // previous setting was reset. + firebase.auth().tenantId = tenantId; + // Get sign-in methods for this email. + firebase.auth().fetchSignInMethodsForEmail(email) + .then((methods) => { + // Step 3. + // Ask the user to sign in with existing Google account. + if (methods[0] == 'google.com') { + firebase.auth().signInWithRedirect(googleProvider); + } + }); + } + }); + + // Redirect back from Google. auth.tenantId is null after redirecting. + firebase.auth().getRedirectResult().then((result) => { + // Step 4 + // Link the SAML AuthCredential to the existing user. + // result.user.tenantId is 'TENANT_ID'. + result.user.linkWithCredential(pendingCred) + .then((linkResult) => { + // SAML account successfully linked to the existing + // user. + goToApp(); + }); + }); + // [END multitenant_account_exists_redirect] +} \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_account_exists_popup.js b/snippets/auth-next/multi-tenancy/multitenant_account_exists_popup.js new file mode 100644 index 00000000..43734616 --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_account_exists_popup.js @@ -0,0 +1,44 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_account_exists_popup_modular] +import { signInWithPopup, fetchSignInMethodsForEmail, linkWithCredential } from "firebase/auth"; +// Step 1. +// User tries to sign in to the SAML provider in that tenant. +auth.tenantId = 'TENANT_ID'; +signInWithPopup(auth, samlProvider) + .catch((error) => { + // An error happened. + if (error.code === 'auth/account-exists-with-different-credential') { + // Step 2. + // User's email already exists. + // The pending SAML credential. + const pendingCred = error.credential; + // The credential's tenantId if needed: error.tenantId + // The provider account's email address. + const email = error.email; + // Get sign-in methods for this email. + fetchSignInMethodsForEmail(email, auth) + .then((methods) => { + // Step 3. + // Ask the user to sign in with existing Google account. + if (methods[0] == 'google.com') { + signInWithPopup(auth, googleProvider) + .then((result) => { + // Step 4 + // Link the SAML AuthCredential to the existing user. + linkWithCredential(result.user, pendingCred) + .then((linkResult) => { + // SAML account successfully linked to the existing + // user. + goToApp(); + }); + }); + } + }); + } + }); +// [END multitenant_account_exists_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_account_exists_redirect.js b/snippets/auth-next/multi-tenancy/multitenant_account_exists_redirect.js new file mode 100644 index 00000000..f8a3942d --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_account_exists_redirect.js @@ -0,0 +1,51 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_account_exists_redirect_modular] +import { signInWithRedirect, getRedirectResult, fetchSignInMethodsForEmail, linkWithCredential } from "firebase/auth"; +// Step 1. +// User tries to sign in to SAML provider. +auth.tenantId = 'TENANT_ID'; +signInWithRedirect(auth, samlProvider); +var pendingCred; +// Redirect back from SAML IDP. auth.tenantId is null after redirecting. +getRedirectResult(auth).catch((error) => { + if (error.code === 'auth/account-exists-with-different-credential') { + // Step 2. + // User's email already exists. + const tenantId = error.tenantId; + // The pending SAML credential. + pendingCred = error.credential; + // The provider account's email address. + const email = error.email; + // Need to set the tenant ID again as the page was reloaded and the + // previous setting was reset. + auth.tenantId = tenantId; + // Get sign-in methods for this email. + fetchSignInMethodsForEmail(auth, email) + .then((methods) => { + // Step 3. + // Ask the user to sign in with existing Google account. + if (methods[0] == 'google.com') { + signInWithRedirect(auth, googleProvider); + } + }); + } +}); + +// Redirect back from Google. auth.tenantId is null after redirecting. +getRedirectResult(auth).then((result) => { + // Step 4 + // Link the SAML AuthCredential to the existing user. + // result.user.tenantId is 'TENANT_ID'. + linkWithCredential(result.user, pendingCred) + .then((linkResult) => { + // SAML account successfully linked to the existing + // user. + goToApp(); + }); +}); +// [END multitenant_account_exists_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_account_linking.js b/snippets/auth-next/multi-tenancy/multitenant_account_linking.js new file mode 100644 index 00000000..c43ff90d --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_account_linking.js @@ -0,0 +1,34 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_account_linking_modular] +import { signInWithPopup, EmailAuthProvider, linkWithCredential, SAMLAuthProvider, signInWithCredential } from "firebase/auth"; +// Switch to TENANT_ID1 +auth.tenantId = 'TENANT_ID1'; + +// Sign-in with popup +signInWithPopup(auth, provider) + .then((userCredential) => { + // Existing user with e.g. SAML provider. + const prevUser = userCredential.user; + const emailCredential = + EmailAuthProvider.credential(email, password); + return linkWithCredential(prevUser, emailCredential) + .then((linkResult) => { + // Sign in with the newly linked credential + const linkCredential = SAMLAuthProvider.credentialFromResult(linkResult); + return signInWithCredential(auth, linkCredential); + }) + .then((signInResult) => { + // Handle sign in of merged user + // ... + }); + }) + .catch((error) => { + // Handle / display error. + // ... + }); +// [END multitenant_account_linking_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_create_custom_token.js b/snippets/auth-next/multi-tenancy/multitenant_create_custom_token.js new file mode 100644 index 00000000..1426cf8a --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_create_custom_token.js @@ -0,0 +1,20 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_create_custom_token_modular] +// Ensure you're using a tenant-aware auth instance +const tenantManager = admin.auth().tenantManager(); +const tenantAuth = tenantManager.authForTenant('TENANT_ID1'); + +// Create a custom token in the usual manner +tenantAuth.createCustomToken(uid) + .then((customToken) => { + // Send token back to client + }) + .catch((error) => { + console.log('Error creating custom token:', error); + }); +// [END multitenant_create_custom_token_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_send_emaillink.js b/snippets/auth-next/multi-tenancy/multitenant_send_emaillink.js new file mode 100644 index 00000000..4c4d95c5 --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_send_emaillink.js @@ -0,0 +1,23 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_send_emaillink_modular] +import { sendSignInLinkToEmail } from "firebase/auth"; +// Switch to TENANT_ID1 +auth.tenantId = 'TENANT_ID1'; + +sendSignInLinkToEmail(auth, email, actionCodeSettings) + .then(() => { + // The link was successfully sent. Inform the user. + // Save the email locally so you don't need to ask the user for it again + // if they open the link on the same device. + window.localStorage.setItem('emailForSignIn', email); + }) + .catch((error) => { + // Handle / display error. + // ... + }); +// [END multitenant_send_emaillink_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_set_tenant.js b/snippets/auth-next/multi-tenancy/multitenant_set_tenant.js new file mode 100644 index 00000000..9510bc5e --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_set_tenant.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_set_tenant_modular] +import { getAuth } from "firebase/auth"; +const auth = getAuth(); +const tenantId = "TENANT_ID1"; +auth.tenantId = tenantId; +// [END multitenant_set_tenant_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_signin_custom_token.js b/snippets/auth-next/multi-tenancy/multitenant_signin_custom_token.js new file mode 100644 index 00000000..b9fa9c58 --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_signin_custom_token.js @@ -0,0 +1,16 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_signin_custom_token_modular] +import { signInWithCustomToken } from "firebase/auth"; +auth.tenantId = 'TENANT_ID1'; + +signInWithCustomToken(auth, token) + .catch((error) => { + // Handle / display error. + // ... + }); +// [END multitenant_signin_custom_token_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_signin_emaillink.js b/snippets/auth-next/multi-tenancy/multitenant_signin_emaillink.js new file mode 100644 index 00000000..0032af1c --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_signin_emaillink.js @@ -0,0 +1,29 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_signin_emaillink_modular] +import { isSignInWithEmailLink, parseActionCodeURL, signInWithEmailLink } from "firebase/auth"; +if (isSignInWithEmailLink(auth, window.location.href)) { + const actionCodeUrl = parseActionCodeURL(window.location.href); + if (actionCodeUrl.tenantId) { + auth.tenantId = actionCodeUrl.tenantId; + } + let email = window.localStorage.getItem('emailForSignIn'); + if (!email) { + // User opened the link on a different device. To prevent session fixation + // attacks, ask the user to provide the associated email again. For example: + email = window.prompt('Please provide your email for confirmation'); + } + // The client SDK will parse the code from the link for you. + signInWithEmailLink(auth, email, window.location.href) + .then((result) => { + // User is signed in. + // tenant ID available in result.user.tenantId. + // Clear email from storage. + window.localStorage.removeItem('emailForSignIn'); + }); +} +// [END multitenant_signin_emaillink_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_signin_password.js b/snippets/auth-next/multi-tenancy/multitenant_signin_password.js new file mode 100644 index 00000000..73642a8d --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_signin_password.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_signin_password_modular] +import { signInWithEmailAndPassword } from "firebase/auth"; +auth.tenantId = 'TENANT_ID'; + +signInWithEmailAndPassword(auth, email, password) + .then((userCredential) => { + // User is signed in. + // userCredential.user.tenantId is 'TENANT_ID'. + }).catch((error) => { + // Handle / display error. + // ... + }); +// [END multitenant_signin_password_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_signin_password_demo.js b/snippets/auth-next/multi-tenancy/multitenant_signin_password_demo.js new file mode 100644 index 00000000..87882773 --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_signin_password_demo.js @@ -0,0 +1,33 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_signin_password_demo_modular] +import { signInWithEmailAndPassword, onAuthStateChanged } from "firebase/auth"; +// Switch to TENANT_ID1 +auth.tenantId = 'TENANT_ID1'; + +// Sign in with tenant +signInWithEmailAndPassword(auth, email, password) + .then((userCredential) => { + // User is signed in. + const user = userCredential.user; + // user.tenantId is set to 'TENANT_ID1'. + // Switch to 'TENANT_ID2'. + auth.tenantId = 'TENANT_ID2'; + // auth.currentUser still points to the user. + // auth.currentUser.tenantId is 'TENANT_ID1'. + }); + +// You could also get the current user from Auth state observer. +onAuthStateChanged(auth, (user) => { + if (user) { + // User is signed in. + // user.tenantId is set to 'TENANT_ID1'. + } else { + // No user is signed in. + } +}); +// [END multitenant_signin_password_demo_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_signin_saml_popup.js b/snippets/auth-next/multi-tenancy/multitenant_signin_saml_popup.js new file mode 100644 index 00000000..6aa90550 --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_signin_saml_popup.js @@ -0,0 +1,25 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_signin_saml_popup_modular] +import { signInWithPopup } from "firebase/auth"; +// Switch to TENANT_ID1. +auth.tenantId = 'TENANT_ID1'; + +// Sign-in with popup. +signInWithPopup(auth, provider) + .then((userCredential) => { + // User is signed in. + const user = userCredential.user; + // user.tenantId is set to 'TENANT_ID1'. + // Provider data available from the result.user.getIdToken() + // or from result.user.providerData + }) + .catch((error) => { + // Handle / display error. + // ... + }); +// [END multitenant_signin_saml_popup_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_signin_saml_redirect.js b/snippets/auth-next/multi-tenancy/multitenant_signin_saml_redirect.js new file mode 100644 index 00000000..d3552a56 --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_signin_saml_redirect.js @@ -0,0 +1,29 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_signin_saml_redirect_modular] +import { signInWithRedirect, getRedirectResult } from "firebase/auth"; +// Switch to TENANT_ID1. +auth.tenantId = 'TENANT_ID1'; + +// Sign-in with redirect. +signInWithRedirect(auth, provider); + +// After the user completes sign-in and returns to the app, you can get +// the sign-in result by calling getRedirectResult. However, if they sign out +// and sign in again with an IdP, no tenant is used. +getRedirectResult(auth) + .then((result) => { + // User is signed in. + // The tenant ID available in result.user.tenantId. + // Provider data available from the result.user.getIdToken() + // or from result.user.providerData + }) + .catch((error) => { + // Handle / display error. + // ... + }); +// [END multitenant_signin_saml_redirect_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_signup_password.js b/snippets/auth-next/multi-tenancy/multitenant_signup_password.js new file mode 100644 index 00000000..d89d5edf --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_signup_password.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_signup_password_modular] +import { createUserWithEmailAndPassword } from "firebase/auth"; +auth.tenantId = 'TENANT_ID'; + +createUserWithEmailAndPassword(auth, email, password) + .then((userCredential) => { + // User is signed in. + // userCredential.user.tenantId is 'TENANT_ID'. + }).catch((error) => { + // Handle / display error. + // ... + }); +// [END multitenant_signup_password_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_switch_tenant.js b/snippets/auth-next/multi-tenancy/multitenant_switch_tenant.js new file mode 100644 index 00000000..455e4e3b --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_switch_tenant.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_switch_tenant_modular] +// One Auth instance +// Switch to tenant1 +auth.tenantId = "TENANT_ID1"; +// Switch to tenant2 +auth.tenantId = "TENANT_ID2"; +// Switch back to project level IdPs +auth.tenantId = null; +// [END multitenant_switch_tenant_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_switch_tenant_multiinstance.js b/snippets/auth-next/multi-tenancy/multitenant_switch_tenant_multiinstance.js new file mode 100644 index 00000000..72550493 --- /dev/null +++ b/snippets/auth-next/multi-tenancy/multitenant_switch_tenant_multiinstance.js @@ -0,0 +1,19 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/multi-tenancy.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START multitenant_switch_tenant_multiinstance_modular] +// Multiple Auth instances +import { initializeApp } from "firebase/app"; +import { getAuth } from "firebase/auth"; +const firebaseApp1 = initializeApp(firebaseConfig1, 'app1_for_tenantId1'); +const firebaseApp2 = initializeApp(firebaseConfig2, 'app2_for_tenantId2'); + +const auth1 = getAuth(firebaseApp1); +const auth2 = getAuth(firebaseApp2); + +auth1.tenantId = "TENANT_ID1"; +auth2.tenantId = "TENANT_ID2"; +// [END multitenant_switch_tenant_multiinstance_modular] \ No newline at end of file From 1c4c6834f310bf53a98b3fa3c2e2191396cacd69 Mon Sep 17 00:00:00 2001 From: Ian Tay Date: Thu, 21 Oct 2021 10:38:57 -0700 Subject: [PATCH 201/235] add provider_credential snippets for the social Idps that don't have it. (#253) --- auth-next/facebook.js | 9 +++++++++ auth-next/google-signin.js | 9 +++++++++ auth-next/twitter.js | 7 +++++++ auth/facebook.js | 6 ++++++ auth/google-signin.js | 6 ++++++ auth/initialization.txt | 9 +++++++++ auth/multi-tenancy.js | 2 +- auth/twitter.js | 6 ++++++ .../facebook/auth_facebook_provider_credential.js | 11 +++++++++++ .../google-signin/auth_google_provider_credential.js | 11 +++++++++++ .../twitter/auth_twitter_provider_credential.js | 11 +++++++++++ 11 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 auth/initialization.txt create mode 100644 snippets/auth-next/facebook/auth_facebook_provider_credential.js create mode 100644 snippets/auth-next/google-signin/auth_google_provider_credential.js create mode 100644 snippets/auth-next/twitter/auth_twitter_provider_credential.js diff --git a/auth-next/facebook.js b/auth-next/facebook.js index 4b61f4be..90414d7e 100644 --- a/auth-next/facebook.js +++ b/auth-next/facebook.js @@ -163,3 +163,12 @@ function authWithCredential(credential) { }); // [END auth_facebook_signin_credential] } + +function facebookProviderCredential(accessToken) { + // [START auth_facebook_provider_credential] + const { FacebookAuthProvider } = require("firebase/auth"); + + const credential = FacebookAuthProvider.credential(accessToken); + // [END auth_facebook_provider_credential] +} + diff --git a/auth-next/google-signin.js b/auth-next/google-signin.js index 78b79a61..1e1cee59 100644 --- a/auth-next/google-signin.js +++ b/auth-next/google-signin.js @@ -157,4 +157,13 @@ function isUserEqual_wrapper() { // [END auth_google_checksameuser] } +function googleProviderCredential(idToken) { + // [START auth_google_provider_credential] + const { GoogleAuthProvider } = require("firebase/auth"); + + const credential = GoogleAuthProvider.credential(idToken); + // [END auth_google_provider_credential] +} + + diff --git a/auth-next/twitter.js b/auth-next/twitter.js index 8024bbe5..57416b03 100644 --- a/auth-next/twitter.js +++ b/auth-next/twitter.js @@ -73,3 +73,10 @@ function twitterSignInRedirectResult() { // [END auth_twitter_signin_redirect_result] } +function twitterProviderCredential(accessToken, secret) { + // [START auth_twitter_provider_credential] + const { TwitterAuthProvider } = require("firebase/auth"); + + const credential = TwitterAuthProvider.credential(accessToken, secret); + // [END auth_twitter_provider_credential] +} \ No newline at end of file diff --git a/auth/facebook.js b/auth/facebook.js index 3e5c5b14..4259960d 100644 --- a/auth/facebook.js +++ b/auth/facebook.js @@ -151,3 +151,9 @@ function authWithCredential(credential) { }); // [END auth_facebook_signin_credential] } + +function facebookProviderCredential(accessToken) { + // [START auth_facebook_provider_credential] + var credential = firebase.auth.FacebookAuthProvider.credential(accessToken); + // [END auth_facebook_provider_credential] +} diff --git a/auth/google-signin.js b/auth/google-signin.js index 908a32e1..fcc32dc8 100644 --- a/auth/google-signin.js +++ b/auth/google-signin.js @@ -142,3 +142,9 @@ function isUserEqual(googleUser, firebaseUser) { return false; } // [END auth_google_checksameuser] + +function googleProviderCredential(idToken) { + // [START auth_google_provider_credential] + var credential = firebase.auth.GoogleAuthProvider.credential(idToken); + // [END auth_google_provider_credential] +} diff --git a/auth/initialization.txt b/auth/initialization.txt new file mode 100644 index 00000000..bccb0571 --- /dev/null +++ b/auth/initialization.txt @@ -0,0 +1,9 @@ + + \ No newline at end of file diff --git a/auth/multi-tenancy.js b/auth/multi-tenancy.js index 8afc1a5c..8b31e145 100644 --- a/auth/multi-tenancy.js +++ b/auth/multi-tenancy.js @@ -23,7 +23,7 @@ function switchTenantSingleAuth() { // [END multitenant_switch_tenant] } -function switchTenantMultiAuthInstance(config) { +function switchTenantMultiAuth(config) { // [START multitenant_switch_tenant_multiinstance] // Multiple Auth instances firebase.initializeApp(config, 'app1_for_tenantId1'); diff --git a/auth/twitter.js b/auth/twitter.js index b1ca2581..a78370b7 100644 --- a/auth/twitter.js +++ b/auth/twitter.js @@ -76,3 +76,9 @@ function twitterSignInRedirectResult() { }); // [END auth_twitter_signin_redirect_result] } + +function twitterProviderCredential(accessToken, secret) { + // [START auth_twitter_provider_credential] + var credential = firebase.auth.TwitterAuthProvider.credential(accessToken, secret); + // [END auth_twitter_provider_credential] +} \ No newline at end of file diff --git a/snippets/auth-next/facebook/auth_facebook_provider_credential.js b/snippets/auth-next/facebook/auth_facebook_provider_credential.js new file mode 100644 index 00000000..b7bbca25 --- /dev/null +++ b/snippets/auth-next/facebook/auth_facebook_provider_credential.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/facebook.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_facebook_provider_credential_modular] +import { FacebookAuthProvider } from "firebase/auth"; + +const credential = FacebookAuthProvider.credential(accessToken); +// [END auth_facebook_provider_credential_modular] \ No newline at end of file diff --git a/snippets/auth-next/google-signin/auth_google_provider_credential.js b/snippets/auth-next/google-signin/auth_google_provider_credential.js new file mode 100644 index 00000000..924aa167 --- /dev/null +++ b/snippets/auth-next/google-signin/auth_google_provider_credential.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/google-signin.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_google_provider_credential_modular] +import { GoogleAuthProvider } from "firebase/auth"; + +const credential = GoogleAuthProvider.credential(idToken); +// [END auth_google_provider_credential_modular] \ No newline at end of file diff --git a/snippets/auth-next/twitter/auth_twitter_provider_credential.js b/snippets/auth-next/twitter/auth_twitter_provider_credential.js new file mode 100644 index 00000000..e25b369c --- /dev/null +++ b/snippets/auth-next/twitter/auth_twitter_provider_credential.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/twitter.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START auth_twitter_provider_credential_modular] +import { TwitterAuthProvider } from "firebase/auth"; + +const credential = TwitterAuthProvider.credential(accessToken, secret); +// [END auth_twitter_provider_credential_modular] \ No newline at end of file From 509769a817d7437616bcfcb816f783b29aaca843 Mon Sep 17 00:00:00 2001 From: Ersin Ertan <4809853+ersin-ertan@users.noreply.github.com> Date: Fri, 21 Jan 2022 16:18:29 -0500 Subject: [PATCH 202/235] Update method in comment for getting the id token (#262) Sources - https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/src/model/user.ts#L85 - https://firebase.google.com/docs/reference/js/v8/firebase.User#getidtoken - https://firebase.google.com/docs/reference/js/auth.user.md#usergetidtoken - https://firebase.google.com/docs/auth/web/manage-users#get_a_users_profile --- auth/manage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/manage.js b/auth/manage.js index 7163ef00..217199f2 100644 --- a/auth/manage.js +++ b/auth/manage.js @@ -16,7 +16,7 @@ function getUserProfile() { // The user's ID, unique to the Firebase project. Do NOT use // this value to authenticate with your backend server, if - // you have one. Use User.getToken() instead. + // you have one. Use User.getIdToken() instead. const uid = user.uid; } // [END auth_get_user_profile] From 9bdf357b4b667c71b0914f4af9fa6210b4a953d5 Mon Sep 17 00:00:00 2001 From: Yarego Brozek <78966160+devkiloton@users.noreply.github.com> Date: Thu, 21 Apr 2022 11:31:19 -0300 Subject: [PATCH 203/235] adding missing code in a snippet (#288) --- database-next/read-and-write.js | 2 +- .../database-next/read-and-write/rtdb_social_write_fan_out.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/database-next/read-and-write.js b/database-next/read-and-write.js index 2cbd5c5b..4196c0d7 100644 --- a/database-next/read-and-write.js +++ b/database-next/read-and-write.js @@ -74,9 +74,9 @@ function socialSingleValueRead() { } function writeNewPost_wrapped() { + // [START rtdb_social_write_fan_out] const { getDatabase, ref, child, push, update } = require("firebase/database"); - // [START rtdb_social_write_fan_out] function writeNewPost(uid, username, picture, title, body) { const db = getDatabase(); diff --git a/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js b/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js index f787d4bd..783eca2b 100644 --- a/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js +++ b/snippets/database-next/read-and-write/rtdb_social_write_fan_out.js @@ -5,6 +5,8 @@ // 'npm run snippets'. // [START rtdb_social_write_fan_out_modular] +import { getDatabase, ref, child, push, update } from "firebase/database"; + function writeNewPost(uid, username, picture, title, body) { const db = getDatabase(); From 69c85abdc7cd6990618720cd33aa0d1ee357c652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ros=C3=A1rio=20Pereira=20Fernandes?= Date: Thu, 19 May 2022 13:37:24 +0100 Subject: [PATCH 204/235] fix error handling on v9 auth snippets (#289) --- auth-next/apple.js | 6 +++--- auth-next/facebook.js | 8 ++++---- auth-next/github.js | 4 ++-- auth-next/google-signin.js | 8 ++++---- auth-next/index.js | 2 +- auth-next/multi-tenancy.js | 4 ++-- auth-next/oidc.js | 6 +++--- auth-next/saml.js | 4 ++-- auth-next/twitter.js | 4 ++-- .../auth-next/apple/auth_apple_reauthenticate_popup.js | 2 +- snippets/auth-next/apple/auth_apple_signin_popup.js | 2 +- .../auth-next/apple/auth_apple_signin_redirect_result.js | 2 +- snippets/auth-next/facebook/auth_facebook_callback.js | 2 +- .../auth-next/facebook/auth_facebook_signin_credential.js | 2 +- snippets/auth-next/facebook/auth_facebook_signin_popup.js | 2 +- .../facebook/auth_facebook_signin_redirect_result.js | 2 +- snippets/auth-next/github/auth_github_signin_popup.js | 2 +- .../github/auth_github_signin_redirect_result.js | 2 +- .../auth-next/google-signin/auth_google_build_signin.js | 2 +- snippets/auth-next/google-signin/auth_google_callback.js | 2 +- .../google-signin/auth_google_signin_credential.js | 2 +- .../auth-next/google-signin/auth_google_signin_popup.js | 2 +- .../google-signin/auth_google_signin_redirect_result.js | 2 +- snippets/auth-next/index/auth_signin_credential.js | 2 +- .../multi-tenancy/multitenant_account_exists_popup.js | 2 +- .../multi-tenancy/multitenant_account_exists_redirect.js | 2 +- snippets/auth-next/oidc/auth_oidc_direct_sign_in.js | 2 +- snippets/auth-next/oidc/auth_oidc_signin_popup.js | 2 +- .../auth-next/oidc/auth_oidc_signin_redirect_result.js | 2 +- snippets/auth-next/saml/auth_saml_signin_popup.js | 2 +- .../auth-next/saml/auth_saml_signin_redirect_result.js | 2 +- snippets/auth-next/twitter/auth_twitter_signin_popup.js | 2 +- .../twitter/auth_twitter_signin_redirect_result.js | 2 +- 33 files changed, 47 insertions(+), 47 deletions(-) diff --git a/auth-next/apple.js b/auth-next/apple.js index 29a33dea..7cffca8b 100644 --- a/auth-next/apple.js +++ b/auth-next/apple.js @@ -45,7 +45,7 @@ function appleSignInPopup(provider) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The credential that was used. const credential = OAuthProvider.credentialFromError(error); @@ -85,7 +85,7 @@ function appleSignInRedirectResult() { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The credential that was used. const credential = OAuthProvider.credentialFromError(error); @@ -123,7 +123,7 @@ function appleReauthenticatePopup() { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The credential that was used. const credential = OAuthProvider.credentialFromError(error); diff --git a/auth-next/facebook.js b/auth-next/facebook.js index 90414d7e..67b397f2 100644 --- a/auth-next/facebook.js +++ b/auth-next/facebook.js @@ -40,7 +40,7 @@ function facebookSignInPopup(provider) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = FacebookAuthProvider.credentialFromError(error); @@ -66,7 +66,7 @@ function facebookSignInRedirectResult() { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // AuthCredential type that was used. const credential = FacebookAuthProvider.credentialFromError(error); // ... @@ -102,7 +102,7 @@ function checkLoginState_wrapper() { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = FacebookAuthProvider.credentialFromError(error); // ... @@ -156,7 +156,7 @@ function authWithCredential(credential) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = FacebookAuthProvider.credentialFromError(error); // ... diff --git a/auth-next/github.js b/auth-next/github.js index 941a9047..babfd1ee 100644 --- a/auth-next/github.js +++ b/auth-next/github.js @@ -46,7 +46,7 @@ function githubSignInPopup(provider) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = GithubAuthProvider.credentialFromError(error); // ... @@ -75,7 +75,7 @@ function githubSignInRedirectResult() { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = GithubAuthProvider.credentialFromError(error); // ... diff --git a/auth-next/google-signin.js b/auth-next/google-signin.js index 1e1cee59..136c26b5 100644 --- a/auth-next/google-signin.js +++ b/auth-next/google-signin.js @@ -39,7 +39,7 @@ function googleSignInPopup(provider) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = GoogleAuthProvider.credentialFromError(error); // ... @@ -65,7 +65,7 @@ function googleSignInRedirectResult() { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = GoogleAuthProvider.credentialFromError(error); // ... @@ -87,7 +87,7 @@ function googleBuildAndSignIn(id_token) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = GoogleAuthProvider.credentialFromError(error); // ... @@ -123,7 +123,7 @@ function onSignIn_wrapper() { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The credential that was used. const credential = GoogleAuthProvider.credentialFromError(error); // ... diff --git a/auth-next/index.js b/auth-next/index.js index c4dadfe0..b4a17903 100644 --- a/auth-next/index.js +++ b/auth-next/index.js @@ -107,7 +107,7 @@ function authWithCredential(credential) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // ... }); // [END auth_signin_credential] diff --git a/auth-next/multi-tenancy.js b/auth-next/multi-tenancy.js index c0c86662..d7577f34 100644 --- a/auth-next/multi-tenancy.js +++ b/auth-next/multi-tenancy.js @@ -273,7 +273,7 @@ function accountExistsPopupTenant(auth, samlProvider, googleProvider, goToApp) { const pendingCred = error.credential; // The credential's tenantId if needed: error.tenantId // The provider account's email address. - const email = error.email; + const email = error.customData.email; // Get sign-in methods for this email. fetchSignInMethodsForEmail(email, auth) .then((methods) => { @@ -315,7 +315,7 @@ function accountExistsRedirectTenant(auth, samlProvider, googleProvider, goToApp // The pending SAML credential. pendingCred = error.credential; // The provider account's email address. - const email = error.email; + const email = error.customData.email; // Need to set the tenant ID again as the page was reloaded and the // previous setting was reset. auth.tenantId = tenantId; diff --git a/auth-next/oidc.js b/auth-next/oidc.js index 5dc20e81..dae69fe9 100644 --- a/auth-next/oidc.js +++ b/auth-next/oidc.js @@ -24,7 +24,7 @@ function oidcSignInPopup(provider) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = OAuthProvider.credentialFromError(error); // Handle / display error. @@ -58,7 +58,7 @@ function oidcSignInRedirectResult(provider) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = OAuthProvider.credentialFromError(error); // Handle / display error. @@ -86,7 +86,7 @@ function oidcDirectSignIn(provider, oidcIdToken) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = OAuthProvider.credentialFromError(error); // Handle / display error. diff --git a/auth-next/saml.js b/auth-next/saml.js index 9a5683d9..cdecce56 100644 --- a/auth-next/saml.js +++ b/auth-next/saml.js @@ -24,7 +24,7 @@ function samlSignInPopup(provider) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = SAMLAuthProvider.credentialFromError(error); // Handle / display error. @@ -58,7 +58,7 @@ function samlSignInRedirectResult(provider) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = SAMLAuthProvider.credentialFromError(error); // Handle / display error. diff --git a/auth-next/twitter.js b/auth-next/twitter.js index 57416b03..a386e4ab 100644 --- a/auth-next/twitter.js +++ b/auth-next/twitter.js @@ -36,7 +36,7 @@ function twitterSignInPopup(provider) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = TwitterAuthProvider.credentialFromError(error); // ... @@ -65,7 +65,7 @@ function twitterSignInRedirectResult() { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = TwitterAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js b/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js index 129fe920..cd40151d 100644 --- a/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js +++ b/snippets/auth-next/apple/auth_apple_reauthenticate_popup.js @@ -32,7 +32,7 @@ reauthenticateWithPopup(auth.currentUser, provider) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The credential that was used. const credential = OAuthProvider.credentialFromError(error); diff --git a/snippets/auth-next/apple/auth_apple_signin_popup.js b/snippets/auth-next/apple/auth_apple_signin_popup.js index 2db09607..c2a392cf 100644 --- a/snippets/auth-next/apple/auth_apple_signin_popup.js +++ b/snippets/auth-next/apple/auth_apple_signin_popup.js @@ -25,7 +25,7 @@ signInWithPopup(auth, provider) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The credential that was used. const credential = OAuthProvider.credentialFromError(error); diff --git a/snippets/auth-next/apple/auth_apple_signin_redirect_result.js b/snippets/auth-next/apple/auth_apple_signin_redirect_result.js index 68dba4ab..654f95e5 100644 --- a/snippets/auth-next/apple/auth_apple_signin_redirect_result.js +++ b/snippets/auth-next/apple/auth_apple_signin_redirect_result.js @@ -25,7 +25,7 @@ getRedirectResult(auth) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The credential that was used. const credential = OAuthProvider.credentialFromError(error); diff --git a/snippets/auth-next/facebook/auth_facebook_callback.js b/snippets/auth-next/facebook/auth_facebook_callback.js index 8596bb68..63106871 100644 --- a/snippets/auth-next/facebook/auth_facebook_callback.js +++ b/snippets/auth-next/facebook/auth_facebook_callback.js @@ -26,7 +26,7 @@ function checkLoginState(response) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = FacebookAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/facebook/auth_facebook_signin_credential.js b/snippets/auth-next/facebook/auth_facebook_signin_credential.js index dcd42c7e..3b784f24 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_credential.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_credential.js @@ -19,7 +19,7 @@ signInWithCredential(auth, credential) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = FacebookAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/facebook/auth_facebook_signin_popup.js b/snippets/auth-next/facebook/auth_facebook_signin_popup.js index 2bc014ed..7d35aaf2 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_popup.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_popup.js @@ -24,7 +24,7 @@ signInWithPopup(auth, provider) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = FacebookAuthProvider.credentialFromError(error); diff --git a/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js b/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js index 49f3a494..eb6cdb30 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js @@ -20,7 +20,7 @@ getRedirectResult(auth) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // AuthCredential type that was used. const credential = FacebookAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/github/auth_github_signin_popup.js b/snippets/auth-next/github/auth_github_signin_popup.js index 74e76cc9..e1b4768e 100644 --- a/snippets/auth-next/github/auth_github_signin_popup.js +++ b/snippets/auth-next/github/auth_github_signin_popup.js @@ -22,7 +22,7 @@ signInWithPopup(auth, provider) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = GithubAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/github/auth_github_signin_redirect_result.js b/snippets/auth-next/github/auth_github_signin_redirect_result.js index 6147d9de..b3d31d0a 100644 --- a/snippets/auth-next/github/auth_github_signin_redirect_result.js +++ b/snippets/auth-next/github/auth_github_signin_redirect_result.js @@ -24,7 +24,7 @@ getRedirectResult(auth) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = GithubAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/google-signin/auth_google_build_signin.js b/snippets/auth-next/google-signin/auth_google_build_signin.js index 6df84e3e..98f35eb2 100644 --- a/snippets/auth-next/google-signin/auth_google_build_signin.js +++ b/snippets/auth-next/google-signin/auth_google_build_signin.js @@ -17,7 +17,7 @@ signInWithCredential(auth, credential).catch((error) => { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = GoogleAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/google-signin/auth_google_callback.js b/snippets/auth-next/google-signin/auth_google_callback.js index 27aa8dc6..873778dd 100644 --- a/snippets/auth-next/google-signin/auth_google_callback.js +++ b/snippets/auth-next/google-signin/auth_google_callback.js @@ -25,7 +25,7 @@ function onSignIn(googleUser) { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The credential that was used. const credential = GoogleAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/google-signin/auth_google_signin_credential.js b/snippets/auth-next/google-signin/auth_google_signin_credential.js index a3a8808e..25c6f3ba 100644 --- a/snippets/auth-next/google-signin/auth_google_signin_credential.js +++ b/snippets/auth-next/google-signin/auth_google_signin_credential.js @@ -10,7 +10,7 @@ signInWithCredential(auth, credential).catch((error) => { const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The credential that was used. const credential = GoogleAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/google-signin/auth_google_signin_popup.js b/snippets/auth-next/google-signin/auth_google_signin_popup.js index 55c46488..d6c70eb9 100644 --- a/snippets/auth-next/google-signin/auth_google_signin_popup.js +++ b/snippets/auth-next/google-signin/auth_google_signin_popup.js @@ -21,7 +21,7 @@ signInWithPopup(auth, provider) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = GoogleAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js b/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js index a64977bb..50c4aded 100644 --- a/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js +++ b/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js @@ -21,7 +21,7 @@ getRedirectResult(auth) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = GoogleAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/index/auth_signin_credential.js b/snippets/auth-next/index/auth_signin_credential.js index ba2db6b8..c2b027a3 100644 --- a/snippets/auth-next/index/auth_signin_credential.js +++ b/snippets/auth-next/index/auth_signin_credential.js @@ -19,7 +19,7 @@ signInWithCredential(auth, credential) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // ... }); // [END auth_signin_credential_modular] \ No newline at end of file diff --git a/snippets/auth-next/multi-tenancy/multitenant_account_exists_popup.js b/snippets/auth-next/multi-tenancy/multitenant_account_exists_popup.js index 43734616..7bf33262 100644 --- a/snippets/auth-next/multi-tenancy/multitenant_account_exists_popup.js +++ b/snippets/auth-next/multi-tenancy/multitenant_account_exists_popup.js @@ -19,7 +19,7 @@ signInWithPopup(auth, samlProvider) const pendingCred = error.credential; // The credential's tenantId if needed: error.tenantId // The provider account's email address. - const email = error.email; + const email = error.customData.email; // Get sign-in methods for this email. fetchSignInMethodsForEmail(email, auth) .then((methods) => { diff --git a/snippets/auth-next/multi-tenancy/multitenant_account_exists_redirect.js b/snippets/auth-next/multi-tenancy/multitenant_account_exists_redirect.js index f8a3942d..a81617dd 100644 --- a/snippets/auth-next/multi-tenancy/multitenant_account_exists_redirect.js +++ b/snippets/auth-next/multi-tenancy/multitenant_account_exists_redirect.js @@ -20,7 +20,7 @@ getRedirectResult(auth).catch((error) => { // The pending SAML credential. pendingCred = error.credential; // The provider account's email address. - const email = error.email; + const email = error.customData.email; // Need to set the tenant ID again as the page was reloaded and the // previous setting was reset. auth.tenantId = tenantId; diff --git a/snippets/auth-next/oidc/auth_oidc_direct_sign_in.js b/snippets/auth-next/oidc/auth_oidc_direct_sign_in.js index 65f693a6..558fd915 100644 --- a/snippets/auth-next/oidc/auth_oidc_direct_sign_in.js +++ b/snippets/auth-next/oidc/auth_oidc_direct_sign_in.js @@ -22,7 +22,7 @@ signInWithCredential(auth, credential) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = OAuthProvider.credentialFromError(error); // Handle / display error. diff --git a/snippets/auth-next/oidc/auth_oidc_signin_popup.js b/snippets/auth-next/oidc/auth_oidc_signin_popup.js index 76b01b1d..130d617e 100644 --- a/snippets/auth-next/oidc/auth_oidc_signin_popup.js +++ b/snippets/auth-next/oidc/auth_oidc_signin_popup.js @@ -18,7 +18,7 @@ signInWithPopup(auth, provider) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = OAuthProvider.credentialFromError(error); // Handle / display error. diff --git a/snippets/auth-next/oidc/auth_oidc_signin_redirect_result.js b/snippets/auth-next/oidc/auth_oidc_signin_redirect_result.js index ae5a441d..bc76a620 100644 --- a/snippets/auth-next/oidc/auth_oidc_signin_redirect_result.js +++ b/snippets/auth-next/oidc/auth_oidc_signin_redirect_result.js @@ -19,7 +19,7 @@ getRedirectResult(auth) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = OAuthProvider.credentialFromError(error); // Handle / display error. diff --git a/snippets/auth-next/saml/auth_saml_signin_popup.js b/snippets/auth-next/saml/auth_saml_signin_popup.js index 8010a17b..3a922a9a 100644 --- a/snippets/auth-next/saml/auth_saml_signin_popup.js +++ b/snippets/auth-next/saml/auth_saml_signin_popup.js @@ -18,7 +18,7 @@ signInWithPopup(auth, provider) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = SAMLAuthProvider.credentialFromError(error); // Handle / display error. diff --git a/snippets/auth-next/saml/auth_saml_signin_redirect_result.js b/snippets/auth-next/saml/auth_saml_signin_redirect_result.js index 4e4d4260..e4bf73de 100644 --- a/snippets/auth-next/saml/auth_saml_signin_redirect_result.js +++ b/snippets/auth-next/saml/auth_saml_signin_redirect_result.js @@ -19,7 +19,7 @@ getRedirectResult(auth) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = SAMLAuthProvider.credentialFromError(error); // Handle / display error. diff --git a/snippets/auth-next/twitter/auth_twitter_signin_popup.js b/snippets/auth-next/twitter/auth_twitter_signin_popup.js index a5fb5a95..ae8e2007 100644 --- a/snippets/auth-next/twitter/auth_twitter_signin_popup.js +++ b/snippets/auth-next/twitter/auth_twitter_signin_popup.js @@ -24,7 +24,7 @@ signInWithPopup(auth, provider) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = TwitterAuthProvider.credentialFromError(error); // ... diff --git a/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js b/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js index 53b42c85..73e42bab 100644 --- a/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js +++ b/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js @@ -24,7 +24,7 @@ getRedirectResult(auth) const errorCode = error.code; const errorMessage = error.message; // The email of the user's account used. - const email = error.email; + const email = error.customData.email; // The AuthCredential type that was used. const credential = TwitterAuthProvider.credentialFromError(error); // ... From 2b97722e03d0276347523590ae8f6588ca5cf79b Mon Sep 17 00:00:00 2001 From: Frank van Puffelen Date: Fri, 10 Jun 2022 04:18:10 -0700 Subject: [PATCH 205/235] Fix nesting issue in collection group query sample (#280) --- firestore-next/test.firestore.js | 22 +++++++++---------- .../fs_collection_group_query_data_setup.js | 22 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 71c54b95..59ab267b 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -1095,48 +1095,48 @@ describe("firestore", () => { describe('collectionGroup(landmarks)', () => { it("should setup example data", async () => { // [START fs_collection_group_query_data_setup] - const { collection, doc, setDoc } = require("firebase/firestore"); + const { collection, addDoc } = require("firebase/firestore"); const citiesRef = collection(db, 'cities'); await Promise.all([ - setDoc(doc(citiesRef, 'SF', 'landmarks'), { + addDoc(collection(citiesRef, 'SF', 'landmarks'), { name: 'Golden Gate Bridge', type: 'bridge' }), - setDoc(doc(citiesRef, 'SF', 'landmarks'), { + addDoc(collection(citiesRef, 'SF', 'landmarks'), { name: 'Legion of Honor', type: 'museum' }), - setDoc(doc(citiesRef, 'LA', 'landmarks'), { + addDoc(collection(citiesRef, 'LA', 'landmarks'), { name: 'Griffith Park', type: 'park' }), - setDoc(doc(citiesRef, 'LA', 'landmarks'), { + addDoc(collection(citiesRef, 'LA', 'landmarks'), { name: 'The Getty', type: 'museum' }), - setDoc(doc(citiesRef, 'DC', 'landmarks'), { + addDoc(collection(citiesRef, 'DC', 'landmarks'), { name: 'Lincoln Memorial', type: 'memorial' }), - setDoc(doc(citiesRef, 'DC', 'landmarks'), { + addDoc(collection(citiesRef, 'DC', 'landmarks'), { name: 'National Air and Space Museum', type: 'museum' }), - setDoc(doc(citiesRef, 'TOK', 'landmarks'), { + addDoc(collection(citiesRef, 'TOK', 'landmarks'), { name: 'Ueno Park', type: 'park' }), - setDoc(doc(citiesRef, 'TOK', 'landmarks'), { + addDoc(collection(citiesRef, 'TOK', 'landmarks'), { name: 'National Museum of Nature and Science', type: 'museum' }), - setDoc(doc(citiesRef, 'BJ', 'landmarks'), { + addDoc(collection(citiesRef, 'BJ', 'landmarks'), { name: 'Jingshan Park', type: 'park' }), - setDoc(doc(citiesRef, 'BJ', 'landmarks'), { + addDoc(collection(citiesRef, 'BJ', 'landmarks'), { name: 'Beijing Ancient Observatory', type: 'museum' }) diff --git a/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js b/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js index f4f62178..f06ea0f8 100644 --- a/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js +++ b/snippets/firestore-next/test-firestore/fs_collection_group_query_data_setup.js @@ -5,48 +5,48 @@ // 'npm run snippets'. // [START fs_collection_group_query_data_setup_modular] -import { collection, doc, setDoc } from "firebase/firestore"; +import { collection, addDoc } from "firebase/firestore"; const citiesRef = collection(db, 'cities'); await Promise.all([ - setDoc(doc(citiesRef, 'SF', 'landmarks'), { + addDoc(collection(citiesRef, 'SF', 'landmarks'), { name: 'Golden Gate Bridge', type: 'bridge' }), - setDoc(doc(citiesRef, 'SF', 'landmarks'), { + addDoc(collection(citiesRef, 'SF', 'landmarks'), { name: 'Legion of Honor', type: 'museum' }), - setDoc(doc(citiesRef, 'LA', 'landmarks'), { + addDoc(collection(citiesRef, 'LA', 'landmarks'), { name: 'Griffith Park', type: 'park' }), - setDoc(doc(citiesRef, 'LA', 'landmarks'), { + addDoc(collection(citiesRef, 'LA', 'landmarks'), { name: 'The Getty', type: 'museum' }), - setDoc(doc(citiesRef, 'DC', 'landmarks'), { + addDoc(collection(citiesRef, 'DC', 'landmarks'), { name: 'Lincoln Memorial', type: 'memorial' }), - setDoc(doc(citiesRef, 'DC', 'landmarks'), { + addDoc(collection(citiesRef, 'DC', 'landmarks'), { name: 'National Air and Space Museum', type: 'museum' }), - setDoc(doc(citiesRef, 'TOK', 'landmarks'), { + addDoc(collection(citiesRef, 'TOK', 'landmarks'), { name: 'Ueno Park', type: 'park' }), - setDoc(doc(citiesRef, 'TOK', 'landmarks'), { + addDoc(collection(citiesRef, 'TOK', 'landmarks'), { name: 'National Museum of Nature and Science', type: 'museum' }), - setDoc(doc(citiesRef, 'BJ', 'landmarks'), { + addDoc(collection(citiesRef, 'BJ', 'landmarks'), { name: 'Jingshan Park', type: 'park' }), - setDoc(doc(citiesRef, 'BJ', 'landmarks'), { + addDoc(collection(citiesRef, 'BJ', 'landmarks'), { name: 'Beijing Ancient Observatory', type: 'museum' }) From 71c95ee64a0ddc4e2692e0461fc5eb553cff0252 Mon Sep 17 00:00:00 2001 From: CommanderRoot Date: Fri, 10 Jun 2022 13:24:36 +0200 Subject: [PATCH 206/235] refactor: replace deprecated String.prototype.substr() (#281) .substr() is deprecated so we replace it with .slice() which works similarily but isn't deprecated --- auth-next/apple.js | 2 +- auth/apple.js | 2 +- scripts/separate-snippets.ts | 2 +- snippets/auth-next/apple/auth_apple_nonce_node.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/auth-next/apple.js b/auth-next/apple.js index 7cffca8b..f9670b4c 100644 --- a/auth-next/apple.js +++ b/auth-next/apple.js @@ -169,7 +169,7 @@ function appleNonceNode() { crypto.randomFillSync(buf); nonce = decoder.write(buf); } - return nonce.substr(0, length); + return nonce.slice(0, length); }; const unhashedNonce = generateNonce(10); diff --git a/auth/apple.js b/auth/apple.js index ad65ef08..e99349c8 100644 --- a/auth/apple.js +++ b/auth/apple.js @@ -170,7 +170,7 @@ function appleNonceNode() { crypto.randomFillSync(buf); nonce = decoder.write(buf); } - return nonce.substr(0, length); + return nonce.slice(0, length); }; const unhashedNonce = generateNonce(10); diff --git a/scripts/separate-snippets.ts b/scripts/separate-snippets.ts index ff93a58f..a888d908 100644 --- a/scripts/separate-snippets.ts +++ b/scripts/separate-snippets.ts @@ -77,7 +77,7 @@ function adjustIndentation(lines: string[]) { if (isBlank(line)) { outputLines.push(""); } else { - outputLines.push(line.substr(minIndent)); + outputLines.push(line.slice(minIndent)); } } return outputLines; diff --git a/snippets/auth-next/apple/auth_apple_nonce_node.js b/snippets/auth-next/apple/auth_apple_nonce_node.js index 26bb2ef0..9dd417a5 100644 --- a/snippets/auth-next/apple/auth_apple_nonce_node.js +++ b/snippets/auth-next/apple/auth_apple_nonce_node.js @@ -17,7 +17,7 @@ const generateNonce = (length) => { crypto.randomFillSync(buf); nonce = decoder.write(buf); } - return nonce.substr(0, length); + return nonce.slice(0, length); }; const unhashedNonce = generateNonce(10); From 01d37b7b0a42e5304d172543b986282d0d61d214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ros=C3=A1rio=20Pereira=20Fernandes?= Date: Fri, 10 Jun 2022 12:33:42 +0100 Subject: [PATCH 207/235] popuation --> population (#296) --- firestore-next/test.firestore.js | 2 +- snippets/firestore-next/test-firestore/start_doc.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 59ab267b..17ff6d29 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -1048,7 +1048,7 @@ describe("firestore", () => { const docSnap = await getDoc(doc(citiesRef, "SF")); // Get all cities with a population bigger than San Francisco - const biggerThanSf = query(citiesRef, orderBy("popuation"), startAt(docSnap)); + const biggerThanSf = query(citiesRef, orderBy("population"), startAt(docSnap)); // ... // [END start_doc] }); diff --git a/snippets/firestore-next/test-firestore/start_doc.js b/snippets/firestore-next/test-firestore/start_doc.js index e75c7984..88448fcd 100644 --- a/snippets/firestore-next/test-firestore/start_doc.js +++ b/snippets/firestore-next/test-firestore/start_doc.js @@ -11,6 +11,6 @@ const citiesRef = collection(db, "cities"); const docSnap = await getDoc(doc(citiesRef, "SF")); // Get all cities with a population bigger than San Francisco -const biggerThanSf = query(citiesRef, orderBy("popuation"), startAt(docSnap)); +const biggerThanSf = query(citiesRef, orderBy("population"), startAt(docSnap)); // ... // [END start_doc_modular] \ No newline at end of file From 1a603211c8970d98630f0054761c9ad32620e725 Mon Sep 17 00:00:00 2001 From: Guy Torbet <61030227+Torbet@users.noreply.github.com> Date: Tue, 28 Jun 2022 19:17:23 +0100 Subject: [PATCH 208/235] shoud --> should (#298) "Should Paginate" to "Should paginate" --- firestore/test.firestore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index 2aadf8d5..dbf6e18e 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -1011,7 +1011,7 @@ describe("firestore", () => { // [END start_multiple_orderby] }); - it("shoud paginate", () => { + it("should paginate", () => { // [START paginate] var first = db.collection("cities") .orderBy("population") From 5879ad7dedb29c6703bf94f760f6c55073c7c4ac Mon Sep 17 00:00:00 2001 From: Frank van Puffelen Date: Wed, 6 Jul 2022 15:55:52 -0700 Subject: [PATCH 209/235] Fix tiny type (#299) --- auth/manage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/manage.js b/auth/manage.js index 217199f2..0e1f0e7b 100644 --- a/auth/manage.js +++ b/auth/manage.js @@ -144,7 +144,7 @@ function reauthenticateWithCredential() { user.reauthenticateWithCredential(credential).then(() => { // User re-authenticated. }).catch((error) => { - // An error ocurred + // An error occurred // ... }); // [END auth_reauth_with_credential] From 7403e77cc6b0c9bae8e9cd9d43f58eb93df2241a Mon Sep 17 00:00:00 2001 From: Andrea Wu <1359259+andreaowu@users.noreply.github.com> Date: Thu, 8 Sep 2022 14:24:27 +0200 Subject: [PATCH 210/235] analytics select_content should not have items (#300) --- analytics-next/index.js | 3 +-- snippets/analytics-next/index/analytics_log_event_params.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/analytics-next/index.js b/analytics-next/index.js index 510fa758..2b736cde 100644 --- a/analytics-next/index.js +++ b/analytics-next/index.js @@ -27,8 +27,7 @@ function logEventParams() { const analytics = getAnalytics(); logEvent(analytics, 'select_content', { content_type: 'image', - content_id: 'P12453', - items: [{ name: 'Kittens' }] + content_id: 'P12453' }); // [END analytics_log_event_params] } diff --git a/snippets/analytics-next/index/analytics_log_event_params.js b/snippets/analytics-next/index/analytics_log_event_params.js index 27e6528d..e79d7ec0 100644 --- a/snippets/analytics-next/index/analytics_log_event_params.js +++ b/snippets/analytics-next/index/analytics_log_event_params.js @@ -10,7 +10,6 @@ import { getAnalytics, logEvent } from "firebase/analytics"; const analytics = getAnalytics(); logEvent(analytics, 'select_content', { content_type: 'image', - content_id: 'P12453', - items: [{ name: 'Kittens' }] + content_id: 'P12453' }); // [END analytics_log_event_params_modular] \ No newline at end of file From 8eb8a7c7c59049edb01398a2743562192e397227 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 20 Oct 2022 14:46:57 -0700 Subject: [PATCH 211/235] Auto-update dependencies. (#241) --- analytics-next/package.json | 2 +- appcheck-next/package.json | 2 +- auth-next/package.json | 2 +- database-next/package.json | 2 +- firebaseapp-next/package.json | 2 +- firestore-next/package.json | 2 +- functions-next/package.json | 2 +- messaging-next/package.json | 2 +- perf-next/package.json | 2 +- remoteconfig-next/package.json | 2 +- storage-next/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index d0955d16..0fb07418 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.1.0" + "firebase": "^9.12.1" } } diff --git a/appcheck-next/package.json b/appcheck-next/package.json index 7c84b7df..ad78db9f 100644 --- a/appcheck-next/package.json +++ b/appcheck-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.1.0" + "firebase": "^9.12.1" } } diff --git a/auth-next/package.json b/auth-next/package.json index 53d964a2..48adc595 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.1.0" + "firebase": "^9.12.1" } } diff --git a/database-next/package.json b/database-next/package.json index 175d6c63..be3cab88 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.1.0" + "firebase": "^9.12.1" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index 88dd8954..d7b654df 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.1.0" + "firebase": "^9.12.1" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 2c95f580..39b5c6a9 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.1.0", + "firebase": "^9.12.1", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/package.json b/functions-next/package.json index 4ddfe8c3..618ee0c5 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.1.0" + "firebase": "^9.12.1" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index fe28f50e..2eb86c54 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.1.0" + "firebase": "^9.12.1" } } diff --git a/perf-next/package.json b/perf-next/package.json index 69cf753b..e05ef409 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.1.0" + "firebase": "^9.12.1" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index 8a072847..ffbd6c3e 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.1.0" + "firebase": "^9.12.1" } } diff --git a/storage-next/package.json b/storage-next/package.json index fbce56ec..a64d67b2 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.1.0" + "firebase": "^9.12.1" } } From 476223e29552c2128ac2d62e3906628130047cf8 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 20 Oct 2022 14:55:19 -0700 Subject: [PATCH 212/235] Auto-update dependencies. (#242) * Auto-update dependencies. * Auto-update dependencies. Co-authored-by: Morgan Chen --- firestore/index.html | 4 ++-- messaging/service-worker.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firestore/index.html b/firestore/index.html index ddc3c44d..3599ca13 100644 --- a/firestore/index.html +++ b/firestore/index.html @@ -12,8 +12,8 @@ - - + + diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 3b2f7de0..26f9d097 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/9.2.0/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/9.2.0/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 36740fb2c39383621c0c0a948236e9eab8a71516 Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Thu, 20 Oct 2022 15:15:06 -0700 Subject: [PATCH 213/235] Add count query snippet (#307) * Add count query snippet * add simpler snippet * consts * no masking * run snippets --- firestore-next/test.firestore.js | 21 +++++++++++++++++++ .../count_aggregate_collection.js | 11 ++++++++++ .../test-firestore/count_aggregate_query.js | 12 +++++++++++ 3 files changed, 44 insertions(+) create mode 100644 snippets/firestore-next/test-firestore/count_aggregate_collection.js create mode 100644 snippets/firestore-next/test-firestore/count_aggregate_query.js diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 17ff6d29..2469b736 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -1158,6 +1158,27 @@ describe("firestore", () => { }); }); + describe("aggregate queries", () => { + it("should fetch the count of documents in a collection", async () => { + const { collection, getCountFromServer } = require("firebase/firestore"); + // [START count_aggregate_collection] + const coll = collection(db, "cities"); + const snapshot = await getCountFromServer(coll); + console.log('count: ', snapshot.data().count); + // [END count_aggregate_collection] + }); + + it("should fetch the count of documents in a query", async () => { + const { collection, getCountFromServer, where, query } = require("firebase/firestore"); + // [START count_aggregate_query] + const coll = collection(db, "cities"); + const q = query(coll, where("state", "==", "CA")); + const snapshot = await getCountFromServer(q); + console.log('count: ', snapshot.data().count); + // [END count_aggregate_query] + }); + }); + // TODO: Break out into separate file describe("solution-aggregation", () => { it("should update a restaurant in a transaction #UNVERIFIED", async () => { diff --git a/snippets/firestore-next/test-firestore/count_aggregate_collection.js b/snippets/firestore-next/test-firestore/count_aggregate_collection.js new file mode 100644 index 00000000..7dca7e37 --- /dev/null +++ b/snippets/firestore-next/test-firestore/count_aggregate_collection.js @@ -0,0 +1,11 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START count_aggregate_collection_modular] +const coll = collection(db, "cities"); +const snapshot = await getCountFromServer(coll); +console.log('count: ', snapshot.data().count); +// [END count_aggregate_collection_modular] \ No newline at end of file diff --git a/snippets/firestore-next/test-firestore/count_aggregate_query.js b/snippets/firestore-next/test-firestore/count_aggregate_query.js new file mode 100644 index 00000000..37a27458 --- /dev/null +++ b/snippets/firestore-next/test-firestore/count_aggregate_query.js @@ -0,0 +1,12 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START count_aggregate_query_modular] +const coll = collection(db, "cities"); +const q = query(coll, where("state", "==", "CA")); +const snapshot = await getCountFromServer(q); +console.log('count: ', snapshot.data().count); +// [END count_aggregate_query_modular] \ No newline at end of file From 7ca0947f12931dce792e66f986707ffa2839184a Mon Sep 17 00:00:00 2001 From: markarndt <50713862+markarndt@users.noreply.github.com> Date: Thu, 2 Feb 2023 16:02:59 -0800 Subject: [PATCH 214/235] Add Storage emulator snippets that were previously hard-coded in docs. (#304) * Initial push to prepare for review. * Fix lint error. * Generate /snippets/storage-next/emulator-suite. * Fix errant RTDB reference in comment lines. --- .../emulator-suite/storage_emulator_connect.js | 15 +++++++++++++++ storage-next/emulator-suite.js | 14 ++++++++++++++ storage/emulator-suite.js | 16 ++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 snippets/storage-next/emulator-suite/storage_emulator_connect.js create mode 100644 storage-next/emulator-suite.js create mode 100644 storage/emulator-suite.js diff --git a/snippets/storage-next/emulator-suite/storage_emulator_connect.js b/snippets/storage-next/emulator-suite/storage_emulator_connect.js new file mode 100644 index 00000000..5cdc1589 --- /dev/null +++ b/snippets/storage-next/emulator-suite/storage_emulator_connect.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./storage-next/emulator-suite.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START storage_emulator_connect_modular] +import { getStorage, connectStorageEmulator } from "firebase/storage"; + +const storage = getStorage(); +if (location.hostname === "localhost") { + // Point to the Storage emulator running on localhost. + connectStorageEmulator(storage, "localhost", 9199); +} +// [END storage_emulator_connect_modular] \ No newline at end of file diff --git a/storage-next/emulator-suite.js b/storage-next/emulator-suite.js new file mode 100644 index 00000000..b3038033 --- /dev/null +++ b/storage-next/emulator-suite.js @@ -0,0 +1,14 @@ +// [SNIPPET_REGISTRY disabled] +// [SNIPPETS_SEPARATION enabled] + +function onDocumentReady() { + // [START storage_emulator_connect] + const { getStorage, connectStorageEmulator } = require("firebase/storage"); + + const storage = getStorage(); + if (location.hostname === "localhost") { + // Point to the Storage emulator running on localhost. + connectStorageEmulator(storage, "localhost", 9199); + } + // [END storage_emulator_connect] +} diff --git a/storage/emulator-suite.js b/storage/emulator-suite.js new file mode 100644 index 00000000..7f93e660 --- /dev/null +++ b/storage/emulator-suite.js @@ -0,0 +1,16 @@ +// These samples are intended for Web so this import would normally be +// done in HTML however using modules here is more convenient for +// ensuring sample correctness offline. +import firebase from "firebase/app"; +import "firebase/storage"; + +function onDocumentReady() { + // [START storage_emulator_connect] + var storage = firebase.storage(); + if (location.hostname === "localhost") { + // Point to the Storage emulator running on localhost. + storage.useEmulator("localhost", 9199); + } + // [END storage_emulator_connect] +} + From b48560b155e6f27db977f51070470631e7a2db56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ros=C3=A1rio=20Pereira=20Fernandes?= Date: Fri, 3 Feb 2023 18:05:46 +0000 Subject: [PATCH 215/235] refactor: import getMessaging from messaging/sw (#320) --- messaging-next/service-worker.js | 2 +- .../service-worker/messaging_on_background_message.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/messaging-next/service-worker.js b/messaging-next/service-worker.js index a81a7c18..55f07524 100644 --- a/messaging-next/service-worker.js +++ b/messaging-next/service-worker.js @@ -40,7 +40,7 @@ function initInSw() { function onBackgroundMessage() { // [START messaging_on_background_message] - const { getMessaging } = require("firebase/messaging"); + const { getMessaging } = require("firebase/messaging/sw"); const { onBackgroundMessage } = require("firebase/messaging/sw"); const messaging = getMessaging(); diff --git a/snippets/messaging-next/service-worker/messaging_on_background_message.js b/snippets/messaging-next/service-worker/messaging_on_background_message.js index b7f65b53..79c17eea 100644 --- a/snippets/messaging-next/service-worker/messaging_on_background_message.js +++ b/snippets/messaging-next/service-worker/messaging_on_background_message.js @@ -5,7 +5,7 @@ // 'npm run snippets'. // [START messaging_on_background_message_modular] -import { getMessaging } from "firebase/messaging"; +import { getMessaging } from "firebase/messaging/sw"; import { onBackgroundMessage } from "firebase/messaging/sw"; const messaging = getMessaging(); From 73a4f0b01c7e9869e3bb8bd4494ff186eb784ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ros=C3=A1rio=20Pereira=20Fernandes?= Date: Fri, 3 Feb 2023 18:09:33 +0000 Subject: [PATCH 216/235] mention getAdditionalUserInfo() in oauth providers (#319) --- auth-next/apple.js | 1 + auth-next/facebook.js | 3 +++ auth-next/github.js | 3 +++ auth-next/google-signin.js | 3 +++ auth-next/twitter.js | 3 +++ auth/apple.js | 7 +++++-- auth/facebook.js | 4 ++++ auth/github.js | 5 ++++- auth/google-signin.js | 5 ++++- auth/twitter.js | 5 ++++- snippets/auth-next/apple/auth_apple_signin_popup.js | 1 + snippets/auth-next/facebook/auth_facebook_signin_popup.js | 1 + .../facebook/auth_facebook_signin_redirect_result.js | 2 ++ snippets/auth-next/github/auth_github_signin_popup.js | 1 + .../auth-next/github/auth_github_signin_redirect_result.js | 2 ++ .../auth-next/google-signin/auth_google_signin_popup.js | 1 + .../google-signin/auth_google_signin_redirect_result.js | 2 ++ snippets/auth-next/twitter/auth_twitter_signin_popup.js | 1 + .../twitter/auth_twitter_signin_redirect_result.js | 2 ++ 19 files changed, 47 insertions(+), 5 deletions(-) diff --git a/auth-next/apple.js b/auth-next/apple.js index f9670b4c..2777a085 100644 --- a/auth-next/apple.js +++ b/auth-next/apple.js @@ -38,6 +38,7 @@ function appleSignInPopup(provider) { const accessToken = credential.accessToken; const idToken = credential.idToken; + // IdP data available using getAdditionalUserInfo(result) // ... }) .catch((error) => { diff --git a/auth-next/facebook.js b/auth-next/facebook.js index 67b397f2..3c6feb8a 100644 --- a/auth-next/facebook.js +++ b/auth-next/facebook.js @@ -33,6 +33,7 @@ function facebookSignInPopup(provider) { const credential = FacebookAuthProvider.credentialFromResult(result); const accessToken = credential.accessToken; + // IdP data available using getAdditionalUserInfo(result) // ... }) .catch((error) => { @@ -61,6 +62,8 @@ function facebookSignInRedirectResult() { const token = credential.accessToken; const user = result.user; + // IdP data available using getAdditionalUserInfo(result) + // ... }).catch((error) => { // Handle Errors here. const errorCode = error.code; diff --git a/auth-next/github.js b/auth-next/github.js index babfd1ee..4c128721 100644 --- a/auth-next/github.js +++ b/auth-next/github.js @@ -40,6 +40,7 @@ function githubSignInPopup(provider) { // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) // ... }).catch((error) => { // Handle Errors here. @@ -70,6 +71,8 @@ function githubSignInRedirectResult() { // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) + // ... }).catch((error) => { // Handle Errors here. const errorCode = error.code; diff --git a/auth-next/google-signin.js b/auth-next/google-signin.js index 136c26b5..025eebd6 100644 --- a/auth-next/google-signin.js +++ b/auth-next/google-signin.js @@ -33,6 +33,7 @@ function googleSignInPopup(provider) { const token = credential.accessToken; // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) // ... }).catch((error) => { // Handle Errors here. @@ -60,6 +61,8 @@ function googleSignInRedirectResult() { // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) + // ... }).catch((error) => { // Handle Errors here. const errorCode = error.code; diff --git a/auth-next/twitter.js b/auth-next/twitter.js index a386e4ab..f96e574b 100644 --- a/auth-next/twitter.js +++ b/auth-next/twitter.js @@ -30,6 +30,7 @@ function twitterSignInPopup(provider) { // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) // ... }).catch((error) => { // Handle Errors here. @@ -60,6 +61,8 @@ function twitterSignInRedirectResult() { // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) + // ... }).catch((error) => { // Handle Errors here. const errorCode = error.code; diff --git a/auth/apple.js b/auth/apple.js index e99349c8..00e2598e 100644 --- a/auth/apple.js +++ b/auth/apple.js @@ -40,7 +40,8 @@ function appleSignInPopup(provider) { var accessToken = credential.accessToken; var idToken = credential.idToken; - // ... + // IdP data available using getAdditionalUserInfo(result) + // ... }) .catch((error) => { // Handle Errors here. @@ -77,6 +78,7 @@ function appleSignInRedirectResult() { var accessToken = credential.accessToken; var idToken = credential.idToken; + // IdP data available in result.additionalUserInfo.profile. // ... } // The signed-in user info. @@ -117,7 +119,8 @@ function appleReauthenticatePopup() { var accessToken = credential.accessToken; var idToken = credential.idToken; - // ... + // IdP data available in result.additionalUserInfo.profile. + // ... }) .catch((error) => { // Handle Errors here. diff --git a/auth/facebook.js b/auth/facebook.js index 4259960d..75e99d43 100644 --- a/auth/facebook.js +++ b/auth/facebook.js @@ -31,6 +31,8 @@ function facebookSignInPopup(provider) { // The signed-in user info. var user = result.user; + // IdP data available in result.additionalUserInfo.profile. + // ... // This gives you a Facebook Access Token. You can use it to access the Facebook API. var accessToken = credential.accessToken; @@ -66,6 +68,8 @@ function facebookSignInRedirectResult() { } // The signed-in user info. var user = result.user; + // IdP data available in result.additionalUserInfo.profile. + // ... }).catch((error) => { // Handle Errors here. var errorCode = error.code; diff --git a/auth/github.js b/auth/github.js index 6ae1e531..8ae9b39c 100644 --- a/auth/github.js +++ b/auth/github.js @@ -40,7 +40,8 @@ function githubSignInPopup(provider) { // The signed-in user info. var user = result.user; - // ... + // IdP data available in result.additionalUserInfo.profile. + // ... }).catch((error) => { // Handle Errors here. var errorCode = error.code; @@ -70,6 +71,8 @@ function githubSignInRedirectResult() { // The signed-in user info. var user = result.user; + // IdP data available in result.additionalUserInfo.profile. + // ... }).catch((error) => { // Handle Errors here. var errorCode = error.code; diff --git a/auth/google-signin.js b/auth/google-signin.js index fcc32dc8..06a488e4 100644 --- a/auth/google-signin.js +++ b/auth/google-signin.js @@ -34,7 +34,8 @@ function googleSignInPopup(provider) { var token = credential.accessToken; // The signed-in user info. var user = result.user; - // ... + // IdP data available in result.additionalUserInfo.profile. + // ... }).catch((error) => { // Handle Errors here. var errorCode = error.code; @@ -63,6 +64,8 @@ function googleSignInRedirectResult() { } // The signed-in user info. var user = result.user; + // IdP data available in result.additionalUserInfo.profile. + // ... }).catch((error) => { // Handle Errors here. var errorCode = error.code; diff --git a/auth/twitter.js b/auth/twitter.js index a78370b7..68ed6f35 100644 --- a/auth/twitter.js +++ b/auth/twitter.js @@ -32,7 +32,8 @@ function twitterSignInPopup(provider) { // The signed-in user info. var user = result.user; - // ... + // IdP data available in result.additionalUserInfo.profile. + // ... }).catch((error) => { // Handle Errors here. var errorCode = error.code; @@ -64,6 +65,8 @@ function twitterSignInRedirectResult() { // The signed-in user info. var user = result.user; + // IdP data available in result.additionalUserInfo.profile. + // ... }).catch((error) => { // Handle Errors here. var errorCode = error.code; diff --git a/snippets/auth-next/apple/auth_apple_signin_popup.js b/snippets/auth-next/apple/auth_apple_signin_popup.js index c2a392cf..e3a0f11b 100644 --- a/snippets/auth-next/apple/auth_apple_signin_popup.js +++ b/snippets/auth-next/apple/auth_apple_signin_popup.js @@ -18,6 +18,7 @@ signInWithPopup(auth, provider) const accessToken = credential.accessToken; const idToken = credential.idToken; + // IdP data available using getAdditionalUserInfo(result) // ... }) .catch((error) => { diff --git a/snippets/auth-next/facebook/auth_facebook_signin_popup.js b/snippets/auth-next/facebook/auth_facebook_signin_popup.js index 7d35aaf2..524a11ac 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_popup.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_popup.js @@ -17,6 +17,7 @@ signInWithPopup(auth, provider) const credential = FacebookAuthProvider.credentialFromResult(result); const accessToken = credential.accessToken; + // IdP data available using getAdditionalUserInfo(result) // ... }) .catch((error) => { diff --git a/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js b/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js index eb6cdb30..c65c47d7 100644 --- a/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js +++ b/snippets/auth-next/facebook/auth_facebook_signin_redirect_result.js @@ -15,6 +15,8 @@ getRedirectResult(auth) const token = credential.accessToken; const user = result.user; + // IdP data available using getAdditionalUserInfo(result) + // ... }).catch((error) => { // Handle Errors here. const errorCode = error.code; diff --git a/snippets/auth-next/github/auth_github_signin_popup.js b/snippets/auth-next/github/auth_github_signin_popup.js index e1b4768e..3839a70f 100644 --- a/snippets/auth-next/github/auth_github_signin_popup.js +++ b/snippets/auth-next/github/auth_github_signin_popup.js @@ -16,6 +16,7 @@ signInWithPopup(auth, provider) // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) // ... }).catch((error) => { // Handle Errors here. diff --git a/snippets/auth-next/github/auth_github_signin_redirect_result.js b/snippets/auth-next/github/auth_github_signin_redirect_result.js index b3d31d0a..fb5f7ca2 100644 --- a/snippets/auth-next/github/auth_github_signin_redirect_result.js +++ b/snippets/auth-next/github/auth_github_signin_redirect_result.js @@ -19,6 +19,8 @@ getRedirectResult(auth) // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) + // ... }).catch((error) => { // Handle Errors here. const errorCode = error.code; diff --git a/snippets/auth-next/google-signin/auth_google_signin_popup.js b/snippets/auth-next/google-signin/auth_google_signin_popup.js index d6c70eb9..433bb88e 100644 --- a/snippets/auth-next/google-signin/auth_google_signin_popup.js +++ b/snippets/auth-next/google-signin/auth_google_signin_popup.js @@ -15,6 +15,7 @@ signInWithPopup(auth, provider) const token = credential.accessToken; // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) // ... }).catch((error) => { // Handle Errors here. diff --git a/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js b/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js index 50c4aded..2953ab5f 100644 --- a/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js +++ b/snippets/auth-next/google-signin/auth_google_signin_redirect_result.js @@ -16,6 +16,8 @@ getRedirectResult(auth) // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) + // ... }).catch((error) => { // Handle Errors here. const errorCode = error.code; diff --git a/snippets/auth-next/twitter/auth_twitter_signin_popup.js b/snippets/auth-next/twitter/auth_twitter_signin_popup.js index ae8e2007..adb7322e 100644 --- a/snippets/auth-next/twitter/auth_twitter_signin_popup.js +++ b/snippets/auth-next/twitter/auth_twitter_signin_popup.js @@ -18,6 +18,7 @@ signInWithPopup(auth, provider) // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) // ... }).catch((error) => { // Handle Errors here. diff --git a/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js b/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js index 73e42bab..357faa4e 100644 --- a/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js +++ b/snippets/auth-next/twitter/auth_twitter_signin_redirect_result.js @@ -19,6 +19,8 @@ getRedirectResult(auth) // The signed-in user info. const user = result.user; + // IdP data available using getAdditionalUserInfo(result) + // ... }).catch((error) => { // Handle Errors here. const errorCode = error.code; From 486e5c67bcb895a00ccab90f1b20cefdba6c9e3a Mon Sep 17 00:00:00 2001 From: dwyfrequency Date: Wed, 15 Feb 2023 13:28:52 -0500 Subject: [PATCH 217/235] Update gstatic url for v8 example (#325) --- messaging/service-worker.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 26f9d097..c0f875bb 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -1,5 +1,5 @@ -import firebase from "firebase/app"; -import "firebase/messaging"; +import firebase from 'firebase/app'; +import 'firebase/messaging'; // See: https://github.com/microsoft/TypeScript/issues/14877 /** @type {ServiceWorkerGlobalScope} */ @@ -10,8 +10,8 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/9.2.0/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/9.2.0/firebase-messaging.js'); + importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js'); + importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. @@ -38,16 +38,18 @@ function onBackgroundMessage() { // [START messaging_on_background_message] messaging.onBackgroundMessage((payload) => { - console.log('[firebase-messaging-sw.js] Received background message ', payload); + console.log( + '[firebase-messaging-sw.js] Received background message ', + payload + ); // Customize notification here const notificationTitle = 'Background Message Title'; const notificationOptions = { body: 'Background Message body.', icon: '/firebase-logo.png' }; - - self.registration.showNotification(notificationTitle, - notificationOptions); + + self.registration.showNotification(notificationTitle, notificationOptions); }); // [END messaging_on_background_message] } From e2beb93c2842b540ce78403ff4e2b115ebc0d072 Mon Sep 17 00:00:00 2001 From: Shabbirjodhpur <62835725+Shabbirjodhpur@users.noreply.github.com> Date: Tue, 4 Apr 2023 21:43:38 +0530 Subject: [PATCH 218/235] Update get_document.js (#335) We get the snapshot of data using 'getDoc()' and get result 'docSnap' And then we perform check on this 'docSnap' in the if else block So in the else block the comment should ne docSnap.data() will ne undefined --- firestore-next/test.firestore.js | 2 +- snippets/firestore-next/test-firestore/get_document.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 2469b736..a430064f 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -583,7 +583,7 @@ describe("firestore", () => { if (docSnap.exists()) { console.log("Document data:", docSnap.data()); } else { - // doc.data() will be undefined in this case + // docSnap.data() will be undefined in this case console.log("No such document!"); } // [END get_document] diff --git a/snippets/firestore-next/test-firestore/get_document.js b/snippets/firestore-next/test-firestore/get_document.js index 4cfbaaf6..1653b61a 100644 --- a/snippets/firestore-next/test-firestore/get_document.js +++ b/snippets/firestore-next/test-firestore/get_document.js @@ -13,7 +13,7 @@ const docSnap = await getDoc(docRef); if (docSnap.exists()) { console.log("Document data:", docSnap.data()); } else { - // doc.data() will be undefined in this case + // docSnap.data() will be undefined in this case console.log("No such document!"); } // [END get_document_modular] \ No newline at end of file From 1852962750472181dbb4523e5185b8e0350f2f38 Mon Sep 17 00:00:00 2001 From: Juan Lara Date: Tue, 9 May 2023 02:26:28 -0700 Subject: [PATCH 219/235] Add a snippet demonstrating a subcollection query. (#339) --- firestore-next/test.firestore.js | 12 ++++++++++++ .../firestore_query_subcollection.js | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 snippets/firestore-next/test-firestore/firestore_query_subcollection.js diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index a430064f..c961af9d 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -683,6 +683,18 @@ describe("firestore", () => { // [END get_multiple_all] }); + it("should get all documents from a subcollection", async () => { + // [START firestore_query_subcollection] + const { collection, getDocs } = require("firebase/firestore"); + // Query a reference to a subcollection + const querySnapshot = await getDocs(collection(db, "cities", "SF", "landmarks")); + querySnapshot.forEach((doc) => { + // doc.data() is never undefined for query doc snapshots + console.log(doc.id, " => ", doc.data()); + }); + // [END firestore_query_subcollection] + }); + it("should listen on multiple documents #UNVERIFIED", (done) => { // [START listen_multiple] const { collection, query, where, onSnapshot } = require("firebase/firestore"); diff --git a/snippets/firestore-next/test-firestore/firestore_query_subcollection.js b/snippets/firestore-next/test-firestore/firestore_query_subcollection.js new file mode 100644 index 00000000..76a1b847 --- /dev/null +++ b/snippets/firestore-next/test-firestore/firestore_query_subcollection.js @@ -0,0 +1,15 @@ +// This snippet file was generated by processing the source file: +// ./firestore-next/test.firestore.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + +// [START firestore_query_subcollection_modular] +import { collection, getDocs } from "firebase/firestore"; +// Query a reference to a subcollection +const querySnapshot = await getDocs(collection(db, "cities", "SF", "landmarks")); +querySnapshot.forEach((doc) => { + // doc.data() is never undefined for query doc snapshots + console.log(doc.id, " => ", doc.data()); +}); +// [END firestore_query_subcollection_modular] \ No newline at end of file From 2414b5519c79472a228a38205f646e71d43cb182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ros=C3=A1rio=20P=2E=20Fernandes?= Date: Mon, 22 May 2023 14:32:41 +0100 Subject: [PATCH 220/235] fix broken ref docs urls (#343) * fix broken ref docs urls * update the separate-snippets script to replace ref docs urls --- auth-next/index.js | 4 +-- auth/index.js | 4 +-- firestore/test.firestore.js | 2 +- scripts/separate-snippets.ts | 27 +++++++++++++++++++ snippets/auth-next/index/auth_current_user.js | 2 +- .../auth-next/index/auth_state_listener.js | 2 +- 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/auth-next/index.js b/auth-next/index.js index b4a17903..b741a6d7 100644 --- a/auth-next/index.js +++ b/auth-next/index.js @@ -52,7 +52,7 @@ function authStateListener() { onAuthStateChanged(auth, (user) => { if (user) { // User is signed in, see docs for a list of available properties - // https://firebase.google.com/docs/reference/js/firebase.User + // https://firebase.google.com/docs/reference/js/v8/firebase.User const uid = user.uid; // ... } else { @@ -72,7 +72,7 @@ function currentUser() { if (user) { // User is signed in, see docs for a list of available properties - // https://firebase.google.com/docs/reference/js/firebase.User + // https://firebase.google.com/docs/reference/js/v8/firebase.User // ... } else { // No user is signed in. diff --git a/auth/index.js b/auth/index.js index 6567c030..35546aa3 100644 --- a/auth/index.js +++ b/auth/index.js @@ -43,7 +43,7 @@ function authStateListener() { firebase.auth().onAuthStateChanged((user) => { if (user) { // User is signed in, see docs for a list of available properties - // https://firebase.google.com/docs/reference/js/firebase.User + // https://firebase.google.com/docs/reference/js/v8/firebase.User var uid = user.uid; // ... } else { @@ -60,7 +60,7 @@ function currentUser() { if (user) { // User is signed in, see docs for a list of available properties - // https://firebase.google.com/docs/reference/js/firebase.User + // https://firebase.google.com/docs/reference/js/v8/firebase.User // ... } else { // No user is signed in. diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index dbf6e18e..ec89172e 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -600,7 +600,7 @@ describe("firestore", () => { var docRef = db.collection("cities").doc("SF"); // Valid options for source are 'server', 'cache', or - // 'default'. See https://firebase.google.com/docs/reference/js/firebase.firestore.GetOptions + // 'default'. See https://firebase.google.com/docs/reference/js/v8/firebase.firestore.GetOptions // for more information. var getOptions = { source: 'cache' diff --git a/scripts/separate-snippets.ts b/scripts/separate-snippets.ts index a888d908..b2f41de3 100644 --- a/scripts/separate-snippets.ts +++ b/scripts/separate-snippets.ts @@ -18,6 +18,15 @@ const RE_END_SNIPPET = /\[END\s+([A-Za-z_]+)\s*\]/; // TODO: Handle multiline imports? const RE_REQUIRE = /const {(.+?)} = require\((.+?)\)/; +// Regex for ref docs URLs +// eg. "https://firebase.google.com/docs/reference/js/v8/firebase.User" +const RE_REF_DOCS = /https:\/\/firebase\.google\.com\/docs\/reference\/js\/(.*)/; + +// Maps v8 ref docs URLs to their v9 counterpart +const REF_DOCS_MAPPINGS: { [key: string]: string } = { + "v8/firebase.User" : "auth.user" +}; + type SnippetsConfig = { enabled: boolean; suffix: string; @@ -30,6 +39,23 @@ function isBlank(line: string) { return line.trim().length === 0; } +/** + * Replace all v8 ref doc urls with their v9 counterpart. + */ +function replaceRefDocsUrls(lines: string[]) { + const outputLines = []; + for (const line of lines) { + if (line.match(RE_REF_DOCS)) { + outputLines.push(line.replace(RE_REF_DOCS, (match: string, p1?: string) => { + return p1 ? `https://firebase.google.com/docs/reference/js/${REF_DOCS_MAPPINGS[p1]}` : match; + })); + } else { + outputLines.push(line); + } + } + return outputLines; +} + /** * Replace all const { foo } = require('bar') with import { foo } from 'bar'; */ @@ -119,6 +145,7 @@ function processSnippet( outputLines = addSuffixToSnippetNames(outputLines, snippetSuffix); outputLines = adjustIndentation(outputLines); outputLines = removeFirstLineAfterComments(outputLines); + outputLines = replaceRefDocsUrls(outputLines); // Add a preamble to every snippet const preambleLines = [ diff --git a/snippets/auth-next/index/auth_current_user.js b/snippets/auth-next/index/auth_current_user.js index c094a464..6925b021 100644 --- a/snippets/auth-next/index/auth_current_user.js +++ b/snippets/auth-next/index/auth_current_user.js @@ -12,7 +12,7 @@ const user = auth.currentUser; if (user) { // User is signed in, see docs for a list of available properties - // https://firebase.google.com/docs/reference/js/firebase.User + // https://firebase.google.com/docs/reference/js/auth.user // ... } else { // No user is signed in. diff --git a/snippets/auth-next/index/auth_state_listener.js b/snippets/auth-next/index/auth_state_listener.js index aebe6818..0f3e4e88 100644 --- a/snippets/auth-next/index/auth_state_listener.js +++ b/snippets/auth-next/index/auth_state_listener.js @@ -11,7 +11,7 @@ const auth = getAuth(); onAuthStateChanged(auth, (user) => { if (user) { // User is signed in, see docs for a list of available properties - // https://firebase.google.com/docs/reference/js/firebase.User + // https://firebase.google.com/docs/reference/js/auth.user const uid = user.uid; // ... } else { From 8fc7be2dc9ea398e63f57222d02428f8fa506a11 Mon Sep 17 00:00:00 2001 From: gregfenton Date: Mon, 22 May 2023 13:19:10 -0400 Subject: [PATCH 221/235] Remove unused function parameter (#344) --- firestore/test.solution-counters.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firestore/test.solution-counters.js b/firestore/test.solution-counters.js index c8c62fe6..c7c51cff 100644 --- a/firestore/test.solution-counters.js +++ b/firestore/test.solution-counters.js @@ -22,7 +22,7 @@ function createCounter(ref, num_shards) { // [END create_counter] // [START increment_counter] -function incrementCounter(db, ref, num_shards) { +function incrementCounter(ref, num_shards) { // Select a shard of the counter at random const shard_id = Math.floor(Math.random() * num_shards).toString(); const shard_ref = ref.collection('shards').doc(shard_id); @@ -67,7 +67,7 @@ describe("firestore-solution-counters", () => { // Create a counter, then increment it const ref = db.collection('counters').doc(); return createCounter(ref, 10).then(() => { - return incrementCounter(db, ref, 10); + return incrementCounter(ref, 10); }); }); @@ -75,7 +75,7 @@ describe("firestore-solution-counters", () => { // Create a counter, increment it, then get the count const ref = db.collection('counters').doc(); return createCounter(ref, 10).then(() => { - return incrementCounter(db, ref, 10); + return incrementCounter(ref, 10); }).then(() => { return getCount(ref); }); From adb06a357b6a6509019f15b88cccbdc2788353ef Mon Sep 17 00:00:00 2001 From: markarndt <50713862+markarndt@users.noreply.github.com> Date: Thu, 8 Jun 2023 15:39:37 -0700 Subject: [PATCH 222/235] Emulator localhost updates, localhost -> 127.0.0.1 (#334) * Update v8 and v9 for localhost -> 127.0.0.1 requirement. * Update Auth emulator snippets for localhost -> 127.0.0.1 requirement. * Update RTDB emulator snippet for localhost -> 127.0.0.1 requirement. * Update Storage emulator snippets for localhost -> 127.0.0.1 requirement. * More Database emulator snippet updates. * Update emulator-suite.js * Update emulator-suite.js * Update v8 and v9 for localhost -> 127.0.0.1 requirement. * Update Auth emulator snippets for localhost -> 127.0.0.1 requirement. * Update RTDB emulator snippet for localhost -> 127.0.0.1 requirement. * Update Storage emulator snippets for localhost -> 127.0.0.1 requirement. * More Database emulator snippet updates. * After running local script, new update file. * Test using "Delete" to remove file from PR, not repo * Put this file back. --- auth-next/emulator-suite.js | 2 +- auth/emulator-suite.js | 2 +- database-next/emulator-suite.js | 2 +- database/emulator-suite.js | 2 +- firestore-next/emulator-suite.js | 2 +- firestore/emulator-suite.js | 2 +- functions-next/emulator-suite.js | 2 +- functions/emulator-suite.js | 2 +- snippets/auth-next/emulator-suite/auth_emulator_connect.js | 2 +- snippets/database-next/emulator-suite/rtdb_emulator_connect.js | 2 +- snippets/firestore-next/emulator-suite/fs_emulator_connect.js | 2 +- .../emulator-suite/fb_functions_emulator_connect.js | 2 +- .../storage-next/emulator-suite/storage_emulator_connect.js | 2 +- storage-next/emulator-suite.js | 2 +- storage/emulator-suite.js | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/auth-next/emulator-suite.js b/auth-next/emulator-suite.js index 66507de3..13b1ba95 100644 --- a/auth-next/emulator-suite.js +++ b/auth-next/emulator-suite.js @@ -6,7 +6,7 @@ function emulatorConnect() { const { getAuth, connectAuthEmulator } = require("firebase/auth"); const auth = getAuth(); - connectAuthEmulator(auth, "http://localhost:9099"); + connectAuthEmulator(auth, "http://127.0.0.1:9099"); // [END auth_emulator_connect] } diff --git a/auth/emulator-suite.js b/auth/emulator-suite.js index b14a72db..b0f815e2 100644 --- a/auth/emulator-suite.js +++ b/auth/emulator-suite.js @@ -4,7 +4,7 @@ import "firebase/auth"; function emulatorConnect() { // [START auth_emulator_connect] const auth = firebase.auth(); - auth.useEmulator("http://localhost:9099"); + auth.useEmulator("http://127.0.0.1:9099"); // [END auth_emulator_connect] } diff --git a/database-next/emulator-suite.js b/database-next/emulator-suite.js index ab86bf9b..f94d3c89 100644 --- a/database-next/emulator-suite.js +++ b/database-next/emulator-suite.js @@ -8,7 +8,7 @@ function onDocumentReady() { const db = getDatabase(); if (location.hostname === "localhost") { // Point to the RTDB emulator running on localhost. - connectDatabaseEmulator(db, "localhost", 9000); + connectDatabaseEmulator(db, "127.0.0.1", 9000); } // [END rtdb_emulator_connect] } diff --git a/database/emulator-suite.js b/database/emulator-suite.js index 8fe739e4..8da23e25 100644 --- a/database/emulator-suite.js +++ b/database/emulator-suite.js @@ -10,7 +10,7 @@ function onDocumentReady() { var db = firebase.database(); if (location.hostname === "localhost") { // Point to the RTDB emulator running on localhost. - db.useEmulator("localhost", 9000); + db.useEmulator("127.0.0.1", 9000); } // [END rtdb_emulator_connect] } diff --git a/firestore-next/emulator-suite.js b/firestore-next/emulator-suite.js index 30ad24eb..edc900c1 100644 --- a/firestore-next/emulator-suite.js +++ b/firestore-next/emulator-suite.js @@ -7,6 +7,6 @@ function onDocumentReady() { // firebaseApps previously initialized using initializeApp() const db = getFirestore(); - connectFirestoreEmulator(db, 'localhost', 8080); + connectFirestoreEmulator(db, '127.0.0.1', 8080); // [END fs_emulator_connect] } diff --git a/firestore/emulator-suite.js b/firestore/emulator-suite.js index 714d38e7..03aef1e9 100644 --- a/firestore/emulator-suite.js +++ b/firestore/emulator-suite.js @@ -6,7 +6,7 @@ function onDocumentReady() { // Firebase previously initialized using firebase.initializeApp(). var db = firebase.firestore(); if (location.hostname === "localhost") { - db.useEmulator("localhost", 8080); + db.useEmulator("127.0.0.1", 8080); } // [END fs_emulator_connect] } diff --git a/functions-next/emulator-suite.js b/functions-next/emulator-suite.js index 7a750fc4..db7fd49d 100644 --- a/functions-next/emulator-suite.js +++ b/functions-next/emulator-suite.js @@ -15,7 +15,7 @@ export function emulatorSettings() { const { getFunctions, connectFunctionsEmulator } = require("firebase/functions"); const functions = getFunctions(getApp()); - connectFunctionsEmulator(functions, "localhost", 5001); + connectFunctionsEmulator(functions, "127.0.0.1", 5001); // [END fb_functions_emulator_connect] } diff --git a/functions/emulator-suite.js b/functions/emulator-suite.js index a9cdc7d7..e0413370 100644 --- a/functions/emulator-suite.js +++ b/functions/emulator-suite.js @@ -3,6 +3,6 @@ import "firebase/functions"; function emulatorSettings() { // [START fb_functions_emulator_connect] - firebase.functions().useEmulator("localhost", 5001); + firebase.functions().useEmulator("127.0.0.1", 5001); // [END fb_functions_emulator_connect] } diff --git a/snippets/auth-next/emulator-suite/auth_emulator_connect.js b/snippets/auth-next/emulator-suite/auth_emulator_connect.js index dd0b2e37..525a92b8 100644 --- a/snippets/auth-next/emulator-suite/auth_emulator_connect.js +++ b/snippets/auth-next/emulator-suite/auth_emulator_connect.js @@ -8,5 +8,5 @@ import { getAuth, connectAuthEmulator } from "firebase/auth"; const auth = getAuth(); -connectAuthEmulator(auth, "http://localhost:9099"); +connectAuthEmulator(auth, "http://127.0.0.1:9099"); // [END auth_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/database-next/emulator-suite/rtdb_emulator_connect.js b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js index 4cc268e7..0bd145f6 100644 --- a/snippets/database-next/emulator-suite/rtdb_emulator_connect.js +++ b/snippets/database-next/emulator-suite/rtdb_emulator_connect.js @@ -10,6 +10,6 @@ import { getDatabase, connectDatabaseEmulator } from "firebase/database"; const db = getDatabase(); if (location.hostname === "localhost") { // Point to the RTDB emulator running on localhost. - connectDatabaseEmulator(db, "localhost", 9000); + connectDatabaseEmulator(db, "127.0.0.1", 9000); } // [END rtdb_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js index 7e31fcfd..d70fbb68 100644 --- a/snippets/firestore-next/emulator-suite/fs_emulator_connect.js +++ b/snippets/firestore-next/emulator-suite/fs_emulator_connect.js @@ -9,5 +9,5 @@ import { getFirestore, connectFirestoreEmulator } from "firebase/firestore"; // firebaseApps previously initialized using initializeApp() const db = getFirestore(); -connectFirestoreEmulator(db, 'localhost', 8080); +connectFirestoreEmulator(db, '127.0.0.1', 8080); // [END fs_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js b/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js index 9b186fc2..835a2c60 100644 --- a/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js +++ b/snippets/functions-next/emulator-suite/fb_functions_emulator_connect.js @@ -9,5 +9,5 @@ import { getApp } from "firebase/app"; import { getFunctions, connectFunctionsEmulator } from "firebase/functions"; const functions = getFunctions(getApp()); -connectFunctionsEmulator(functions, "localhost", 5001); +connectFunctionsEmulator(functions, "127.0.0.1", 5001); // [END fb_functions_emulator_connect_modular] \ No newline at end of file diff --git a/snippets/storage-next/emulator-suite/storage_emulator_connect.js b/snippets/storage-next/emulator-suite/storage_emulator_connect.js index 5cdc1589..4b247d17 100644 --- a/snippets/storage-next/emulator-suite/storage_emulator_connect.js +++ b/snippets/storage-next/emulator-suite/storage_emulator_connect.js @@ -10,6 +10,6 @@ import { getStorage, connectStorageEmulator } from "firebase/storage"; const storage = getStorage(); if (location.hostname === "localhost") { // Point to the Storage emulator running on localhost. - connectStorageEmulator(storage, "localhost", 9199); + connectStorageEmulator(storage, "127.0.0.1", 9199); } // [END storage_emulator_connect_modular] \ No newline at end of file diff --git a/storage-next/emulator-suite.js b/storage-next/emulator-suite.js index b3038033..78891a4f 100644 --- a/storage-next/emulator-suite.js +++ b/storage-next/emulator-suite.js @@ -8,7 +8,7 @@ function onDocumentReady() { const storage = getStorage(); if (location.hostname === "localhost") { // Point to the Storage emulator running on localhost. - connectStorageEmulator(storage, "localhost", 9199); + connectStorageEmulator(storage, "127.0.0.1", 9199); } // [END storage_emulator_connect] } diff --git a/storage/emulator-suite.js b/storage/emulator-suite.js index 7f93e660..be1f2dd4 100644 --- a/storage/emulator-suite.js +++ b/storage/emulator-suite.js @@ -9,7 +9,7 @@ function onDocumentReady() { var storage = firebase.storage(); if (location.hostname === "localhost") { // Point to the Storage emulator running on localhost. - storage.useEmulator("localhost", 9199); + storage.useEmulator("127.0.0.1", 9199); } // [END storage_emulator_connect] } From 10cfebc889c92c7e41bfaec49dd3b777c88f9f53 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Thu, 22 Jun 2023 15:19:27 -0700 Subject: [PATCH 223/235] Auto-update dependencies. (#311) --- analytics-next/package.json | 2 +- appcheck-next/package.json | 2 +- auth-next/package.json | 2 +- database-next/package.json | 2 +- firebaseapp-next/package.json | 2 +- firestore-next/package.json | 2 +- functions-next/package.json | 2 +- messaging-next/package.json | 2 +- perf-next/package.json | 2 +- remoteconfig-next/package.json | 2 +- storage-next/package.json | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index 0fb07418..2483e0cd 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.12.1" + "firebase": "^9.22.2" } } diff --git a/appcheck-next/package.json b/appcheck-next/package.json index ad78db9f..8af508c9 100644 --- a/appcheck-next/package.json +++ b/appcheck-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.12.1" + "firebase": "^9.22.2" } } diff --git a/auth-next/package.json b/auth-next/package.json index 48adc595..748ff657 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.12.1" + "firebase": "^9.22.2" } } diff --git a/database-next/package.json b/database-next/package.json index be3cab88..6e7d6f69 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.12.1" + "firebase": "^9.22.2" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index d7b654df..1e40f536 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.12.1" + "firebase": "^9.22.2" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 39b5c6a9..3ec379a7 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.12.1", + "firebase": "^9.22.2", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/package.json b/functions-next/package.json index 618ee0c5..81d6c2f4 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.12.1" + "firebase": "^9.22.2" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index 2eb86c54..7ba8ab2c 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.12.1" + "firebase": "^9.22.2" } } diff --git a/perf-next/package.json b/perf-next/package.json index e05ef409..e5d27230 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.12.1" + "firebase": "^9.22.2" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index ffbd6c3e..d0482e46 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.12.1" + "firebase": "^9.22.2" } } diff --git a/storage-next/package.json b/storage-next/package.json index a64d67b2..7098fd72 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.12.1" + "firebase": "^9.22.2" } } From 7156e6c4c245ff85082c1aa54f16cbcf1a75a640 Mon Sep 17 00:00:00 2001 From: Juyoung Kim Date: Fri, 7 Jul 2023 22:29:12 +0900 Subject: [PATCH 224/235] chore: add missing whitespace & fix an incorrect snippet (#352) * chore: add missing whitespace * chore: fix an incorrect snippet (#324) --- auth-next/index.js | 2 +- database-next/read-and-write.js | 2 +- snippets/auth-next/index/auth_set_language_code.js | 2 +- .../read-and-write/rtdb_social_listen_star_count.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/auth-next/index.js b/auth-next/index.js index b741a6d7..04ac7d03 100644 --- a/auth-next/index.js +++ b/auth-next/index.js @@ -87,7 +87,7 @@ function setLanguageCode() { const auth = getAuth(); auth.languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. - // firebase.auth().useDeviceLanguage(); + // auth.useDeviceLanguage(); // [END auth_set_language_code] } diff --git a/database-next/read-and-write.js b/database-next/read-and-write.js index 4196c0d7..c06c66b4 100644 --- a/database-next/read-and-write.js +++ b/database-next/read-and-write.js @@ -44,7 +44,7 @@ function socialListenStarCount() { } // [START rtdb_social_listen_star_count] - const { getDatabase, ref, onValue} = require("firebase/database"); + const { getDatabase, ref, onValue } = require("firebase/database"); const db = getDatabase(); const starCountRef = ref(db, 'posts/' + postId + '/starCount'); diff --git a/snippets/auth-next/index/auth_set_language_code.js b/snippets/auth-next/index/auth_set_language_code.js index 47e78295..fe9a2025 100644 --- a/snippets/auth-next/index/auth_set_language_code.js +++ b/snippets/auth-next/index/auth_set_language_code.js @@ -10,5 +10,5 @@ import { getAuth } from "firebase/auth"; const auth = getAuth(); auth.languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. -// firebase.auth().useDeviceLanguage(); +// auth.useDeviceLanguage(); // [END auth_set_language_code_modular] \ No newline at end of file diff --git a/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js b/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js index ab520ce6..eb782894 100644 --- a/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js +++ b/snippets/database-next/read-and-write/rtdb_social_listen_star_count.js @@ -5,7 +5,7 @@ // 'npm run snippets'. // [START rtdb_social_listen_star_count_modular] -import { getDatabase, ref, onValue} from "firebase/database"; +import { getDatabase, ref, onValue } from "firebase/database"; const db = getDatabase(); const starCountRef = ref(db, 'posts/' + postId + '/starCount'); From 99310330e9cf4836ca94fc9e92114ed58cbdf1b9 Mon Sep 17 00:00:00 2001 From: Chase Hartsell <51487099+ch5zzy@users.noreply.github.com> Date: Mon, 10 Jul 2023 11:58:34 -0700 Subject: [PATCH 225/235] Update phone auth snippets with RecaptchaVerifier parameter reordering (#348) * Update phone auth snippets with RecaptchaVerifier parameter reordering * Update auth-next dependency to v10 --- auth-next/package.json | 2 +- auth-next/phone-auth.js | 10 +++++----- .../auth_phone_recaptcha_verifier_invisible.js | 4 ++-- .../phone-auth/auth_phone_recaptcha_verifier_simple.js | 2 +- .../auth_phone_recaptcha_verifier_visible.js | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/auth-next/package.json b/auth-next/package.json index 748ff657..8d43bad1 100644 --- a/auth-next/package.json +++ b/auth-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.22.2" + "firebase": "^10.0.0" } } diff --git a/auth-next/phone-auth.js b/auth-next/phone-auth.js index cd894c64..99492f99 100644 --- a/auth-next/phone-auth.js +++ b/auth-next/phone-auth.js @@ -15,13 +15,13 @@ function recaptchaVerifierInvisible() { const { getAuth, RecaptchaVerifier } = require("firebase/auth"); const auth = getAuth(); - window.recaptchaVerifier = new RecaptchaVerifier('sign-in-button', { + window.recaptchaVerifier = new RecaptchaVerifier(auth, 'sign-in-button', { 'size': 'invisible', 'callback': (response) => { // reCAPTCHA solved, allow signInWithPhoneNumber. onSignInSubmit(); } - }, auth); + }); // [END auth_phone_recaptcha_verifier_invisible] } @@ -30,7 +30,7 @@ function recaptchaVerifierVisible() { const { getAuth, RecaptchaVerifier } = require("firebase/auth"); const auth = getAuth(); - window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', { + window.recaptchaVerifier = new RecaptchaVerifier(auth, 'recaptcha-container', { 'size': 'normal', 'callback': (response) => { // reCAPTCHA solved, allow signInWithPhoneNumber. @@ -40,7 +40,7 @@ function recaptchaVerifierVisible() { // Response expired. Ask user to solve reCAPTCHA again. // ... } - }, auth); + }); // [END auth_phone_recaptcha_verifier_visible] } @@ -49,7 +49,7 @@ function recaptchaVerifierSimple() { const { getAuth, RecaptchaVerifier } = require("firebase/auth"); const auth = getAuth(); - window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', {}, auth); + window.recaptchaVerifier = new RecaptchaVerifier(auth, 'recaptcha-container', {}); // [END auth_phone_recaptcha_verifier_simple] } diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js index f6b6893f..7fd16eea 100644 --- a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_invisible.js @@ -8,11 +8,11 @@ import { getAuth, RecaptchaVerifier } from "firebase/auth"; const auth = getAuth(); -window.recaptchaVerifier = new RecaptchaVerifier('sign-in-button', { +window.recaptchaVerifier = new RecaptchaVerifier(auth, 'sign-in-button', { 'size': 'invisible', 'callback': (response) => { // reCAPTCHA solved, allow signInWithPhoneNumber. onSignInSubmit(); } -}, auth); +}); // [END auth_phone_recaptcha_verifier_invisible_modular] \ No newline at end of file diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js index ed56fe99..b57eb37b 100644 --- a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_simple.js @@ -8,5 +8,5 @@ import { getAuth, RecaptchaVerifier } from "firebase/auth"; const auth = getAuth(); -window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', {}, auth); +window.recaptchaVerifier = new RecaptchaVerifier(auth, 'recaptcha-container', {}); // [END auth_phone_recaptcha_verifier_simple_modular] \ No newline at end of file diff --git a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js index c91e6041..42ebbe69 100644 --- a/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js +++ b/snippets/auth-next/phone-auth/auth_phone_recaptcha_verifier_visible.js @@ -8,7 +8,7 @@ import { getAuth, RecaptchaVerifier } from "firebase/auth"; const auth = getAuth(); -window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', { +window.recaptchaVerifier = new RecaptchaVerifier(auth, 'recaptcha-container', { 'size': 'normal', 'callback': (response) => { // reCAPTCHA solved, allow signInWithPhoneNumber. @@ -18,5 +18,5 @@ window.recaptchaVerifier = new RecaptchaVerifier('recaptcha-container', { // Response expired. Ask user to solve reCAPTCHA again. // ... } -}, auth); +}); // [END auth_phone_recaptcha_verifier_visible_modular] \ No newline at end of file From 88aa8eb8210c90263eef7fe1f454cd6477a5a252 Mon Sep 17 00:00:00 2001 From: DPEBot Date: Mon, 10 Jul 2023 12:23:45 -0700 Subject: [PATCH 226/235] Auto-update dependencies. (#350) --- analytics-next/package.json | 2 +- appcheck-next/package.json | 2 +- database-next/package.json | 2 +- firebaseapp-next/package.json | 2 +- firestore-next/package.json | 2 +- functions-next/package.json | 2 +- messaging-next/package.json | 2 +- perf-next/package.json | 2 +- remoteconfig-next/package.json | 2 +- storage-next/package.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/analytics-next/package.json b/analytics-next/package.json index 2483e0cd..ee4e36ff 100644 --- a/analytics-next/package.json +++ b/analytics-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.22.2" + "firebase": "^10.0.0" } } diff --git a/appcheck-next/package.json b/appcheck-next/package.json index 8af508c9..e863723e 100644 --- a/appcheck-next/package.json +++ b/appcheck-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.22.2" + "firebase": "^10.0.0" } } diff --git a/database-next/package.json b/database-next/package.json index 6e7d6f69..eb16e2d5 100644 --- a/database-next/package.json +++ b/database-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.22.2" + "firebase": "^10.0.0" } } diff --git a/firebaseapp-next/package.json b/firebaseapp-next/package.json index 1e40f536..13cc74cd 100644 --- a/firebaseapp-next/package.json +++ b/firebaseapp-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.22.2" + "firebase": "^10.0.0" } } diff --git a/firestore-next/package.json b/firestore-next/package.json index 3ec379a7..ef3b8708 100644 --- a/firestore-next/package.json +++ b/firestore-next/package.json @@ -6,7 +6,7 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.22.2", + "firebase": "^10.0.0", "geofire-common": "^5.1.0" }, "devDependencies": { diff --git a/functions-next/package.json b/functions-next/package.json index 81d6c2f4..14f097ee 100644 --- a/functions-next/package.json +++ b/functions-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.22.2" + "firebase": "^10.0.0" } } diff --git a/messaging-next/package.json b/messaging-next/package.json index 7ba8ab2c..e4887a2a 100644 --- a/messaging-next/package.json +++ b/messaging-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.22.2" + "firebase": "^10.0.0" } } diff --git a/perf-next/package.json b/perf-next/package.json index e5d27230..688f6db0 100644 --- a/perf-next/package.json +++ b/perf-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.22.2" + "firebase": "^10.0.0" } } diff --git a/remoteconfig-next/package.json b/remoteconfig-next/package.json index d0482e46..952b1540 100644 --- a/remoteconfig-next/package.json +++ b/remoteconfig-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.22.2" + "firebase": "^10.0.0" } } diff --git a/storage-next/package.json b/storage-next/package.json index 7098fd72..b1c449ab 100644 --- a/storage-next/package.json +++ b/storage-next/package.json @@ -6,6 +6,6 @@ }, "license": "Apache-2.0", "dependencies": { - "firebase": "^9.22.2" + "firebase": "^10.0.0" } } From d781c67b528afe99fcdb7c7056104772463fa3ec Mon Sep 17 00:00:00 2001 From: Jonas Kaas Date: Fri, 29 Sep 2023 17:51:19 +0200 Subject: [PATCH 227/235] Fix comment for signup (#356) --- auth-next/email.js | 2 +- snippets/auth-next/email/auth_signup_password.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/auth-next/email.js b/auth-next/email.js index b00551c8..26391f81 100644 --- a/auth-next/email.js +++ b/auth-next/email.js @@ -32,7 +32,7 @@ function signUpWithEmailPassword() { const auth = getAuth(); createUserWithEmailAndPassword(auth, email, password) .then((userCredential) => { - // Signed in + // Signed up const user = userCredential.user; // ... }) diff --git a/snippets/auth-next/email/auth_signup_password.js b/snippets/auth-next/email/auth_signup_password.js index 00aa9bd5..936b64ce 100644 --- a/snippets/auth-next/email/auth_signup_password.js +++ b/snippets/auth-next/email/auth_signup_password.js @@ -10,7 +10,7 @@ import { getAuth, createUserWithEmailAndPassword } from "firebase/auth"; const auth = getAuth(); createUserWithEmailAndPassword(auth, email, password) .then((userCredential) => { - // Signed in + // Signed up const user = userCredential.user; // ... }) From 1f9e7978ed8f6805fad12b32f34b6216ab4556cb Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Thu, 9 Nov 2023 09:50:47 -0800 Subject: [PATCH 228/235] fix broken array-in snippets (#360) * fix broken array-in snippets * npm run snippets * revert array contians anay changes --- firestore-next/test.firestore.js | 2 +- firestore/test.firestore.js | 2 +- snippets/firestore-next/test-firestore/in_filter_with_array.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index c961af9d..969c1654 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -920,7 +920,7 @@ describe("firestore", () => { // [START in_filter_with_array] const { query, where } = require("firebase/firestore"); - const q = query(citiesRef, where('regions', 'in', [['west_coast', 'east_coast']])); + const q = query(citiesRef, where('regions', 'in', [['west_coast'], ['east_coast']])); // [END in_filter_with_array] } }); diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index ec89172e..20032d36 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -893,7 +893,7 @@ describe("firestore", () => { // [START in_filter_with_array] citiesRef.where('regions', 'in', - [['west_coast', 'east_coast']]); + [['west_coast'], ['east_coast']]); // [END in_filter_with_array] }); diff --git a/snippets/firestore-next/test-firestore/in_filter_with_array.js b/snippets/firestore-next/test-firestore/in_filter_with_array.js index ebe6f18b..190e9dfe 100644 --- a/snippets/firestore-next/test-firestore/in_filter_with_array.js +++ b/snippets/firestore-next/test-firestore/in_filter_with_array.js @@ -7,5 +7,5 @@ // [START in_filter_with_array_modular] import { query, where } from "firebase/firestore"; -const q = query(citiesRef, where('regions', 'in', [['west_coast', 'east_coast']])); +const q = query(citiesRef, where('regions', 'in', [['west_coast'], ['east_coast']])); // [END in_filter_with_array_modular] \ No newline at end of file From e74e8fd9591f70007a44c58580ff0f1fcd1c7959 Mon Sep 17 00:00:00 2001 From: Kevin Sanders Date: Thu, 9 Nov 2023 21:07:49 -0500 Subject: [PATCH 229/235] Typo Fix (#361) --- auth-next/custom-email-handler.js | 4 ++-- .../custom-email-handler/auth_handle_mgmt_query_params.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/auth-next/custom-email-handler.js b/auth-next/custom-email-handler.js index 728baff8..5fcc1f71 100644 --- a/auth-next/custom-email-handler.js +++ b/auth-next/custom-email-handler.js @@ -28,8 +28,8 @@ function handleUserManagementQueryParams() { // Configure the Firebase SDK. // This is the minimum configuration required for the API to be used. const config = { - 'apiKey': "YOU_API_KEY" // Copy this key from the web initialization - // snippet found in the Firebase console. + 'apiKey': "YOUR_API_KEY" // Copy this key from the web initialization + // snippet found in the Firebase console. }; const app = initializeApp(config); const auth = getAuth(app); diff --git a/snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js b/snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js index 6dec3399..d0a22696 100644 --- a/snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js +++ b/snippets/auth-next/custom-email-handler/auth_handle_mgmt_query_params.js @@ -23,8 +23,8 @@ document.addEventListener('DOMContentLoaded', () => { // Configure the Firebase SDK. // This is the minimum configuration required for the API to be used. const config = { - 'apiKey': "YOU_API_KEY" // Copy this key from the web initialization - // snippet found in the Firebase console. + 'apiKey': "YOUR_API_KEY" // Copy this key from the web initialization + // snippet found in the Firebase console. }; const app = initializeApp(config); const auth = getAuth(app); From a9160f62f8ebff02285779974620ad3ff260f5ac Mon Sep 17 00:00:00 2001 From: James Daniels Date: Wed, 13 Mar 2024 16:22:44 -0400 Subject: [PATCH 230/235] FirebaseServerApp (#366) * First. * already snippets for that * cleanup * auth_svc_admin * Auth, not auth-next * Express stub should not be in snippet * Move import into snippet * Update firebaseserverapp.js --- auth/package.json | 1 + auth/service-worker-sessions.js | 43 +++++++++++++++++++++ firebaseserverapp-next/firebaseserverapp.js | 27 +++++++++++++ firebaseserverapp-next/package.json | 12 ++++++ 4 files changed, 83 insertions(+) create mode 100644 firebaseserverapp-next/firebaseserverapp.js create mode 100644 firebaseserverapp-next/package.json diff --git a/auth/package.json b/auth/package.json index a6827027..b4b13f01 100644 --- a/auth/package.json +++ b/auth/package.json @@ -7,6 +7,7 @@ "license": "Apache 2.0", "dependencies": { "firebase": "^8.10.0", + "firebase-admin": "^12.0.0", "firebaseui": "^5.0.0" } } diff --git a/auth/service-worker-sessions.js b/auth/service-worker-sessions.js index babbf91e..05791463 100644 --- a/auth/service-worker-sessions.js +++ b/auth/service-worker-sessions.js @@ -162,3 +162,46 @@ function svcSignInEmail(email, password) { }); // [END auth_svc_sign_in_email] } + +function svcRedirectAdmin() { + const app = { use: (a) => {} }; + + // [START auth_svc_admin] + // Server side code. + const admin = require('firebase-admin'); + + // The Firebase Admin SDK is used here to verify the ID token. + admin.initializeApp(); + + function getIdToken(req) { + // Parse the injected ID token from the request header. + const authorizationHeader = req.headers.authorization || ''; + const components = authorizationHeader.split(' '); + return components.length > 1 ? components[1] : ''; + } + + function checkIfSignedIn(url) { + return (req, res, next) => { + if (req.url == url) { + const idToken = getIdToken(req); + // Verify the ID token using the Firebase Admin SDK. + // User already logged in. Redirect to profile page. + admin.auth().verifyIdToken(idToken).then((decodedClaims) => { + // User is authenticated, user claims can be retrieved from + // decodedClaims. + // In this sample code, authenticated users are always redirected to + // the profile page. + res.redirect('/profile'); + }).catch((error) => { + next(); + }); + } else { + next(); + } + }; + } + + // If a user is signed in, redirect to profile page. + app.use(checkIfSignedIn('/')); + // [END auth_svc_admin] +} diff --git a/firebaseserverapp-next/firebaseserverapp.js b/firebaseserverapp-next/firebaseserverapp.js new file mode 100644 index 00000000..d0ab338c --- /dev/null +++ b/firebaseserverapp-next/firebaseserverapp.js @@ -0,0 +1,27 @@ +// @ts-nocheck +// [START serverapp_auth] +import { initializeServerApp } from 'firebase/app'; +import { getAuth } from 'firebase/auth'; +import { headers } from 'next/headers'; +import { redirect } from 'next/navigation'; + +export default function MyServerComponent() { + + // Get relevant request headers (in Next.JS) + const authIdToken = headers().get('Authorization')?.split('Bearer ')[1]; + + // Initialize the FirebaseServerApp instance. + const serverApp = initializeServerApp(firebaseConfig, { authIdToken }); + + // Initialize Firebase Authentication using the FirebaseServerApp instance. + const auth = getAuth(serverApp); + + if (auth.currentUser) { + redirect('/profile'); + } + + // ... +} +// [END serverapp_auth] + +const firebaseConfig = {}; diff --git a/firebaseserverapp-next/package.json b/firebaseserverapp-next/package.json new file mode 100644 index 00000000..0836b0b2 --- /dev/null +++ b/firebaseserverapp-next/package.json @@ -0,0 +1,12 @@ +{ + "name": "firebaseserverapp-next", + "version": "1.0.0", + "scripts": { + "compile": "cp ../tsconfig.json.template ./tsconfig.json && tsc" + }, + "license": "Apache-2.0", + "dependencies": { + "firebase": "^10.0.0", + "next": "^14.1.3" + } +} From 1abb6ce1a784ae5552946dff5f1f5aab7dcbda30 Mon Sep 17 00:00:00 2001 From: "Nhien (Ricky) Lam" <62775270+NhienLam@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:24:45 -0700 Subject: [PATCH 231/235] =?UTF-8?q?Add=20snippets=20for=20Handling=20the?= =?UTF-8?q?=20account-exists-with-different=E2=80=A6=20(#367)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add v8 and v9 snippets for Handling the account-exists-with-different-credential error * Import auth functions * Add missing methods to param * Add missing methods to params for legacy snippets --- auth-next/link-multiple-accounts.js | 58 ++++++++++++++++++ auth/link-multiple-accounts.js | 56 +++++++++++++++++ .../account_exists_popup.js | 61 +++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 snippets/auth-next/link-multiple-accounts/account_exists_popup.js diff --git a/auth-next/link-multiple-accounts.js b/auth-next/link-multiple-accounts.js index 34c0db58..1938aafc 100644 --- a/auth-next/link-multiple-accounts.js +++ b/auth-next/link-multiple-accounts.js @@ -182,3 +182,61 @@ function unlink(providerId) { }); // [END auth_unlink_provider] } + +function accountExistsPopup(auth, facebookProvider, goToApp, promptUserForPassword, promptUserForSignInMethod, getProviderForProviderId) { + // [START account_exists_popup] + const { signInWithPopup, signInWithEmailAndPassword, linkWithCredential } = require("firebase/auth"); + + // User tries to sign in with Facebook. + signInWithPopup(auth, facebookProvider).catch((error) => { + // User's email already exists. + if (error.code === 'auth/account-exists-with-different-credential') { + // The pending Facebook credential. + const pendingCred = error.credential; + // The provider account's email address. + const email = error.customData.email; + + // Present the user with a list of providers they might have + // used to create the original account. + // Then, ask the user to sign in with the existing provider. + const method = promptUserForSignInMethod(); + + if (method === 'password') { + // TODO: Ask the user for their password. + // In real scenario, you should handle this asynchronously. + const password = promptUserForPassword(); + signInWithEmailAndPassword(auth, email, password).then((result) => { + return linkWithCredential(result.user, pendingCred); + }).then(() => { + // Facebook account successfully linked to the existing user. + goToApp(); + }); + return; + } + + // All other cases are external providers. + // Construct provider object for that provider. + // TODO: Implement getProviderForProviderId. + const provider = getProviderForProviderId(method); + // At this point, you should let the user know that they already have an + // account with a different provider, and validate they want to sign in + // with the new provider. + // Note: Browsers usually block popups triggered asynchronously, so in + // real app, you should ask the user to click on a "Continue" button + // that will trigger signInWithPopup(). + signInWithPopup(auth, provider).then((result) => { + // Note: Identity Platform doesn't control the provider's sign-in + // flow, so it's possible for the user to sign in with an account + // with a different email from the first one. + + // Link the Facebook credential. We have access to the pending + // credential, so we can directly call the link method. + linkWithCredential(result.user, pendingCred).then((userCred) => { + // Success. + goToApp(); + }); + }); + } +}); +// [END account_exists_popup] +} diff --git a/auth/link-multiple-accounts.js b/auth/link-multiple-accounts.js index 30f5a2ec..8eed77b8 100644 --- a/auth/link-multiple-accounts.js +++ b/auth/link-multiple-accounts.js @@ -166,3 +166,59 @@ function unlink(providerId) { }); // [END auth_unlink_provider] } + +function accountExistsPopup(facebookProvider, goToApp, promptUserForPassword, promptUserForSignInMethod, getProviderForProviderId) { + // [START account_exists_popup] + // User tries to sign in with Facebook. + auth.signInWithPopup(facebookProvider).catch((error) => { + // User's email already exists. + if (error.code === 'auth/account-exists-with-different-credential') { + // The pending Facebook credential. + const pendingCred = error.credential; + // The provider account's email address. + const email = error.email; + + // Present the user with a list of providers they might have + // used to create the original account. + // Then, ask the user to sign in with the existing provider. + const method = promptUserForSignInMethod(); + + if (method === 'password') { + // TODO: Ask the user for their password. + // In real scenario, you should handle this asynchronously. + const password = promptUserForPassword(); + auth.signInWithEmailAndPassword(email, password).then((result) => { + return result.user.linkWithCredential(pendingCred); + }).then(() => { + // Facebook account successfully linked to the existing user. + goToApp(); + }); + return; + } + + // All other cases are external providers. + // Construct provider object for that provider. + // TODO: Implement getProviderForProviderId. + const provider = getProviderForProviderId(method); + // At this point, you should let the user know that they already have an + // account with a different provider, and validate they want to sign in + // with the new provider. + // Note: Browsers usually block popups triggered asynchronously, so in + // real app, you should ask the user to click on a "Continue" button + // that will trigger signInWithPopup(). + auth.signInWithPopup(provider).then((result) => { + // Note: Identity Platform doesn't control the provider's sign-in + // flow, so it's possible for the user to sign in with an account + // with a different email from the first one. + + // Link the Facebook credential. We have access to the pending + // credential, so we can directly call the link method. + result.user.linkWithCredential(pendingCred).then((userCred) => { + // Success. + goToApp(); + }); + }); + } +}); +// [END account_exists_popup] +} diff --git a/snippets/auth-next/link-multiple-accounts/account_exists_popup.js b/snippets/auth-next/link-multiple-accounts/account_exists_popup.js new file mode 100644 index 00000000..2c667882 --- /dev/null +++ b/snippets/auth-next/link-multiple-accounts/account_exists_popup.js @@ -0,0 +1,61 @@ +// This snippet file was generated by processing the source file: +// ./auth-next/link-multiple-accounts.js +// +// To update the snippets in this file, edit the source and then run +// 'npm run snippets'. + + // [START account_exists_popup_modular] + import { signInWithPopup, signInWithEmailAndPassword, linkWithCredential } from "firebase/auth"; + + // User tries to sign in with Facebook. + signInWithPopup(auth, facebookProvider).catch((error) => { + // User's email already exists. + if (error.code === 'auth/account-exists-with-different-credential') { + // The pending Facebook credential. + const pendingCred = error.credential; + // The provider account's email address. + const email = error.customData.email; + + // Present the user with a list of providers they might have + // used to create the original account. + // Then, ask the user to sign in with the existing provider. + const method = promptUserForSignInMethod(); + + if (method === 'password') { + // TODO: Ask the user for their password. + // In real scenario, you should handle this asynchronously. + const password = promptUserForPassword(); + signInWithEmailAndPassword(auth, email, password).then((result) => { + return linkWithCredential(result.user, pendingCred); + }).then(() => { + // Facebook account successfully linked to the existing user. + goToApp(); + }); + return; + } + + // All other cases are external providers. + // Construct provider object for that provider. + // TODO: Implement getProviderForProviderId. + const provider = getProviderForProviderId(method); + // At this point, you should let the user know that they already have an + // account with a different provider, and validate they want to sign in + // with the new provider. + // Note: Browsers usually block popups triggered asynchronously, so in + // real app, you should ask the user to click on a "Continue" button + // that will trigger signInWithPopup(). + signInWithPopup(auth, provider).then((result) => { + // Note: Identity Platform doesn't control the provider's sign-in + // flow, so it's possible for the user to sign in with an account + // with a different email from the first one. + + // Link the Facebook credential. We have access to the pending + // credential, so we can directly call the link method. + linkWithCredential(result.user, pendingCred).then((userCred) => { + // Success. + goToApp(); + }); + }); + } +}); +// [END account_exists_popup_modular] \ No newline at end of file From 2117c619ce49b08d582f282e7d2ec798f5105c3d Mon Sep 17 00:00:00 2001 From: spider-hand Date: Wed, 29 May 2024 01:05:44 +0900 Subject: [PATCH 232/235] chore: update outdated comments (#370) --- auth-next/email-link-auth.js | 10 ++++++---- .../auth-next/email-link-auth/email_link_complete.js | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/auth-next/email-link-auth.js b/auth-next/email-link-auth.js index 59ea2115..4748e699 100644 --- a/auth-next/email-link-auth.js +++ b/auth-next/email-link-auth.js @@ -68,11 +68,13 @@ function emailLinkComplete() { .then((result) => { // Clear email from storage. window.localStorage.removeItem('emailForSignIn'); - // You can access the new user via result.user - // Additional user info profile not available via: - // result.additionalUserInfo.profile == null + // You can access the new user by importing getAdditionalUserInfo + // and calling it with result: + // getAdditionalUserInfo(result) + // You can access the user's profile via: + // getAdditionalUserInfo(result)?.profile // You can check if the user is new or existing: - // result.additionalUserInfo.isNewUser + // getAdditionalUserInfo(result)?.isNewUser }) .catch((error) => { // Some error occurred, you can inspect the code: error.code diff --git a/snippets/auth-next/email-link-auth/email_link_complete.js b/snippets/auth-next/email-link-auth/email_link_complete.js index b42b9af9..dbe1143d 100644 --- a/snippets/auth-next/email-link-auth/email_link_complete.js +++ b/snippets/auth-next/email-link-auth/email_link_complete.js @@ -26,11 +26,13 @@ if (isSignInWithEmailLink(auth, window.location.href)) { .then((result) => { // Clear email from storage. window.localStorage.removeItem('emailForSignIn'); - // You can access the new user via result.user - // Additional user info profile not available via: - // result.additionalUserInfo.profile == null + // You can access the new user by importing getAdditionalUserInfo + // and calling it with result: + // getAdditionalUserInfo(result) + // You can access the user's profile via: + // getAdditionalUserInfo(result)?.profile // You can check if the user is new or existing: - // result.additionalUserInfo.isNewUser + // getAdditionalUserInfo(result)?.isNewUser }) .catch((error) => { // Some error occurred, you can inspect the code: error.code From 56d70627e2dc275f01cd0e55699794bf40faca80 Mon Sep 17 00:00:00 2001 From: Daniel La Rocque Date: Tue, 8 Oct 2024 15:17:01 -0400 Subject: [PATCH 233/235] Upgrade versions in FCM service worker (#382) * Upgrade versions in FCM service worker * Add comment telling users to use latest --- messaging/service-worker.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/messaging/service-worker.js b/messaging/service-worker.js index c0f875bb..1a202159 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,8 +10,9 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js'); + // Replace 10.13.2 with latest version of the Firebase JS SDK. + importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-app-compat.js'); + importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-messaging-compat.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. From 3d04522869ad402c4da3ae74d6b30a4dbf8d1233 Mon Sep 17 00:00:00 2001 From: Athira M Date: Fri, 24 Jan 2025 12:17:10 +0530 Subject: [PATCH 234/235] RC doc update to provide default prod value for minimumFetchIntervalMillis (#389) * Add comment to highlight the default prod value for minimumFetchIntervalMillis. Issue addressed: https://github.com/firebase/firebase-js-sdk/issues/2841 * Update code snipped with default prod value for minimumFetchIntervalMillis. * Update code snipped with default prod value for minimumFetchIntervalMillis. * Update code snipped with default prod value for minimumFetchIntervalMillis. --------- Co-authored-by: Athira M --- remoteconfig-next/index.js | 1 + snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js | 1 + 2 files changed, 2 insertions(+) diff --git a/remoteconfig-next/index.js b/remoteconfig-next/index.js index aeeb263a..287f3c99 100644 --- a/remoteconfig-next/index.js +++ b/remoteconfig-next/index.js @@ -14,6 +14,7 @@ function getInstance() { function setMinimumFetchTime() { const remoteConfig = getInstance(); // [START rc_set_minimum_fetch_time] + // The default and recommended production fetch interval for Remote Config is 12 hours remoteConfig.settings.minimumFetchIntervalMillis = 3600000; // [END rc_set_minimum_fetch_time] } diff --git a/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js b/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js index 131976c5..77aa9f45 100644 --- a/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js +++ b/snippets/remoteconfig-next/index/rc_set_minimum_fetch_time.js @@ -5,5 +5,6 @@ // 'npm run snippets'. // [START rc_set_minimum_fetch_time_modular] +// The default and recommended production fetch interval for Remote Config is 12 hours remoteConfig.settings.minimumFetchIntervalMillis = 3600000; // [END rc_set_minimum_fetch_time_modular] \ No newline at end of file From 467eaa165dcbd9b3ab15711e76fa52237ba37f8b Mon Sep 17 00:00:00 2001 From: "Nhien (Ricky) Lam" <62775270+NhienLam@users.noreply.github.com> Date: Thu, 6 Feb 2025 15:39:06 -0800 Subject: [PATCH 235/235] Update email link auth snippet to stop using deprecated `dynamicLinkDomain` (#390) * Update email link auth snippet to remove FDL * Update custom domain example --- auth-next/email-link-auth.js | 3 ++- .../email-link-auth/auth_email_link_actioncode_settings.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/auth-next/email-link-auth.js b/auth-next/email-link-auth.js index 4748e699..fde67663 100644 --- a/auth-next/email-link-auth.js +++ b/auth-next/email-link-auth.js @@ -19,7 +19,8 @@ function emailLinkActionCodeSettings() { installApp: true, minimumVersion: '12' }, - dynamicLinkDomain: 'example.page.link' + // The domain must be configured in Firebase Hosting and owned by the project. + linkDomain: 'custom-domain.com' }; // [END auth_email_link_actioncode_settings] } diff --git a/snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js b/snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js index a1480a11..010b5c09 100644 --- a/snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js +++ b/snippets/auth-next/email-link-auth/auth_email_link_actioncode_settings.js @@ -19,6 +19,7 @@ const actionCodeSettings = { installApp: true, minimumVersion: '12' }, - dynamicLinkDomain: 'example.page.link' + // The domain must be configured in Firebase Hosting and owned by the project. + linkDomain: 'custom-domain.com' }; // [END auth_email_link_actioncode_settings_modular] \ No newline at end of file