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

147
Visualizações
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'message') at click

I am creating a registration form, and it is necessary to implement the click function, when clicked, we will call the appropriate functions: login or registartion, but an Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'message') at click error occurs. What is the problem?

const {user} = useContext(Context)
    const location = useLocation()
    const history = useHistory()
    const isLogin = location.pathname === LOGIN_ROUTE
    const [email, setEmail] = useState('')
    const [password, setPassword] = useState('')

    const click = async () => {
        try {
            let data;
            if (isLogin) {
                data = await login(email, password);
            } else {
                data = await registration(email, password);
            }
            user.setUser(user)
            user.setIsAuth(true)
            history.push(SHOP_ROUTE)
        } catch (e) {
            alert(e.response.data.message)
        }

    }

Here are the functions login, registration

import {$authHost, $host} from "./index";

    export const registration = async (email, password) => {
        const response = await $host.post('api/user/registration', {email, password, role: 'ADMIN'});
        return response;
    }
    
    export const login = async (email, password) => {
        const response = await $host.post('api/user/login', {email, password});
        return response;
    }

Error also appears POST https://localhost:5000/api/user/registration net::ERR_CONNECTION_REFUSED

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