Create a user-specific dashboard Questions

Hi community,

I am new to Mongo Charts and recently built a demo dashboard , but having questions regarding the user setting.

I am currently using JWT authentication method to embed the dashboard in my nodejs application.
However, I want to create a user “filter” , which means each user can only see their own data.

I tried to refer to the documentation about the Injected User Filter , by using email to define each user,however, I am having errors 17. I wonder what is the correct setting / any demo code to use the user filter.

Please advise.

Hi @Super_Chain -

It sounds like you’re on the right track. As per the docs, error 17 means “injected filter failed to apply”. Can you share your filter function code? It should interrogate the context.token object and return a JavaScript object representing a valid MQL filter.

For example, if the user’s email address is in the sub field of the JWT token and you want to filter based on the ownerId field in your collection, the function would look like this:

function getFilter(context) {
  return { ownerId: context.token.sub };
}

Tom

2 Likes

Hey Tom !!!

Thanks for your reply !!!

Just fixed it ! Thanks for explaining the “sub” field, I wasnt know it was referring to the JWT token. I decoded the JWT token by putting the token in jwt.io and found that our payload is not using “sub” , instead using “username” , so after changing that it works perfectly !!!

Cheers!