How can it be that this code snippet:
this.store.select(getAuthResponseSelector)
.subscribe((response: AuthenticateResponse) => {
if (response != null) {
console.log('Response', response);
console.log('ResponseType', typeof response);
console.log('EntroSubscribeTokenBefore', JSON.parse(JSON.stringify(response)));
console.log('EntroSubscribeTokenType', typeof JSON.parse(JSON.stringify(response)));
console.log('EntroSubscribeToken', JSON.parse(JSON.stringify(response)).access_token);
const newToken = Object.assign({}, response);
console.log('NewObject', typeof newToken);
for(let key in newToken){
console.log('Key:', newToken[key])
}
this.token = newToken.access_token
}
});
This is the resulting output:
[12:32:39] console.log: Response
{"access_token":"afcddc76-8322-4186-9b54-aa4143f381eb","token_type":"bearer","refresh_token":"fda3fcf4-8335-45cf-94ca-cd0aec1a90cb","expires_in":26313,"scope":"custom
default","firstname":"testswinetmm_cost","lastname":"testswinetmm_cost","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="562233252225213f3833223b3b093539252216223325223f38313b373f3a7835393b">[email protected]</a>","uid":"testswinetmm_cost"}
[12:32:39] console.log: ResponseType string
[12:32:39] console.log: EntroSubscribeTokenBefore
{"access_token":"afcddc76-8322-4186-9b54-aa4143f381eb","token_type":"bearer","refresh_token":"fda3fcf4-8335-45cf-94ca-cd0aec1a90cb","expires_in":26313,"scope":"custom
default","firstname":"testswinetmm_cost","lastname":"testswinetmm_cost","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e89c8d9b9c9b9f81868d9c8585b78b879b9ca89c8d9b9c81868f85898184c68b8785">[email protected]</a>","uid":"testswinetmm_cost"}
[12:32:39] console.log: EntroSubscribeTokenType string
[12:32:39] console.log: EntroSubscribeToken
[12:32:39] console.log: NewObject object
[12:32:39] console.log: Key: {
[12:32:39] console.log: Key: "
[12:32:39] console.log: Key: a
[12:32:39] console.log: Key: c
[12:32:39] console.log: Key: c
[12:32:39] console.log: Key: e
[12:32:39] console.log: Key: s
[12:32:39] console.log: Key: s
[12:32:39] console.log: Key: _
[12:32:39] console.log: Key: t
[12:32:39] console.log: Key: o
[12:32:39] console.log: Key: k
[12:32:39] console.log: Key: e
[12:32:39] console.log: Key: n
[12:32:39] console.log: Key: "
[12:32:39] console.log: Key: :
[12:32:39] console.log: Key: "
[12:32:39] console.log: Key: a
[12:32:39] console.log: Key: f
[12:32:39] console.log: Key: c
[12:32:39] console.log: Key: d
[12:32:39] console.log: Key: d
...
The response object has a custom type, but when trying to convert it into a JSON format, unexpected results are obtained. Can anyone shed light on how this is happening?
UPDATE
Even when attempting to stringify a string which should throw an error, creating a new object with Object.assign()
prints out as an object type, yet iterating through its properties displays each letter as a separate string - which seems illogical.
UPDATE 2 I am aware that using JSON.parse(JSON.stringify()) may not make sense in this scenario. I have tried various conversions due to discrepancies between the expected and received responses.
P.S: Although unusual, JSON.parse(JSON.stringify()) is often utilized for generating deep copies of a JSON object :)