Netlify function not parsing valid user JWT

I have a netlify function that pulls user off of clientContext. However, when I pass a valid JWT in the Authorization header, Netlify does not decrypt the JWT and provide clientContext.user. user in this case is null. I have verified both on the browser and in the function that the JWT is being sent in the Authorization header with the correct syntax. Not sure what else to do from here.

Here’s the client code:

fetch('/.netlify/functions/create-entry', {
  method: 'POST',
  body: JSON.stringify(dataObject),
  headers: {
    Authorization: `Bearer ${netlifyIdentity.currentUser().token.access_token}`,
  },
}),

Looks like I might have answered my own question. Had to change my code to the following:

fetch('/.netlify/functions/create-entry', {
  method: 'POST',
  body: JSON.stringify(dataObject),
  headers: {
    Authorization: `Bearer ${await netlifyIdentity.currentUser().jwt()}`,
  },
}),

Note that the code above was inside an async function.

1 Like

thanks for sharing your solution! That’s definitely helpful for others :slight_smile: