Unverified Commit 356bcdec authored by Thomas Wang's avatar Thomas Wang Committed by GitHub

Move `window` check to after initializing Firebase (#20764)

You can initialize the Firebase app instance without checking for window, but it is required for using the analytics module.
parent c8bc17f3
...@@ -15,13 +15,15 @@ const clientCredentials = { ...@@ -15,13 +15,15 @@ const clientCredentials = {
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID, appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
} }
// Check that `window` is in scope for the analytics module! if (!firebase.apps.length) {
if (typeof window !== 'undefined' && !firebase.apps.length) {
firebase.initializeApp(clientCredentials) firebase.initializeApp(clientCredentials)
// To enable analytics. https://firebase.google.com/docs/analytics/get-started // Check that `window` is in scope for the analytics module!
if ('measurementId' in clientCredentials) { if (typeof window !== 'undefined') {
firebase.analytics() // Enable analytics. https://firebase.google.com/docs/analytics/get-started
firebase.performance() if ('measurementId' in clientCredentials) {
firebase.analytics()
firebase.performance()
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment