Able read a user profile and can update user meta data from Auth0 in my angular 2 application.Like this
this.lock.getProfile(authResult.idToken, (error, profile) => {
if (error) {
// Handle error
alert(error);
return;
}
And
this.authHttp
.patch('https://' + myConfig.domain + '/api/v2/users/' + this.auth.userProfile.user_id, data, {headers: headers})
.map(response => response.json())
.subscribe(
response => {
this.auth.userProfile = response;
localStorage.setItem('profile', JSON.stringify(response));
this.router.navigate(['/profile']);
},
error => alert(error.json().message)
);
But while trying to get all user getting error - "Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 404."
This is the code
var headers: any = {
"Content-Type": "application/json; charset=utf-8",
"cache-control": "no-cache"
};
this.authHttp
.get('https://' + myConfig.domain + '/api/v2/users/' + '?per_page=100&page=0&search_engine=v2', { headers: headers })
.map(response => response.json())
.subscribe(
response => {
console.log(response);
},
error => alert(error.json().message)
);
where client test is working fine in the website https://auth0.com/docs/api/management/v2#!/Users/get_users Not sure what going wrong.
Also header with Access-Control-Allow-Origin, have same issue
var headers: any = {
"Content-Type": "application/json; charset=utf-8",
"cache-control": "no-cache",
"Access-Control-Allow-Origin": "*"
};
Actually, You are trying with
localhost
, so you have to addheader
in back-end:Hope this help.