How can I get user data into a javascript object?

that’s because you have defined the variable theUser as null and overridden the one that has the object before then you have tried to call the object.

just remove this line
var theUser;