Skip to content

Commit

Permalink
Added firebase connection and hook
Browse files Browse the repository at this point in the history
  • Loading branch information
bgonp committed Mar 27, 2021
1 parent a4ea2b2 commit 9ec48d2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
VITE_FB_API_KEY=
VITE_FB_AUTH_DOMAIN=
VITE_FB_PROJECT_ID=
VITE_FB_STORAGE_BUCKET=
VITE_FB_SENDER_ID=
VITE_FB_APP_ID=
35 changes: 35 additions & 0 deletions src/hooks/useFirebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import firebase from 'firebase'
import { useCallback } from 'react'
import { useAuthState } from 'react-firebase-hooks/auth'
import { useCollectionData } from 'react-firebase-hooks/firestore'

firebase.initializeApp({
apiKey: import.meta.env.VITE_FB_API_KEY,
authDomain: import.meta.env.VITE_FB_AUTH_DOMAIN,
projectId: import.meta.env.VITE_FB_PROJECT_ID,
storageBucket: import.meta.env.VITE_FB_STORAGE_BUCKET,
messagingSenderId: import.meta.env.VITE_FB_SENDER_ID,
appId: import.meta.env.VITE_FB_APP_ID
})

const auth = firebase.auth()
const firestore = firebase.firestore()

const useFirebase = () => {
const [user] = useAuthState(auth)

const signIn = useCallback(() => {
const provider = new firebase.auth.GoogleAuthProvider()
auth.signInWithPopup(provider)
})

const signOut = useCallback(() => auth.signOut(), [])

return {
user,
signIn,
signOut
}
}

export default useFirebase

0 comments on commit 9ec48d2

Please sign in to comment.