I have an application in CubeJS which will receive a JWT with a user_id claim.
The table that contains this also has a list of ids from another table.
The idea is to use a subquery so the user can only access data containing a member of this list of IDs.
Something like
SELECT posts FROM posts
where posts.user_id IN
(
SELECT allowed_ids AS ids FROM users
WHERE user_id = '9bef1222-f1ee-4879-a60e-16e94e88df28'
)
But the issue is that I have access only to the query object from cubeJS, and I'm not sure how can I add a subquery to it.
This is an example of the code filtering only by the user_id:
cube.js
module.exports = {
queryRewrite: (query, { securityContext }) => {
query.filters.push({
member: "users.id",
operator: "equals",
values: [securityContext.user_id],
});
return query;
},
};