ga-wdi-boston / game-project

Other
7 stars 102 forks source link

can't retrieve ID from 'store' for signout #848

Closed dianamcnulty closed 7 years ago

dianamcnulty commented 7 years ago

I'm able to sign in successfully, in my sign-in "then" function I successfully console.log(store) and these are the results I get in the console:

then when I select 'log-out' I know the ajax function is being invoked because I can log a message inside it, I can also log the data in 'store' which does have an id, but I can't get the id itself. If I replace "store.user.id" with the actual ID it works fine. I even tried throwing in an extra 'user' in the middle (store.user.user.id) but it still didn't work.

here's the function I'm using to make the ajax call

const logOut = function () {
  console.log('store id is', store)
  return $.ajax({
    method: 'DELETE',
    url: config.apiOrigin + '/sign-out/' + store.user.id,
    headers: {
      Authorization: 'Token token=' + store.user.token
    }
  })
}

and here's what "store" looks like in the console (it looks wonky because it what copied from chrome... sorry):

{user: {…}} user : {id: 874, email: "dianana", token: "BAhJIiVlNDQ5ODg3OTk4OTVjNTBmMTdiYmFiMmQwMzVmNzI1ZQY6BkVG--cd6076ef3667e8d05cc0dff3d8f829d55fbd872e"} proto : Object

-- and here's the function that actually writes to the store upon successful login:

const logInSuccess = function (data) {
  store.user = data.user
  console.log('logged in successfully', store)
  gameui.showGame()
}

Any ideas on what I might be doing wrong? Thanks!

dianamcnulty commented 7 years ago

I was missing a slash at the end of the API development URL Issue is resolved thanks!!