I’m working on an app in angular and currently trying to simply get the current users meta_data to check if I need to modify it. From my understanding this can be done on the front-end through the access token that’s available if the user is logged in. I’m trying to do this with the following code:
this.auth.getAccessTokenSilently().subscribe((token) => {
const headers = new HttpHeaders()
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.set('audience', 'https://-validdomain/api/v2/');
this.auth.idTokenClaims$.subscribe((claims) => {
let userId = claims!['sub'];
const url = 'https://-validdomain-/api/v2/users/' + userId;
console.log(claims);
this.http.get(url, { 'headers': headers }).subscribe((userData: any) => {
if(!userData.user_metadata) {
const metadata = {
'user_metadata': {
'custom_nickname': 'test123'
}
};
const body = JSON.stringify(metadata);
console.log(body);
} else {
}
});
});
});
But this return a response of “Status: 0, Unknown Error” Why is this?
I’ve double check that the user exists and the information is valid.