I am switching my app from a jquery to vuejs app. For this reason, I’m attempting to convert $.ajax to axios.
This is the current ajax request (which works fine) which puts user’s data into the Auth0 account’s user_metadata:
$.ajax({
url: 'https://' + auth0Url + '/api/v2/users/' + profile.user_id,
method: 'PATCH',
contentType: 'application/json',
data: JSON.stringify({ user_metadata: {firstName: userFirstName, lastName: userLastName} }),
'beforeSend': function(xhr) {
xhr.setRequestHeader('Authorization',
'Bearer ' + localStorage.getItem('id_token'));
}
}).done(function(updated_profile) {
localStorage.setItem('profile', JSON.stringify(updated_profile));
});
Below is my axios version of the same ajax request, but on this, no data gets put into the Auth0 account. No errors and 200 response - user profile is returned (without metadata).
var dataObj = JSON.stringify({ user_metadata: {firstName: userFirstName, lastName: userLastName} });
axios.get('/api/v2/users/' + profile.user_id,{
method:'PATCH',
baseURL: 'https://' + auth0Url,
headers:{
'Content-Type': 'application/json',
'Authorization':'Bearer ' + localStorage.getItem('id_token')
},
data:{dataObj}
})
.then(response => {
localStorage.setItem('profile', JSON.stringify(response.data));
});
I’ve tried a million different combinations with the {} and JSON.stringify and nothing seems to work - can anyone provide any suggestions on things to try with this axios function.