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

186
Views
How should I do a post request to this url by using Axios (React)

I have to make a post request to sort of complex url :http://localhost:8080/api/login?email=example%40gmail.com&password=examplepassword according to swagger-ui. The examples at axios's github page says that the second parameter is an object. In my example the second parameter must include email and password properties but after that? I tried many ways to pull this situation of. One of these is below. By the way this error occurs: xhr.js:187 POST http://localhost:8080/api/login?email=asdsadsad&password=[object%20Object]

CustomerSlice:

const customerService = new CustomerService()

export const logCustomerIn = createAsyncThunk(
    'customer/logCustomerIn',
    async (email, password)=>{
        // const response = await customerService.logCustomerIn(email, password)
        
        const response = await axios.post(`http://localhost:8080/api/login?email=${email}&password=${password}`)
        console.log(response)
        return response.data.success
    }
)
export const getCustomers = createAsyncThunk(
    'customer/getCustomers',
    async ()=>{
       const response = await customerService.getAll()
        return response.data.data
    }
)

export const getCustomerByEmail = createAsyncThunk(
    'customer/getCustomerById',
    async(email)=>{
        const response = await customerService.getCustomerByEmail(email)
        console.log(response)
        return response.data.data
    }
)
export const customerSlice = createSlice({
    name:'customer',
    initialState: {
        items:[],
        currentCustomer:{},
        loggedIn:false,

    },
    reducers:{},
    extraReducers:{
        [logCustomerIn.fulfilled]:(state,action)=>{
            state.loggedIn = true
            console.log("logcustomer fulfilled")
        },
        [getCustomers.fulfilled]:(state,action)=>{
            state.items = action.payload
        },
        [getCustomerByEmail.fulfilled]: (state,action)=>{
            state.currentCustomer = action.payload
            console.log(state.currentCustomer)
        }
    }
})

export default customerSlice.reducer

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem is that the the callback function you pass to createAsyncThunk is called with a second parameter being an object called "thunkAPI", and not the password you've intended. Please see this doc: https://redux-toolkit.js.org/api/createAsyncThunk.

TL;DR;

If you need to pass in multiple values, pass them together in an object when you dispatch the thunk.

So what you should do is to pass an object like this

{
  email: <user_email>,
  password: <user_password>
}

and change the code that sends the request accordingly:

export const logCustomerIn = createAsyncThunk(
    'customer/logCustomerIn',
    async (credentials)=>{
        const response = await axios.post(`http://localhost:8080/api/login?email=${credentials.email}&password=${credentials.password}`)
        console.log(response)
        return response.data.success
    }
)
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!