Skip to content

Commit

Permalink
docs: add note about type restriction for jwt payload (#598) Thanks to
Browse files Browse the repository at this point in the history
  • Loading branch information
bnchdrff authored Apr 16, 2020
1 parent 1d36a97 commit 32e45e2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/Cube.js-Backend/Security.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ app.use((req, res, next) => {

app.get('/auth/cubejs-token', (req, res) => {
res.json({
// Take note: cubejs expects the JWT payload to contain an object!
token: jwt.sign({ u: req.user }, process.env.CUBEJS_API_SECRET, { expiresIn: '1d' })
})
})
Expand Down Expand Up @@ -107,6 +108,8 @@ For example if you want to pass user id in security context you can create token

In this case `{ "id": 42 }` object will be accessible as [USER_CONTEXT](cube#context-variables-user-context) in the Cube.js Data Schema.

The Cube.js server expects the context to be an object. If you don't provide an object as the JWT payload, you will see an error like `Cannot create proxy with a non-object as target or handler`.

Consider the following example. We want to show orders only for
customers, who owns these orders. `orders` table has a `user_id` column, which we
can use to filter the results.
Expand Down

0 comments on commit 32e45e2

Please sign in to comment.