Skip to content
Advertisement

(Bug) fetched object from server returns undefined

There is a lot of code involved in this process, so I will explain the best way possible to narrow down the problem. First, the user signs up and sends an object with other nested objects and arrays to the middleware. The middleware…

JavaScript

the console gets logged “passData returned: [object Object]”

this then gets processed into a “block” to be added to a block chain, with an array property named data that contains an object, deeper in this object eventually it contains the eccrypto https://github.com/bitchan/eccrypto public key. I need to access the public key but it keeps returning undefined (public key is almost certainly not the issue but for context).

Upon login, the user fetches the blockchain and the code narrows down the desired data depending on form input (form + processing form code may not be relevant).

I set a variable equal to field of chain[i].data[0].members[0].user which was derived by fetching the blockchain from the server (chain being the blockchain with different blocks in its indexes, after processing the targeted block it will access its data array with an object that has a “name” key and a members array where it stores all the user objects in its indexes.)

narrowed issue in login backend:

JavaScript
JavaScript

and in the decryptmes function, the debug string on line 11 returns “data returned undefined”

Important console messages:

JavaScript

notes: When I fetch the blockchain on postman, it shows that there is an object in the “members” array, how can it show up on postman but be undefined when I try printing it to console within encryptMes function or in any scope of the login function?

Postman shows:

JavaScript

as you can see, in index 0 there is the first member object indexed as 0 and its object field’s user is not undefined.

conclusion: What am I doing wrong for the object to be undefined? I hope I was able to effectively show what was relevant and any help will be greatly appreciated as I have lots to learn in JavaScript. Thank you

Below you can check out the login client backend, if you need to

login backend:

JavaScript
JavaScript

Advertisement

Answer

based on the object in the question for accessing the user should using members[0][0] so just try

JavaScript
Advertisement