Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!