matheusbezerra1's picture
ok, so this website should be a modern private real estate, its a website where we will add high end properties, invitation only, so you need to create all the structure, backend as well so we can add and edit properties, create accounts
61cba86 verified
Raw History Blame Contribute Delete
745 Bytes
import { createContext, useContext, useEffect, useState } from 'react'
import { auth } from '../firebase'
import { onAuthStateChanged } from 'firebase/auth'
const AuthContext = createContext()
export function AuthProvider({ children }) {
const [currentUser, setCurrentUser] = useState(null)
const [loading, setLoading] = useState(true)
useEffect(() => {
const unsubscribe = onAuthStateChanged(auth, (user) => {
setCurrentUser(user)
setLoading(false)
})
return unsubscribe
}, [])
const value = {
currentUser,
loading
}
return (
<AuthContext.Provider value={value}>
{!loading && children}
</AuthContext.Provider>
)
}
export function useAuth() {
return useContext(AuthContext)
}