Skip to content

Commit

Permalink
Move window check to after initializing Firebase (#20764)
Browse files Browse the repository at this point in the history
You can initialize the Firebase app instance without checking for window, but it is required for using the analytics module.
  • Loading branch information
Thomas Wang committed Jan 5, 2021
1 parent c8bc17f commit 356bcde
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions examples/with-firebase/firebase/clientApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ const clientCredentials = {
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
}

// Check that `window` is in scope for the analytics module!
if (typeof window !== 'undefined' && !firebase.apps.length) {
if (!firebase.apps.length) {
firebase.initializeApp(clientCredentials)
// To enable analytics. https://firebase.google.com/docs/analytics/get-started
if ('measurementId' in clientCredentials) {
firebase.analytics()
firebase.performance()
// Check that `window` is in scope for the analytics module!
if (typeof window !== 'undefined') {
// Enable analytics. https://firebase.google.com/docs/analytics/get-started
if ('measurementId' in clientCredentials) {
firebase.analytics()
firebase.performance()
}
}
}

Expand Down

0 comments on commit 356bcde

Please sign in to comment.