ga-wdi-boston / game-project

Other
7 stars 102 forks source link

Undefined id when updating password #160

Closed susandaiute closed 8 years ago

susandaiute commented 8 years ago

When I go to update a password I get the error: api.js:44 Uncaught TypeError: Cannot read property 'id' of undefinedupdatePassword @ api.js:44(anonymous function) @ events.js:27jQuery.event.dispatch @ jquery.js:4737elemData.handle @ jquery.js:4549 2client?cd17:25 [WDS] App updated. Recompiling...

Relevant code:


const updatePassword = (updateSuccess, failure, data) => {
console.log(app);
let form = {
  "passwords": {
    "old": data.credentials.oldpassword,
    "new": data.credentials.newpassword
  }
};
$.ajax({
  method : 'PATCH',
  url: app.api + '/change-password/' + app.user.id,
  data: form,
  headers: {
    Authorization: 'Token token=' + app.user.token,
  },
}).done(updateSuccess)
.fail(failure);
console.log('patch ran');
};

Line 44 of api.js is :

url: app.api + '/change-password/' + app.user.id,
laurenfazah commented 8 years ago

Hmm what changed from where it was? Is the user object no longer defined? Did something change in setting that on login?

susandaiute commented 8 years ago

I'm not sure. The same thing happens when I go to sign out as well.

laurenfazah commented 8 years ago

What's printing to the console from where console.log(app) is at the top of the function block?

susandaiute commented 8 years ago

I'm not seeing anything printed actually.

laurenfazah commented 8 years ago

Is this function in app.js at line 44? If not, where is it?

susandaiute commented 8 years ago

Sorry, which function? updatePassword?

laurenfazah commented 8 years ago

Yeah

susandaiute commented 8 years ago

It's in api.js, but begins at line 34. Line 44 is:


url: app.api + '/change-password/' + app.user.id,
laurenfazah commented 8 years ago

So the error is saying that user right there is undefined. Also, if that line is being run, the console.log(app) should have fired. Can you double check your browser's console for that log?

susandaiute commented 8 years ago

Sure!

susandaiute commented 8 years ago

I'm not seeing it. From refreshing the page to trying to update password and then sign out, the console reads:

Navigated to http://localhost:8080/ events.js:12 Object {credentials: Object} ui.js:20 Object {user: Object} api.js:35 Object {api: "http://tic-tac-toe.wdibos.com"} api.js:44 Uncaught TypeError: Cannot read property 'id' of undefinedupdatePassword @ api.js:44(anonymous function) @ events.js:27jQuery.event.dispatch @ jquery.js:4737elemData.handle @ jquery.js:4549 api.js:26 Uncaught TypeError: Cannot read property 'id' of undefinedsignOut @ api.js:26(anonymous function) @ events.js:22jQuery.event.dispatch @ jquery.js:4737elemData.handle @ jquery.js:4549

laurenfazah commented 8 years ago

Is this your browser's console? Not the grunt console in your terminal, right?

Could you try again, but add a debugger after that console.log(app) line?

susandaiute commented 8 years ago

It is indeed the browser console. I'll add the debugger.

susandaiute commented 8 years ago

When I hove over app, I get: "http://tic-tac-toe.wdibos.com" user : Object email : "susan@gmail.com" id : 418 token : "954244701a34c2c9694614b8dac7e9c1" proto : Object proto : Object

laurenfazah commented 8 years ago

Hmmmmmmmm....

laurenfazah commented 8 years ago

Are there any linter errors? Could something somewhere else in the code be throwing this off?

susandaiute commented 8 years ago

The only one is in ui.js that says data is defined but never used, line 10.

const signOutSuccess = (data) => {          //this is line 10
  app.user = null;
  console.log(app);
};
laurenfazah commented 8 years ago

Hmm, okay. This is really strange. @J-Weeks or @RDegnen, if you're still up, do you have any idea? This was working and looked exactly like this when I saw it a couple of hours ago, and she's seeing the app.user.id defined when using the debugger now...

susandaiute commented 8 years ago

It broke at some point during my commute which I think makes this the MBTA's fault.

laurenfazah commented 8 years ago

Hah. They're great for devastatingly ruining things. How much would you lose by rolling back to your latest commit if you had to?

susandaiute commented 8 years ago

Nothing. I just turned my computer on

susandaiute commented 8 years ago

Should I hard reset?

laurenfazah commented 8 years ago

Oh, nothing at all has changed? Then maybe try quitting (ctrl+c) your grunt server and restarting...

susandaiute commented 8 years ago

ughhhh it worked!!!!!!

laurenfazah commented 8 years ago

Hahahahahaha oh man

susandaiute commented 8 years ago

gg! thanks lauren!!!!!