# Multiple session problem

**URL:** <https://discourse.nodered.org/t/multiple-session-problem/26147>\
**Category:** Dashboard\
**Created:** [5 May 2020 23:20 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147 "2020-05-05T23:20:38Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)\
**Post date:** [5 May 2020 23:20 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/1 "2020-05-05T23:20:38Z")

</div>

hi  
I have some issuse with msg.socketid  
when send notification with msg.socketid  
all session recived this notification  
what problem its bugged or what

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [6 May 2020 05:05 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/2 "2020-05-06T05:05:57Z")

</div>

There is no multiple users "problem", as there cannot be multiple users.  
Dashboard is single user only. [See documentation](https://flows.nodered.org/node/node-red-dashboard).

> This Dashboard does NOT support multiple individual users. It is a view of the status of the underlying Node-RED flow, which itself is single user. If the state of the flow changes then all clients will get notified of that change.

> Messages coming from the dashboard **do** have a `msg.socketid` , and updates like change of tab, notifications, and audio alerts will be directed only to that session. Delete the `msg.sessionid` to send to all sessions.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [6 May 2020 05:40 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/3 "2020-05-06T05:40:04Z")

</div>

Hi @bakman2,  
Indeed the subject should be _"Multiple session problem"_. But his notification message contains a msg.socketid, so it should only show a notification popup on the dashboard session that is communicating via that socket. Now he sees the same notification on all his sessions, i.e. on all his dashboards.  
@d0d04m3: you will need to provide some more information (a.o. that part of your flow), if you want people to be able to assist you...  
Bart

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 May 2020 06:01 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/4 "2020-05-06T06:01:00Z")

</div>

Please add a debug node showing what is going into the notification node. Set it to Show Complete Message and post the result here.

---

<div class="post-metadata">

**Author:** ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)\
**Post date:** [6 May 2020 13:08 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/5 "2020-05-06T13:08:13Z")

</div>

thanks to all replay  
so  
i have tow user login in dashboard  
and every user have socket id

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d335b662f8686cddd9355cd78e86b27c26832590.png)

so i send msg to this session

![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/59f7d12a02cf1331f4eb9e2835735593e8c5273b.png)

but all session recived this msg

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/db78c7901c8bf1c2c4e8054c39ab7299d4aa6cf7.png)

and other seesion recived too

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/96707fb3e7ba420f5c6c64ef2f4deab10ada9c78.png)

how to send msg to only one session with socket.id

> Messages coming from the dashboard **do** have a `msg.socketid` , and updates like change of tab, notifications, and audio alerts will be directed only to that session. Delete the `msg.sessionid` to send to all sessions.

and it possible to hide or show button at only specified dashboard session ?  
exp when click to login only dashboard how clicked button afected not all session show event

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/1662b81262cb9ed64ea68a297ca836a02239190e.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 May 2020 13:22 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/6 "2020-05-06T13:22:46Z")

</div>

That session is "your" session that you have created.  
If you use a ui\_control node - and inspect the whole message you will see this sort of message on connect of page change  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e99989f927c64217c2c6c6362a9d69c865cdd6e.png)  
It is that socketid that is needed to be part of the msg object in order to restrict where it goes back to - so you will need to create a correspondence table between your session and this socketid.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [6 May 2020 13:24 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/7 "2020-05-06T13:24:26Z")

</div>

While I'm aware that's an industrial standard to create login systems like this, with node-red not being truly multi user you're potentially creating a security issue, in that users presented with this panel can work their way around through the websocket connection back to Node-RED. Like I said, other industrial aimed tools suffer from similar issues too, I can name a couple from the top of my mind even. But that doesn't mean new tools should still implement the same problems.  
I think you need to take back a step and figure out if you really need several users with different access levels, and if so, see if node-red-dashboard is your best solution as it does not currently offer multi-user access, and it will force you to create solutions like this.

---

<div class="post-metadata">

**Author:** ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)\
**Post date:** [6 May 2020 13:40 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/8 "2020-05-06T13:40:34Z")

</div>

> [@dceejay](#):
>
> That session is "your" session that you have created.  
> If you use a ui\_control node - and inspect the whole message you will see this sort of message on connect of page change  
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e99989f927c64217c2c6c6362a9d69c865cdd6e.png)  
> It is that socketid that is needed to be part of the msg object in order to restrict where it goes back to - so you will need to create a correspondence table between your session and this socketid.

yes i known this and Activesocketid generated from this  
but nothing work

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/00805d12eef6c7a362f138e889bcdcc19b23dab5.png)

---

<div class="post-metadata">

**Author:** ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)\
**Post date:** [6 May 2020 13:44 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/9 "2020-05-06T13:44:02Z")

</div>

> [@afelix](#):
>
> While I'm aware that's an industrial standard to create login systems like this, with node-red not being truly multi user you're potentially creating a security issue, in that users presented with this panel can work their way around through the websocket connection back to Node-RED. Like I said, other industrial aimed tools suffer from similar issues too, I can name a couple from the top of my mind even. But that doesn't mean new tools should still implement the same problems.  
> I think you need to take back a step and figure out if you really need several users with different access levels, and if so, see if node-red-dashboard is your best solution as it does not currently offer multi-user access, and it will force you to create solutions like this.

ok thanks  
but now my probleme not for multiuser  
its forward msg only to target session

---

<div class="post-metadata">

**Author:** ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)\
**Post date:** [6 May 2020 13:53 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/10 "2020-05-06T13:53:49Z")

</div>

so I need any flow exp to send msg only to session target

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [6 May 2020 13:56 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/11 "2020-05-06T13:56:53Z")

</div>

Going to this image:  
[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d335b662f8686cddd9355cd78e86b27c26832590.png) ](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d335b662f8686cddd9355cd78e86b27c26832590.png)  
I see two socket IDs listed for your sessions, as you say Session 1 and Session 2. If you follow the blue arrow back to the address bar, you see that it shows a different socket there than it has for session 1 in the data. The browser socket id does however match the Activesocketid. Which specifically are you trying to send/hoping where it would arrive?

---

<div class="post-metadata">

**Author:** ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)\
**Post date:** [6 May 2020 14:09 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/12 "2020-05-06T14:09:35Z")

</div>

no this old active session and I am missing to refresh Activesession  
and I am use the Ativesession to known how session send me data  
so probleme I send msg with socketid target but all session receved msg  
and i repeat same process with same Activesession and target session but nothing changed

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/859525afc12dfd27316872850b80bd0b15efc093.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 May 2020 18:23 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/13 "2020-05-06T18:23:14Z")

</div>

Is the "Account Login" html in a ui\_template node?

I have seen that `$scope.$watch('msg', function(msg) {` receives all messages from all sessions.

As a test, do this - add a `console.log(msg)` in $scope watch...

```auto
    $scope.$watch('msg', function(msg) {
        console.log(msg);
    })

```

...then open several sessions - you will see the msg appears in console regardless of session.

If so, then you might need to setup a `my_socketid` var (to remember your own session ID) **on the client side** (in the $scope) and ONLY show your custom Dialog if the `msg` arriving has a matching `socketid`

@dceejay is there anywhere in $scope object (or somewhere in ui\_template @ client side) of accessing the current `socketid` (without having to somehow send it and store it client side)?

---

<div class="post-metadata">

**Author:** ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)\
**Post date:** [6 May 2020 20:06 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/14 "2020-05-06T20:06:07Z")

</div>

yes I am use ui\_template

```auto
<div ng-init="init()" id="popup_dialog" class="dialog">
    
    <div class="dialog_content">
        
        <div class="dialog_header">
            <span ng-click="closeDialog()" class="close">&times;</span>
            <h2 class="title">{{payload.title}}</h2>
        </div>
        
        <div class="dialog_body">

            <div layout="column" layout-align="center" style="margin-top: 10px">
                 <h1 class="title">Username:</h1>
                 <md-input-container>
                    
                    <label >{{payload.label1}}</label>
                    <input ng-model="userInput">
                  </md-input-container>
                  <h1 class="title">Password:</h1>
                     <md-input-container>
                         
                    <label>{{payload.label2}}</label>
                    <input type="password" ng-model="passInput">
                  </md-input-container>
         
                 <div layout="row" layout-align="center">
                    <div class="btn_box">
                        <md-button class="btn" ng-click="confirm()">
                            <ng-md-icon icon="done" style="color:#fff;"></ng-md-icon> OK
                        </md-button>
                    </div>
    
                    <div class="btn_box">
                        <md-button class="btn" ng-click="closeDialog()">
                            <ng-md-icon icon="close" style="color:#fff;"></ng-md-icon> Cancel
                        </md-button>
                    </div>
                </div>
            </div> 
          
        </div> <!--dialog_body-->
    </div> <!--dialog_content-->
</div> <!--dialog-->

<style>

/* The Dialog (background) */
.dialog {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 9999; /* Sit on top */
    left: 0;
    top: 0;
    
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
    -webkit-transform: translateZ(0px);
    -webkit-transform: translate3d(0,0,0);
    -webkit-perspective: 1000;
}

.dialog_content {
    position: absolute;
    background-color: #333333;
    left: calc(50% - 170px);
    top: 30px;
    
    margin-top: 8%;
    border-radius: 10px;
    padding: 0;
    width: 340px;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
    -webkit-animation-name: animatetop;
    animation-name: animatetop;
    animation-duration: 0.4s;
}
h2.title {
    margin:10px;
    font-size: 20px;
}
h1.title {
    margin:10px;
    font-size: 15px;
}
/* Media query for smartphones (to Fix?) */
@media only screen and (min-device-width : 375px) and (max-device-width : 667px) { 
    .dialog_content {
    margin-top: 5%;
    margin-left: 5%;
}
}

/* Add Animation */
@-webkit-keyframes animatetop {
    from {top: -300px; opacity: 0} 
    to {top: 0; opacity: 1}
}

@keyframes animatetop {
    from {top: -300px; opacity: 0}
    to {top: 0; opacity: 1}
}

/* Dialog Header */
.dialog_header {
    padding: 2px 16px;
    background-color: #054649;
    border-radius: 10px 10px 0 0;
    color: #00FFFF;
}

/* Dialog Body */
.dialog_body {
    padding: 5px;
    color: #fff;
}

/* The Close Button */
.close {
    color: #fff;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: #1565C0;
    text-decoration: none;
    cursor: pointer;
}

/* Number container */
.btn_box{
    margin: 5px;
}

/* Buttons style */
.btn {
    min-height: 40px;
    min-width: 80px;
    font-weight: bold;
    margin: 0px 10px 10px 0px;
    box-shadow: 4px 4px 6px 0 #dadada;
    background-color: #054649;
    color: #fff;
}

.btn:not([disabled]):hover {
    background-color: #03A9F4;
}

</style>

<script>

/**
 * Steve-Mcl 2020-03-30
 * Adapated from the excellent work by Daniel Lando, https://github.com/robertsLando
 * to be the basis of a user input popup form
 * Original licence below...
 * *********************************************************************************
 * pin_dialog.js
 * Node-Red UI template for Node-Red Dashboard. 
 * Custom dialog that asks for a PIN to allow actions
 * Enjoy it :). 
 * -- Daniel
 *
 *
 * @license The Unlicense, http://unlicense.org/
 * @version 0.2
 * @author Daniel Lando, https://github.com/robertsLando
 * @updated 2019-03-18
 * @link ----
 * **********************************************************************************
 *
 */

var dialog;

/* ==== */
(function(scope) {
    scope.userInput = "";
    scope.passInput = "";
    scope.payload = "";
    scope.topic = "";
    scope.inited = false;
    
    scope.init = function() {
        scope.userInput = "";
        scope.passInput = "";
        //Hide the md-panel
        $('#popup_dialog').parent().parent().css("display", "none");
        dialog = $('#popup_dialog').detach();
    }
    
    scope.showDialog = function() {
        dialog.appendTo(document.body); // better to add the body only when the numpad is displayed (seams to be removed automatically)
        dialog.css("display", "block");
    }
    
    scope.closeDialog = function(){
        scope.userInput = "";
        scope.passInput = "";
        scope.payload = "";
        scope.topic = "";
        dialog.css("display", "none");
    }
    

    scope.confirm = function() {
        scope.send({topic: scope.payload.topic || scope.topic, userInput: scope.userInput, passInput: scope.passInput});
        scope.closeDialog();
    }

    scope.$watch('msg', function(data) {
        if(data && data.topic){
            switch(data.topic){
               case "show":
                   if(scope.inited){
                        scope.topic = data.topic;
                        scope.payload = data.payload;
                        scope.showDialog();
                   }
                   else
                        scope.inited = true;
                break;
                case "close": 
                    scope.closeDialog(); 
                break;
            }
        }
    });
})(scope);

</script>

```

so I inject `console.log(msg)` in $scope watch

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a9a8811774ed4bb4606ab112888526c4232caef0.png)

but cant successful add socketio into scop

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 May 2020 20:22 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/15 "2020-05-06T20:22:46Z")

</div>

Try something like this....

On node-red side, use a ui\_control to send a msg with topic "INIT" when a user connects to dashboard.  
Then in the client code, when topic == "INIT" store the socketid in $scope

Now when a msg comes in, check that the msg.socketid === $scope.socketid

This is off the top of my head so not 100% sure it'll work but give it a go.

---

<div class="post-metadata">

**Author:** ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)\
**Post date:** [6 May 2020 21:07 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/16 "2020-05-06T21:07:37Z")

</div>

i can release that id  
thanks to help

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 June 2020 21:07 UTC](https://discourse.nodered.org/t/multiple-session-problem/26147/17 "2020-06-05T21:07:43Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
