text: import React, { useContext, useState, useEffect } from "react";
  import { createUserWithEmailAndPassword, signInWithEmailAndPassword, signOut } from "firebase/auth"
  import { auth } from "../firebase/firebase"
  
  const AuthContext = React.createContext()
  
  export function useAuth() {
    return useContext(AuthContext)
  }
  
  export function AuthProvider({ children }) {
    const [currentUser, setCurrentUser] = useState()
    const [loading, setLoading] = useState(true)
  
    function signup(email, password) {
      return createUserWithEmailAndPassword(auth, email, password)
    }
  
    function login(email, password) {
      return signInWithEmailAndPassword(auth, email, password)
    }
  
    function logout() {
      return signOut(auth)
    }
  
    function resetPassword(email) {
      return auth.sendPasswordResetEmail(email)
    }
  
    function updateEmail(email) {
      return currentUser.updateEmail(email)
    }
  
    function updatePassword(password) {
      return currentUser.updatePassword(password)
    }
  
    useEffect(() => {
      const unsubscribe = auth.onAuthStateChanged(user => {
        setCurrentUser(user)
        setLoading(false)
      })
  
      return unsubscribe
    }, [])
  
    const value = {
      currentUser,
      login,
      signup,
      logout,
      resetPassword,
      updateEmail,
      updatePassword
    }
  
    return (
      <AuthContext.Provider value={value}>
        {!loading && children}
      </AuthContext.Provider>
    )
  }
  