chore: add comments, setup instructions

This commit is contained in:
Kyle Gill
2019-05-29 20:50:22 -06:00
parent 477dc9e22c
commit 4dbe7ea49d
17 changed files with 91 additions and 20 deletions

View File

@@ -1,5 +1,6 @@
import React from "react"
// create context of firebase instance
const FirebaseContext = React.createContext(null)
export const withFirebase = Component => props => (

View File

@@ -2,6 +2,8 @@ import app from "firebase/app"
import "firebase/auth"
import "firebase/firestore"
// store private keys in .env file
// the prefix GATSBY_ is necessary here
const config = {
apiKey: process.env.GATSBY_FIREBASE_API_KEY,
authDomain: process.env.GATSBY_DEV_AUTH_DOMAIN,
@@ -13,6 +15,8 @@ const config = {
class Firebase {
constructor() {
// protect with conditional so gatsby build doesn't have
// issues trying to access the window object
if (typeof window !== "undefined") {
app.initializeApp(config)
this.auth = app.auth()
@@ -34,20 +38,25 @@ class Firebase {
}
}
// Auth
// authentication
// create user in the database
doCreateUserWithEmailAndPassword = (email, password) =>
this.auth.createUserWithEmailAndPassword(email, password)
// login already existing user
doSignInWithEmailAndPassword = (email, password) =>
this.auth.signInWithEmailAndPassword(email, password)
// sign out user
doSignOut = () => {
this.auth.signOut()
window.location.replace("/login")
}
// send email reset to email provided
doPasswordReset = email => this.auth.sendPasswordResetEmail(email)
// change password to password provided
doPasswordUpdate = password => this.auth.currentUser.updatePassword(password)
}