Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
TypeError: Cannot destructure property 'currentUser' of 'Object(...)(...)' as it is undefined

I'm trying to make a logOut function with firebase on React. I have the following code for the logOut function:

const [error, setError] = useState('');
    const { currentUser, logout } = useAuth();

    const handleLogout = async () => {
        try {
            await logout();
        } catch (error) {
            setError('Server error');
        }
    }

I'm calling that code on a Link because it is in a navBar:

<Link className="nav-link" to="/iniciosesion" onClick={handleLogout}>LogOut</Link>

I'm importing useAuth like this:

import { useAuth } from '../context/AuthContext';

And this is what I have in my AuthContext.js:

import React, { createContext, useEffect, useState, useContext } from 'react'
import { auth } from '../firebase' 

const AuthContext = createContext();
export const useAuth = () => useContext(AuthContext);
export const AuthProvider = (props) => {

    const [currentUser, setCurrentUser] = useState({});

    useEffect(() => {
        auth.onAuthStateChanged((user) => {
            setCurrentUser(user);
        })
    }, [])

    const logout = () => auth.signOut();
    const value = { logout, currentUser };

    return (
        <AuthContext.Provider value={value}>
            {props.children}
        </AuthContext.Provider>
    )
}

I have searched up and I can't find a solution for this problem.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda