-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (41 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module.exports = (RED) => {
RED.plugins.registerPlugin('node-red-dashboard-2-ff-auth', {
type: 'node-red-dashboard-2',
hooks: {
onSetup: (config, req, res) => {
return {
socketio: {
path: `${config.path}/socket.io`,
withCredentials: true,
auth: {
user: req.session?.user
}
}
}
},
onAddConnectionCredentials (conn, msg) {
if (!msg._client) {
msg._client = {}
}
msg._client = { ...msg._client, ...{ user: conn.handshake.auth.user } }
return msg
},
onIsValidConnection (conn, msg) {
// check if the msg contains a specified user
// if it does, does that user match the user in the connection?
if (msg._client?.user) {
return msg._client.user.userId === conn.handshake.auth?.user?.userId
}
return true
},
onCanSaveInStore (msg) {
// check if the msg contains a specified user
// if it does, then we can't save in general data store
if (msg._client?.user) {
return false
}
return true
}
}
})
}