Skip to content

Instantly share code, notes, and snippets.

@ivanfgm
Created August 7, 2020 14:47
Show Gist options
  • Save ivanfgm/dd08739d37cfcf222622d2e8d2087ef0 to your computer and use it in GitHub Desktop.
Save ivanfgm/dd08739d37cfcf222622d2e8d2087ef0 to your computer and use it in GitHub Desktop.
Config file to integrate firebase with next.js or react projects in general
// This assumes you have a .env.local with firebase config constants
import * as firebase from 'firebase/app' // yarn add firebase
import 'firebase/auth' // if you use them
import 'firebase/firestore' // if you use them
const config = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_APIKEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTHDOMAIN,
databaseURL: process.env.NEXT_PUBLIC_FIREBASE_DATABASEURL,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECTID,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGEBUCKET,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGINGSENDERID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APPID,
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENTID
}
if (!firebase.apps.length) {
firebase.initializeApp(config)
}
export default firebase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment