# Invalid token error when trying to login node-red

**URL:** <https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845>\
**Category:** General\
**Created:** [10 July 2020 11:52 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845 "2020-07-10T11:52:19Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![faisalchishti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/faisalchishti/32/18445_2.png) [@faisalchishti](https://discourse.nodered.org/u/faisalchishti)\
**Post date:** [10 July 2020 11:52 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/1 "2020-07-10T11:52:19Z")

</div>

**Node-RED:** v1.0.6  
**Node:** v10.20.1  
**OS:** Linux xxxxxxxx 3.10.0-514.10.2.el7.x86\_64 #1 SMP Thu Mar 2 11:35:29 PST 2017 x86\_64 x86\_64 x86\_64 GNU/Linux

It is worthwhile to note that I am using Docker and persisting node-red data in /data directory. i.e. The settings.js and other files are on the host (/data directory - which is mounted to node-red container /data).

**Some background:** We make use of Node-RED to create backend APIs for one of our web applications i.e. Node-RED is the backend for our Angular app.

I am able to set up auth using bcrypt and adminAuth setting in the **settings.js** file. I can login to Node-RED here. Now I want to push these changes to multiple other servers.

I do a `docker commit` for the image and push the data from the volume (/data) in the form of a `tar` and push it to a registry. This image is extracted by other hosts that sort out the volume using the `entrypoint` of the docker image.

**Problem:** While the login works for the host where I set it up, it does not work for the other servers where I pushed the node-red containers.

I get below error in trace:

> 10/07/2020 17:05:3510 Jul 11:35:35 - [audit] {"event":"auth.invalid-token","level":98,"timestamp":1594380935483}
> 
> 10/07/2020 17:06:1110 Jul 11:36:11 - [audit] {"event":"auth.login.fail.credentials","username":"admin","client":"node-red-editor","scope":"","level":98,"timestamp":1594380971194}
> 
> 10/07/2020 17:10:0210 Jul 11:40:02 - [audit] {"event":"auth.invalid-token","level":98,"timestamp":1594381202139}
> 
> 10/07/2020 17:19:4010 Jul 11:49:40 - [audit] {"event":"auth.login","username":"admin","client":"node-red-editor","scope":"\*","level":98,"timestamp":1594381780401}

I do not get a 'Login failed' message. It just attempts to log in and then comes back to login screen.

---

<div class="post-metadata">

**Author:** ![faisalchishti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/faisalchishti/32/18445_2.png) [@faisalchishti](https://discourse.nodered.org/u/faisalchishti)\
**Post date:** [11 July 2020 08:03 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/3 "2020-07-11T08:03:35Z")

</div>

**UPDATE:** I tried to change the auth from hardcoded value to custom authentication. It seems like a token issue. Here a the errors from my custom login:

> 11/07/2020 13:27:0611 Jul 07:57:06 - [audit] {"event":"auth.invalid-token","level":98,"timestamp":1594454226435}  
> 11/07/2020 13:27:17Logged In **// This is a custom message from my custom login**  
> 11/07/2020 13:27:1711 Jul 07:57:17 - [audit] {"event":"auth.login","username":"123456789","client":"node-red-editor","scope":"\*","level":98,"timestamp":1594454237413}

I am guessing it has something to do with getting or storing tokens. Any help with this appreciated.

The UI does not display any error at the Login screen. It just appears to attempt to login and gets back to login screen.

---

<div class="post-metadata">

**Author:** ![avinashchuahan](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@avinashchuahan](https://discourse.nodered.org/u/avinashchuahan)\
**Post date:** [15 July 2020 08:10 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/4 "2020-07-15T08:10:28Z")

</div>

I am also facing same kind of problem.Have you found any solution so far?

---

<div class="post-metadata">

**Author:** ![faisalchishti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/faisalchishti/32/18445_2.png) [@faisalchishti](https://discourse.nodered.org/u/faisalchishti)\
**Post date:** [15 July 2020 19:19 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/5 "2020-07-15T19:19:01Z")

</div>

I did manage to identify the issue. In my case, we were pushing the images to multiple servers that were load balanced using HAProxy. So, when we attempt to login Node-RED, it autheticates, saves the session in a file on the filesystem, then does a get call to retrieve the session. Since we have it load balance in round-robin fashion, the get request goes to the next available server (where i cannot find the session). So in this case, one solution is to enable sticky sessions on HAProxy using cookies.

---

<div class="post-metadata">

**Author:** ![avinashchuahan](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@avinashchuahan](https://discourse.nodered.org/u/avinashchuahan)\
**Post date:** [16 July 2020 07:52 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/6 "2020-07-16T07:52:11Z")

</div>

Hi,  
thanks for the response . I will have to figure out my problem.It looks different with same error message.

---

<div class="post-metadata">

**Author:** ![faisalchishti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/faisalchishti/32/18445_2.png) [@faisalchishti](https://discourse.nodered.org/u/faisalchishti)\
**Post date:** [16 July 2020 08:35 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/7 "2020-07-16T08:35:53Z")

</div>

Are you sure you’ve updated the right settings file? Are file system permissions for the node-red user correct? Does the .sessions.json file get updated when you attempt logging in?

---

<div class="post-metadata">

**Author:** ![avinashchuahan](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@avinashchuahan](https://discourse.nodered.org/u/avinashchuahan)\
**Post date:** [16 July 2020 09:08 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/8 "2020-07-16T09:08:54Z")

</div>

=\>Below id the index file of my NODE-RED Application

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/9661916f66efbcb68b565329012e1b0cfff75964.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/9/e96119189359b6c22b9bd89d151bbdcf21cc331d.png)

Please check if that helps.

---

<div class="post-metadata">

**Author:** ![avinashchuahan](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@avinashchuahan](https://discourse.nodered.org/u/avinashchuahan)\
**Post date:** [16 July 2020 09:09 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/9 "2020-07-16T09:09:40Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/867d14bd17f9b4a5b2aa469593c99fdd1c432cb1.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [16 July 2020 09:15 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/10 "2020-07-16T09:15:17Z")

</div>

@avinashchuahan pasting lots of screenshots of code does not help.

I can now see you are doing this on IBM Cloud - I've already responded to your other thread with some questions for you to answer.

To save me having to do a line-by-line comparison, have you modified this code at all from what the IBM Cloud Node-RED starter kits gives you to begin with?

---

<div class="post-metadata">

**Author:** ![avinashchuahan](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@avinashchuahan](https://discourse.nodered.org/u/avinashchuahan)\
**Post date:** [16 July 2020 09:23 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/11 "2020-07-16T09:23:21Z")

</div>

I have not done any modification to this file.I tried restarting the node-red Application and saw the logs.  
Everything looks fine.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/079f055c1af9be66c6dfe2bc3fd7c573125a381c.png)  
It's like when I am giving the Login credential problem arises.  
thanks

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [16 July 2020 09:25 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/12 "2020-07-16T09:25:18Z")

</div>

And have you set the `NODE_RED_USERNAME` and `NODE_RED_PASSWORD` environment variables, or are you using the credentials you provided to the setup screens you were shown when you first accessed the application?

---

<div class="post-metadata">

**Author:** ![avinashchuahan](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@avinashchuahan](https://discourse.nodered.org/u/avinashchuahan)\
**Post date:** [16 July 2020 09:27 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/13 "2020-07-16T09:27:14Z")

</div>

I have not used environment variable.It's the same way I provided during setup.

---

<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:** [30 July 2020 09:27 UTC](https://discourse.nodered.org/t/invalid-token-error-when-trying-to-login-node-red/29845/14 "2020-07-30T09:27:16Z")

</div>

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