axios basic auth - how to pass user and password to api?

0

I was looking at the axios documentation and saw that to pass the user and password it is necessary to use:

auth: {
  username: 'janedoe',
  password: 's00pers3cret'
},

I applied the same in my reactjs code:

axios.get(store.urlBase + 'api/teste?teste=' + teste+ '&teste2=' + teste2,{},{
   auth: {
      Username: 'janedoe',
      Password: 's00pers3cret'
   }
})

But when it arrives in api the value of username and password is empty, what can be done?

Note: By Postman it works!

    
asked by anonymous 20.08.2018 / 15:40

1 answer

1

In the axios documentation, the get method receives only two parameters: the url and the settings.

In your code you are passing three. Your second parameter is an empty object ({}) and axios is using it to configure the settings. So, you just call the get method as follows:

axios.get('api', {
   auth: { 
      username: 'janedoe', 
      password: 's00pers3cret' 
   }
})
    
26.08.2018 / 15:01