0

I have a Node-Red Application.

A user logs in with credentials stored in a sqlite database.

Based on the information returned from the database it sets a bunch of variables for use in other flows.

flow.set('sid', userid);
flow.set('fname',forename);
flow.set('sname',surname);

However, if another user logs in at the same time, all of these variables are reset to belong to the User 2 and therefor, user 1 now has all of user 2's information.

Is there a way to set variables, so that both can exist at the same time, so that each time a user visits the application they have their own context of it?

Any help here would be appreciated

Smithy
  • 771
  • 10
  • 29

1 Answers1

2

A node-red flow has no inherent knowledge of 'who' is triggering it. That is an application level detail.

Assuming you have a way to identify the user that has triggered a flow, you can use that information to build unique context keys for them.

For example, let's say msg.req.user contains a unique id for the user. You could then do:

flow.set(msg.req.user+':sid', userid); flow.set(msg.req.user+':fname',forename); flow.set(msg.req.user+':sname',surname);

knolleary
  • 9,777
  • 2
  • 28
  • 35