Skip to content

Commit d9fbdfc

Browse files
authored
Remove default app where possible (firebase#135)
1 parent 8afe3fa commit d9fbdfc

File tree

173 files changed

+284
-566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+284
-566
lines changed

analytics-next/ecommerce.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
// [SNIPPET_REGISTRY disabled]
22
// [SNIPPETS_SEPARATION enabled]
33

4-
import { initializeApp } from "firebase/app";
5-
6-
const firebaseApp = initializeApp({
7-
apiKey: '### FIREBASE API KEY ###',
8-
appId: '### FIREBASE APP ID ###',
9-
projectId: '### FIREBASE PROJECT ID ###'
10-
});
11-
12-
134
// [START analytics_ecommerce_items]
145
// A pair of jeggings
156
const item_jeggings = {
@@ -54,7 +45,7 @@ function ecommerceViewItemList() {
5445
};
5546

5647
// Log event
57-
const analytics = getAnalytics(firebaseApp);
48+
const analytics = getAnalytics();
5849
logEvent(analytics, 'view_item_list', params1);
5950
// [END analytics_ecommerce_view_item_list]
6051
}
@@ -71,7 +62,7 @@ function ecommerceSelectItem() {
7162
};
7263

7364
// Log event
74-
const analytics = getAnalytics(firebaseApp);
65+
const analytics = getAnalytics();
7566
logEvent(analytics, 'select_item', params2);
7667
// [END analytics_ecommerce_select_item]
7768
}
@@ -88,7 +79,7 @@ function ecommerceViewItemDetails() {
8879
};
8980

9081
// Log event
91-
const analytics = getAnalytics(firebaseApp);
82+
const analytics = getAnalytics();
9283
logEvent(analytics, 'view_item', params3);
9384
// [END analytics_ecommerce_view_item_details]
9485
}
@@ -111,7 +102,7 @@ function ecommerceAddCart() {
111102
};
112103

113104
// Log event when a product is added to a wishlist
114-
const analytics = getAnalytics(firebaseApp);
105+
const analytics = getAnalytics();
115106
logEvent(analytics, 'add_to_wishlist', params4);
116107

117108
// Log event when a product is added to the cart
@@ -142,7 +133,7 @@ function ecommerceViewCart() {
142133
};
143134

144135
// Log event when the cart is viewed
145-
const analytics = getAnalytics(firebaseApp);
136+
const analytics = getAnalytics();
146137
logEvent(analytics, 'view_cart', params5);
147138
// [END analytics_ecommerce_view_cart]
148139
}
@@ -159,7 +150,7 @@ function ecommerceRemoveCart() {
159150
};
160151

161152
// Log event
162-
const analytics = getAnalytics(firebaseApp);
153+
const analytics = getAnalytics();
163154
logEvent(analytics, 'remove_from_cart', params6);
164155
// [END analytics_ecommerce_remove_cart]
165156
}
@@ -177,7 +168,7 @@ function ecommerceCheckout() {
177168
};
178169

179170
// Log event
180-
const analytics = getAnalytics(firebaseApp);
171+
const analytics = getAnalytics();
181172
logEvent(analytics, 'begin_checkout', params7);
182173
// [END analytics_ecommerce_checkout]
183174
}
@@ -196,7 +187,7 @@ function ecommerceShippingInfo() {
196187
};
197188

198189
// Log event
199-
const analytics = getAnalytics(firebaseApp);
190+
const analytics = getAnalytics();
200191
logEvent(analytics, 'add_shipping_info', params8);
201192
// [END analytics_ecommerce_shipping_info]
202193
}
@@ -215,7 +206,7 @@ function ecommercePaymentInfo() {
215206
};
216207

217208
// Log event
218-
const analytics = getAnalytics(firebaseApp);
209+
const analytics = getAnalytics();
219210
logEvent(analytics, 'add_payment_info', params9);
220211
// [END analytics_ecommerce_payment_info]
221212
}
@@ -237,7 +228,7 @@ function ecommercePurchase() {
237228
};
238229

239230
// Log event
240-
const analytics = getAnalytics(firebaseApp);
231+
const analytics = getAnalytics();
241232
logEvent(analytics, 'purchase', params10);
242233
// [END analytics_ecommerce_purchase]
243234
}
@@ -264,7 +255,7 @@ function ecommerceRefund() {
264255
params11.items.push(refundedProduct);
265256

266257
// Log event
267-
const analytics = getAnalytics(firebaseApp);
258+
const analytics = getAnalytics();
268259
logEvent(analytics, 'refund', params11);
269260
// [END analytics_ecommerce_refund]
270261
}
@@ -284,7 +275,7 @@ function ecommercePromotions() {
284275
};
285276

286277
// Log event when a promotion is displayed
287-
const analytics = getAnalytics(firebaseApp);
278+
const analytics = getAnalytics();
288279
logEvent(analytics, 'view_promotion', params12);
289280

290281
// Log event when a promotion is selected

analytics-next/index.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,19 @@
33

44
import { initializeApp } from "firebase/app";
55

6-
const firebaseApp = initializeApp({
7-
apiKey: '### FIREBASE API KEY ###',
8-
appId: '### FIREBASE APP ID ###',
9-
projectId: '### FIREBASE PROJECT ID ###'
10-
});
11-
126
function initialize() {
137
// [START analytics_initialize]
148
const { getAnalytics } = require("firebase/analytics");
159

16-
const analytics = getAnalytics(firebaseApp);
10+
const analytics = getAnalytics();
1711
// [END analytics_initialize]
1812
}
1913

2014
function logEvent() {
2115
// [START analytics_log_event]
2216
const { getAnalytics, logEvent } = require("firebase/analytics");
2317

24-
const analytics = getAnalytics(firebaseApp);
18+
const analytics = getAnalytics();
2519
logEvent(analytics, 'notification_received');
2620
// [END analytics_log_event]
2721
}
@@ -30,7 +24,7 @@ function logEventParams() {
3024
// [START analytics_log_event_params]
3125
const { getAnalytics, logEvent } = require("firebase/analytics");
3226

33-
const analytics = getAnalytics(firebaseApp);
27+
const analytics = getAnalytics();
3428
logEvent(analytics, 'select_content', {
3529
content_type: 'image',
3630
content_id: 'P12453',
@@ -43,7 +37,7 @@ function logEventCustomParams() {
4337
// [START analytics_log_event_custom_params]
4438
const { getAnalytics, logEvent } = require("firebase/analytics");
4539

46-
const analytics = getAnalytics(firebaseApp);
40+
const analytics = getAnalytics();
4741
logEvent(analytics, 'goal_completion', { name: 'lever_puzzle'});
4842
// [END analytics_log_event_custom_params]
4943
}
@@ -52,7 +46,7 @@ function setUserProperties() {
5246
// [START analytics_set_user_properties]
5347
const { getAnalytics, setUserProperties } = require("firebase/analytics");
5448

55-
const analytics = getAnalytics(firebaseApp);
49+
const analytics = getAnalytics();
5650
setUserProperties(analytics, { favorite_food: 'apples' });
5751
// [END analytics_set_user_properties]
5852
}

auth-next/anonymous.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
// [SNIPPET_REGISTRY disabled]
22
// [SNIPPETS_SEPARATION enabled]
33

4-
import { initializeApp } from "firebase/app";
5-
6-
const firebaseApp = initializeApp({
7-
projectId: '### PROJECT ID ###',
8-
apiKey: '### FIREBASE API KEY ###',
9-
authDomain: '### FIREBASE AUTH DOMAIN ###',
10-
});
11-
124
function anonSignIn() {
135
// [START auth_anon_sign_in]
146
const { getAuth, signInAnonymously } = require("firebase/auth");
157

16-
const auth = getAuth(firebaseApp);
8+
const auth = getAuth();
179
signInAnonymously(auth)
1810
.then(() => {
1911
// Signed in..

auth-next/apple.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
// [SNIPPET_REGISTRY disabled]
22
// [SNIPPETS_SEPARATION enabled]
33

4-
import { initializeApp } from "firebase/app";
5-
6-
const firebaseApp = initializeApp({
7-
projectId: '### PROJECT ID ###',
8-
apiKey: '### FIREBASE API KEY ###',
9-
authDomain: '### FIREBASE AUTH DOMAIN ###',
10-
});
11-
124
// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/apple.md
135

146
function appleProvider() {
@@ -35,7 +27,7 @@ function appleSignInPopup(provider) {
3527
// [START auth_apple_signin_popup]
3628
const { getAuth, signInWithPopup, OAuthProvider } = require("firebase/auth");
3729

38-
const auth = getAuth(firebaseApp);
30+
const auth = getAuth();
3931
signInWithPopup(auth, provider)
4032
.then((result) => {
4133
// The signed-in user info.
@@ -66,7 +58,7 @@ function appleSignInRedirect(provider) {
6658
// [START auth_apple_signin_redirect]
6759
const { getAuth, signInWithRedirect } = require("firebase/auth");
6860

69-
const auth = getAuth(firebaseApp);
61+
const auth = getAuth();
7062
signInWithRedirect(auth, provider);
7163
// [END auth_apple_signin_redirect]
7264
}
@@ -76,7 +68,7 @@ function appleSignInRedirectResult() {
7668
const { getAuth, getRedirectResult, OAuthProvider } = require("firebase/auth");
7769

7870
// Result from Redirect auth flow.
79-
const auth = getAuth(firebaseApp);
71+
const auth = getAuth();
8072
getRedirectResult(auth)
8173
.then((result) => {
8274
const credential = OAuthProvider.credentialFromResult(result);
@@ -107,7 +99,7 @@ function appleReauthenticatePopup() {
10799
const { getAuth, reauthenticateWithPopup, OAuthProvider } = require("firebase/auth");
108100

109101
// Result from Redirect auth flow.
110-
const auth = getAuth(firebaseApp);
102+
const auth = getAuth();
111103
const provider = new OAuthProvider('apple.com');
112104

113105
reauthenticateWithPopup(auth.currentUser, provider)
@@ -144,7 +136,7 @@ function appleLinkFacebook() {
144136
// [START auth_apple_link_facebook]
145137
const { getAuth, linkWithPopup, FacebookAuthProvider } = require("firebase/auth");
146138

147-
const auth = getAuth(firebaseApp);
139+
const auth = getAuth();
148140
const provider = new FacebookAuthProvider();
149141
provider.addScope('user_birthday');
150142

@@ -192,7 +184,7 @@ function appleSignInNonce(appleIdToken, unhashedNonce,) {
192184
// [START auth_apple_signin_nonce]
193185
const { getAuth, signInWithCredential, OAuthProvider } = require("firebase/auth");
194186

195-
const auth = getAuth(firebaseApp);
187+
const auth = getAuth();
196188

197189
// Build Firebase credential with the Apple ID token.
198190
const provider = new OAuthProvider('apple.com');

auth-next/auth-state-persistence.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
// [SNIPPET_REGISTRY disabled]
22
// [SNIPPETS_SEPARATION enabled]
33

4-
import { initializeApp } from "firebase/app";
5-
6-
const firebaseApp = initializeApp({
7-
projectId: '### PROJECT ID ###',
8-
apiKey: '### FIREBASE API KEY ###',
9-
authDomain: '### FIREBASE AUTH DOMAIN ###',
10-
});
11-
124
function setPersistenceSession() {
135
const email = "...";
146
const password = "...";
157

168
// [START auth_set_persistence_session]
179
const { getAuth, setPersistence, signInWithEmailAndPassword, browserSessionPersistence } = require("firebase/auth");
1810

19-
const auth = getAuth(firebaseApp);
11+
const auth = getAuth();
2012
setPersistence(auth, browserSessionPersistence)
2113
.then(() => {
2214
// Existing and future Auth states are now persisted in the current
@@ -38,7 +30,7 @@ function setPersistenceNone() {
3830
// [START auth_set_persistence_none]
3931
const { getAuth, setPersistence, signInWithRedirect, inMemoryPersistence, GoogleAuthProvider } = require("firebase/auth");
4032

41-
const auth = getAuth(firebaseApp);
33+
const auth = getAuth();
4234
setPersistence(auth, inMemoryPersistence)
4335
.then(() => {
4436
const provider = new GoogleAuthProvider();

auth-next/cordova.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
// [SNIPPET_REGISTRY disabled]
22
// [SNIPPETS_SEPARATION enabled]
33

4-
import { initializeApp } from "firebase/app";
5-
6-
const firebaseApp = initializeApp({
7-
projectId: '### PROJECT ID ###',
8-
apiKey: '### FIREBASE API KEY ###',
9-
authDomain: '### FIREBASE AUTH DOMAIN ###',
10-
});
11-
124
// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/web/cordova.md
135

146
function createGoogleProvider() {
@@ -23,7 +15,7 @@ function cordovaSignInRedirect() {
2315
// [START auth_cordova_sign_in_redirect]
2416
const { getAuth, signInWithRedirect, getRedirectResult, GoogleAuthProvider } = require("firebase/auth");
2517

26-
const auth = getAuth(firebaseApp);
18+
const auth = getAuth();
2719
signInWithRedirect(auth, new GoogleAuthProvider())
2820
.then(() => {
2921
return getRedirectResult(auth);
@@ -50,7 +42,7 @@ function cordovaRedirectResult() {
5042
// [START auth_cordova_redirect_result]
5143
const { getAuth, getRedirectResult, GoogleAuthProvider } = require("firebase/auth");
5244

53-
const auth = getAuth(firebaseApp);
45+
const auth = getAuth();
5446
getRedirectResult(auth)
5547
.then((result) => {
5648
const credential = GoogleAuthProvider.credentialFromResult(result);

auth-next/custom-email-handler.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
// [SNIPPET_REGISTRY disabled]
22
// [SNIPPETS_SEPARATION enabled]
33

4-
import { initializeApp } from "firebase/app";
5-
6-
const firebaseApp = initializeApp({
7-
projectId: '### PROJECT ID ###',
8-
apiKey: '### FIREBASE API KEY ###',
9-
authDomain: '### FIREBASE AUTH DOMAIN ###',
10-
});
11-
124
// Docs: https://source.corp.google.com/piper///depot/google3/third_party/devsite/firebase/en/docs/auth/custom-email-handler.md
135

146
function handleUserManagementQueryParams() {

auth-next/custom.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
// [SNIPPET_REGISTRY disabled]
22
// [SNIPPETS_SEPARATION enabled]
33

4-
import { initializeApp } from "firebase/app";
5-
6-
const firebaseApp = initializeApp({
7-
projectId: '### PROJECT ID ###',
8-
apiKey: '### FIREBASE API KEY ###',
9-
authDomain: '### FIREBASE AUTH DOMAIN ###',
10-
});
11-
124
function signInCustom() {
135
const token = "token123";
146

157
// [START auth_sign_in_custom]
168
const { getAuth, signInWithCustomToken } = require("firebase/auth");
179

18-
const auth = getAuth(firebaseApp);
10+
const auth = getAuth();
1911
signInWithCustomToken(auth, token)
2012
.then((userCredential) => {
2113
// Signed in

0 commit comments

Comments
 (0)