Use JWT in Slash Lambda Field

I am building out an app and need to return a field with true or false logic with a Lambda Field resolver. I need to return true if the JWT provided is the user.

type User {
  email: String! @id
  isSelf: Boolean @lambda
}
const decode = (jwt) => { /* ... */ }
async function isSelf({parent, authHeader}) {
  const { email } = decode(authHeader)
  return email === parent.email
}
self.addGraphQLResolvers({
    "User.isSelf": isSelf
})

This does not work though because authHeader is passed to the server but not through the addGraphQLResolver as a property.

This otherwise would be a simple feat to get this boolean field, but now, I have to do it all on client side, which means changing a front end that I am trying not to change. I am trying to just replace a custom GraphQL endpoint with Slash and hoping for an easier transition.


Other use cases: use the JWT to resolve a lambda field if the user is someone I am following or follows me. Use the JWT to see if I am the author of a post in a lambda field resolver.


cc: @gja

Thanks for pinging. I didn’t notice this one. I’ll get someone to pick it up.

Any update here? I need to access the JWT in my lambda. This is useful for a few reasons… to secure the lambda, perform custom logic using JWT claims and even to perform extended API calls to custom servers that accept the token.

@gja when do you think this can be fixed?

This was fixed yesterday, please update your lambda script ot see the changes. You now will recieve authHeader = {key: “My-Header-Name”, value: “jwt-here”} to the lambda resolver. All calls to graphql automatically pass this header back.

1 Like

I would be interested in how you guys resolve the JWT!

@Poolshark See the following post:

J