Can't use JWT (jsonwebtoken) in mongodb realm functions to verify

I was trying to make a API using mongodb realm functions, and I’ve correctly added/installed dependency named jsonwebtoken

exports = async function(arg){
  const jwt = require("jsonwebtoken")
  let res = jwt.verify("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiI4WEFxeWhMWEFwYUp6NmtIem51QmFwTUp0WVA0In0.XPwOjkCLR7TD0KjJtke1UwKbc-mXZQDNkClojffXXxs", "secret1")

  return res

The code above successfully returns { uid: '8XAqyhLXApaJz6kHznuBapMJtYP4' } when run normally using nodejs CLI/Interpreter.
But here it fails, I get this result

> ran at 1671900424456
> took 
> error: 
{"message":"Value is not an object: undefined","name":"TypeError"}

Plz help I’m stuck here is the screenshot of the same

There was a Issue with jsonwebtoken version 9.0.0, I’ve tried an old version 8.0.0 and it worked like charm :wink:

1 Like

If you run console.log(process.version);, you will see realm functions runs on node 10.

This isn’t supported by version 9 of jsonwebtoken. See Migration Notes: v8 to v9 · auth0/node-jsonwebtoken Wiki · GitHub