import app from 'firebase/app';
import 'firebase/firestore';
apiKey: process.env.REACT_APP_API_KEY,
authDomain: process.env.REACT_APP_AUTH_DOMAIN,
databaseURL: process.env.REACT_APP_DATABASE_URL,
projectId: process.env.REACT_APP_PROJECT_ID,
storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID
app.initializeApp(config);
this.db = app.firestore();
userRef = uid => this.db.doc(`users/${ uid }`);
usersRef = () => this.db.collection('users');
user = async uid => await this.userRef(uid).get();
users = async () => await this.usersRef().get();
// *** Merge Auth and DB User API *** //
onAuthUserListener = (next, fallback) =>
this.auth.onAuthStateChanged(async authUser => {
const dbSnapshot = await this.user(authUser.uid);
const dbUser = dbSnapshot.data();
// merge auth and db user
emailVerified: authUser.emailVerified,
providerData: authUser.providerData,
// doCreateUserWithEmailAndPassword = (email, password) =>
// this.auth.createUserWithEmailAndPassword(email, password);
doSignInWithEmailAndPassword = (email, password) =>
this.auth.signInWithEmailAndPassword(email, password);
doSignOut = () => this.auth.signOut();
doPasswordReset = email => this.auth.sendPasswordResetEmail(email);
doPasswordUpdate = password => this.auth.currentUser.updatePassword(password);