Skip to content

Commit 32e45e2

Browse files
authored
docs: add note about type restriction for jwt payload (#598) Thanks to @bnchdrff!
1 parent 1d36a97 commit 32e45e2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

docs/Cube.js-Backend/Security.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ app.use((req, res, next) => {
7474

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

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

111+
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`.
112+
110113
Consider the following example. We want to show orders only for
111114
customers, who owns these orders. `orders` table has a `user_id` column, which we
112115
can use to filter the results.

0 commit comments

Comments
 (0)