-1

I'm making a web app and it has a login page. Every time I submit the login credentials I keep getting this error.

POST http://localhost:3000/api/user/login 404 (Not Found)

Everything works fine on postman.

My userActions.js

export const login = (email, password) => async (dispatch) => {
try{
    dispatch({type: USER_LOGIN_REQUEST})

    const config = {
        header: {
            "Content-Type": "application/json",
        },
    }

    const {data} = await axios.post('/api/user/login',
    { email, password},
    config)
    dispatch({type: USER_LOGIN_SUCCESS, payload: data})

    localStorage.setItem('userInfo', JSON.stringify(data))
} catch (error) {
    dispatch({
        type: USER_LOGIN_FAIL,
        payload: error.response && error.response.data.message ?
        error.response.data.message : error.message,
    })
}
}

My react app is running on PORT 8675

POST http://localhost:8675/api/user/login in Postman works fine

POST on port 3000 in postman doesn't work however

Dharman
  • 30,962
  • 25
  • 85
  • 135
Rio A.
  • 31
  • 3

1 Answers1

0

You need to write true link on axios.post("...)

    const baseUrl = 'http://localhost:8675/';
    const {data} = await axios.post(baseUrl +'api/user/login',...}

    // or 

    const {data} = await axios.post('http://localhost:8675/api/user/login',...}