Package Exports
- web-firebase
- web-firebase/dist/index.js
- web-firebase/dist/index.modern.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (web-firebase) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
web-firebase
This library makes you to execute some Firebase web authentication processes and Firestore CRUD operations easily.
Install
npm install web-firebaseUsage
Add a custom hook named "useFirebase" to your project
Paste this entire code in this custom hook.
Arrange .env file according to this custom hook.
import { useState, useEffect } from 'react'
import { useAuth, useFirestore, initialize } from 'web-firebase'
const useFirebase = () => {
const [auth, setAuth] = useState(null)
const [db, setDb] = useState(null)
const { userObserver, userInfo } = useAuth(auth)
useEffect(() => {
const { auth: authRes, db: dbRes } = initialize({
apiKey: process.env.REACT_APP_API_KEY,
authDomain: process.env.REACT_APP_AUTH_DOMAIN,
projectId: process.env.REACT_APP_PROJECT_ID,
storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_STORAGE_BUCKET,
appId: process.env.REACT_APP_APP_ID
})
userObserver(authRes)
setAuth(authRes)
setDb(dbRes)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [userInfo])
//? For Authentication Processes
const {
createUser,
signIn,
googleAuth,
updateUserProfile,
updateUserEmail,
changePassword,
verifyEmail,
resetPassword,
logOut,
error: errorAuth
} = useAuth(auth)
//? For Firestore Database CRUD Operations
const {
addNewEntry,
getEntries,
updateEntries,
deleteEntry,
error: errorDb
} = useFirestore(db)
return {
//? Authentication
createUser,
signIn,
googleAuth,
updateUserProfile,
updateUserEmail,
changePassword,
verifyEmail,
resetPassword,
logOut,
errorAuth,
userInfo,
//? Firestore
addNewEntry,
getEntries,
updateEntries,
deleteEntry,
errorDb
}
}
export default useFirebaseLicense
MIT © erol1098
Keywords
Firebase, Authentication, Firestore, CRUD Operations