Auth variables access on custom resolver

Since the use of atob is deprecated (see here to see why), I am using Buffer instead to decode the JWT payload. Unfortunately, it seems that Dgraph Lambda does not support Buffer out of the box and thus you would have to deploy locally using webpack to include Buffer within the bundle. Here’s a snippet which works for me to decode the payload:

Install Buffer

yarn add buffer

Parsing token and returning the payload
Get the token from the authHeader param with const token = authHeader.value.

const parseJwt = ( token ) => {
  const base64Payload = headerValue.split('.')[1];
  const payload = base64Payload ? Buffer.from(base64Payload, 'base64') : 'No payload available!';

  return payload.toString();
}
1 Like