Take a look at my code with the relevant parts highlighted:
authorization.js
while
loop is omitted, I encounter this error:Cannot read property 'toString' of undefined
This error stems from attempting to call
toString
oncurrentUser._id
while it's still undefined. My belief is that initially,Auth.getCurrentUser()
returns a reference to{}
. Upon assignment,{}
should be assigned tocurrentUser
, allowing the code to continue. However, since the response hasn't arrived yet,currentUser
cannot be updated. Therefore, I resorted to using thewhile
loop to halt execution until the response arrives. Surprisingly, the loop runs endlessly! Shouldn't the response eventually arrive, updatecurrentUser
, and turn!currentUser._id
intofalse
, breaking the loop?Initially,
factory cb
and thenuserId
get logged. Yet, the infinite loop kicks in without ever reachingloop, the success callback gets triggered and logssuccess</code/>. Doesn't asynchronous behavior dictate otherwise? How does the loop manage to interfere with the request completion? What exactly is happening here?</p> <p>The call itself isn't causing issues; sans the <code>while
success
. Furthermore, uponconsole.dir(currentUser)
inauthorization.js
, the user's info is displayed. Strangely though, usingconsole.log(currentUser)
yields an empty object. The reason behind this remains unclear.