Cannot get user object from Netlify Function while sending the token from Identity

I’m relatively new to Netlify Identity, so this might be something simple. I’ve read the docs and believe I understand that if I send the access token retrieved by the library in the Authorization header, the claims should be decoded and added as a user object in the context of a function. That does not seem to be happening in my case. I can see the token on the event but nothing in the context. I know I can decode the claims myself, but Im trying to follow the docs. Here is a code sample from my front end:

  let id = netlifyIdentity.currentUser()
  let token = id.token.access_token

  let response = await fetch("/.netlify/functions/addtask", {
    method: "post",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${token}`
    },
    body: JSON.stringify({
      name: this.newTaskInput
    })
  })

Site URL is https://sharp-minsky-8df774.netlify.app

Thanks!

Hey there, @bmorrisondev :wave:

Looks like this thread has been quiet for a few days. Sorry about that! Are you still encountering this issue? If you are, can you please also provide your build log?

So sorry for not responding sooner! This note got buried in my inbox. It eventually ended up working and I honestly have no idea how or why. I havent been able to replicate the issue since. If I run into this again, I’ll open another request here. Thanks for getting back to me, have a great day.

1 Like

No problem at all. Thank you for letting us know! I am glad it is working again. :netliconfetti: