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

114
Visualizações
Async function in another file is not being hit

Currently, I'm trying to create a login and for some reason my code for my login is not being triggered. The function loginUserWithEmail is not being triggered. It is not being triggered because none of the console.log's inside the loginUserWithEmail function is printed in the console. The onSubmit() function in Login.tsx is triggers when I click a "Login" button.

Thank you.

Login.tsx:

import { useFormik } from 'formik';
import { loginUserWithEmail, LoginFormData } from '../../actions/authActions'

const Login = ({ auth, history, login }: {auth: any, history: RouteComponentProps['history'], login: any}) => {
const formik = useFormik({
initialValues: {
    email: '',
    password: '',
},
validationSchema: loginSchema,
    onSubmit: (values: LoginFormData) => {
        console.log("before loginuserwithemail");
        loginUserWithEmail(values, history);
        console.log("after")
    },
    });
...
}

authActions.ts

export const loginUserWithEmail = (formData: LoginFormData, history: RouteComponentProps['history']) => async (dispatch: any, getState: any) => {
  console.log("inside loginuserwithemail function")
  dispatch({ type: LOGIN_WITH_EMAIL_LOADING });
  try {
    const response = await axios.post('/auth/login', formData);
    console.log("inside here")
    dispatch({
      type: LOGIN_WITH_EMAIL_SUCCESS,
      payload: { token: response.data.token, me: response.data.me },
    });

    dispatch(loadMe());
    history.push('/');
  } catch (err: any) {
    dispatch({
      type: LOGIN_WITH_EMAIL_FAIL,
      payload: { error: err.response.data.message },
    });
  }
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

loginUserWithEmail is hoc (function that returns function) You need it to call function returned by this function

await loginUserWithEmail(values, history)(dispatch, getState);
about 4 years ago · Juan Pablo Isaza Relatório
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