text: const config = {
    apiKey: "AIzaSyCi6P1abcy72QaTwfV7ZQHczpsJo6wOzvw",
    authDomain: "gatsbyfb-8e6d6.firebaseapp.com",
    databaseURL: "https://gatsbyfb-8e6d6.firebaseio.com",
    projectId: "gatsbyfb-8e6d6",
    storageBucket: "",
    messagingSenderId: "921327650405",
    appId: "1:921327650405:web:e247fd630bfd6e9a"
  };
  
  class Firebase {
    constructor(app) {
      app.initializeApp(config);
  
      /* Helper */
  
      this.serverValue = app.database.ServerValue;
      this.emailAuthProvider = app.auth.EmailAuthProvider;
  
      /* Firebase APIs */
  
      this.auth = app.auth();
      this.db = app.database();
  
      /* Social Sign In Method Provider */
  
      this.googleProvider = new app.auth.GoogleAuthProvider();
      this.facebookProvider = new app.auth.FacebookAuthProvider();
      this.twitterProvider = new app.auth.TwitterAuthProvider();
    }
  
    // *** Auth API ***
  
    doCreateUserWithEmailAndPassword = (email, password) =>
      this.auth.createUserWithEmailAndPassword(email, password);
  
    doSignInWithEmailAndPassword = (email, password) =>
      this.auth.signInWithEmailAndPassword(email, password);
  
    doSignInWithGoogle = () =>
      this.auth.signInWithPopup(this.googleProvider);
  
    doSignInWithFacebook = () =>
      this.auth.signInWithPopup(this.facebookProvider);
  
    doSignInWithTwitter = () =>
      this.auth.signInWithPopup(this.twitterProvider);
  
    doSignOut = () => this.auth.signOut();
  
    doPasswordReset = email => this.auth.sendPasswordResetEmail(email);
  
    doSendEmailVerification = () =>
      this.auth.currentUser.sendEmailVerification({
        url: process.env.GATSBY_CONFIRMATION_EMAIL_REDIRECT,
      });
  
    doPasswordUpdate = password =>
      this.auth.currentUser.updatePassword(password);
  
    // *** Merge Auth and DB User API *** //
  
    onAuthUserListener = (next, fallback) =>
      this.auth.onAuthStateChanged(authUser => {
        if (authUser) {
          this.user(authUser.uid)
            .once('value')
            .then(snapshot => {
              const dbUser = snapshot.val();
  
              // default empty roles
              if (!dbUser.roles) {
                dbUser.roles = {};
              }
  
              // merge auth and db user
              authUser = {
                uid: authUser.uid,
                email: authUser.email,
                emailVerified: authUser.emailVerified,
                providerData: authUser.providerData,
                ...dbUser,
              };
  
              next(authUser);
            });
        } else {
          fallback();
        }
      });
  
    // *** User API ***
  
    user = uid => this.db.ref(`users/${uid}`);
  
    users = () => this.db.ref('users');
  
    // *** Message API ***
  
    message = uid => this.db.ref(`messages/${uid}`);
  
    messages = () => this.db.ref('messages');
  }
  
  let firebase;
  
  function getFirebase(app, auth, database) {
    if (!firebase) {
      firebase = new Firebase(app, auth, database);
    }
  
    return firebase;
  }
  
  export default getFirebase;
  