# Get the username connected to the dashboard

**URL:** <https://discourse.nodered.org/t/get-the-username-connected-to-the-dashboard/97574>\
**Category:** Dashboard\
**Created:** [12 June 2025 11:44 UTC](https://discourse.nodered.org/t/get-the-username-connected-to-the-dashboard/97574 "2025-06-12T11:44:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonirzi](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@Jonirzi](https://discourse.nodered.org/u/Jonirzi)\
**Post date:** [12 June 2025 11:44 UTC](https://discourse.nodered.org/t/get-the-username-connected-to-the-dashboard/97574/1 "2025-06-12T11:44:49Z")

</div>

Hi,

I have secured the acces of Node RED by setting up nginx. Then, i wanted to know the username of the person connected to the dashboard. So i added a middleware to the settings.js file. The code is below

```auto
	dashboard: {
		middleware: (request, response, next) => {
		const Username = request.headers['x-auth-user'];		
		console.log(Username);
		next()
		
		} 

},

```

When i connect to the dashboard, i get the username write in the console, as you can see below.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f948edbc1b08c080ecb3d196e13185c7fb67e30c.png)

Now i want to get the username to the node red flows, but i don't know how to do it. I tried to use functionGlobalContext, but i figured that the list just update at the launch of node red. So when another user connect to the dashboard, the variable doesn't get refresh, and the variable in node red says "undefined".

Is there a way to store the current username in a global (or flow) variable, and have it automatically update whenever a new user connects to the dashboard?

Thanks already for your help !

---

<div class="post-metadata">

**Author:** ![Jonirzi](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@Jonirzi](https://discourse.nodered.org/u/Jonirzi)\
**Post date:** [12 June 2025 13:26 UTC](https://discourse.nodered.org/t/get-the-username-connected-to-the-dashboard/97574/2 "2025-06-12T13:26:39Z")

</div>

I find how you can do it. You need to set the username as variable of the settings.js file like this

```auto
let Username = 'bonjour';

```

and the you need to modify the middleware of the dashboard, like this

```auto
	dashboard: {
		middleware: (request, response, next) => {
		Username = request.headers['x-auth-user'];		
		console.log(Username);
		next()
		
		} 
},

```

and finally you need to create a function that return the Username like this

```auto
	functionGlobalContext: {
	getUsername: () =>{
	return Username;
	},
},

```

Then in node red you just need to call the function in a function node like this to get the username.

```auto
const globalFunction = global.get('getUsername');
const username = globalFunction();

```

Hope it can helps !

---

<div class="post-metadata">

**Author:** ![Aaqu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aaqu/32/101407_2.png) [@Aaqu](https://discourse.nodered.org/u/Aaqu)\
**Post date:** [12 June 2025 14:03 UTC](https://discourse.nodered.org/t/get-the-username-connected-to-the-dashboard/97574/3 "2025-06-12T14:03:43Z")

</div>

I'm trying to get a guest in a slightly different way, but I don't know if it's good. Maybe the code from the description will give you some hints. Note: it completely blocks the dashboard if there is no user, this may be undesirable.

[@aaqu/node-red-dashboard-2-portal-auth - npm](https://www.npmjs.com/package/@aaqu/node-red-dashboard-2-portal-auth)

---

<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:** [26 June 2025 14:04 UTC](https://discourse.nodered.org/t/get-the-username-connected-to-the-dashboard/97574/4 "2025-06-26T14:04:23Z")

</div>

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