Node Red Password

Hello,
after several attempts it is not possible for me to protect my node red with a password. I'll send you the content of the config:

   adminAuth: {
          type: "credentials",
          users: [{
          username: "admin",
          password: "my generated Hash",
          permissions: "*"
                 }]
    },

I get the following error message:

Error loading settings file: /home/pi/.node-red/settings.js
/home/pi/.node-red/settings.js:21
users: [{
^
SyntaxError: Unexpected token :
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object. (/usr/lib/node_modules/node-red/red.js:119:20)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
nodered.service: Succeeded.

I stick to the exact descriptions on the net. But can't find my fault.

Difficult to say without the surrounding context in the settings file. Maybe a comma is missing after the last setting before adminAuth?

I've had something like this happen couple of times. Once I couldn't spot the error no matter how long I looked. I then rewrote the new part again and the issue disappeared. It might have been an invisible character somehow gotten there.

There are no further entries in the config. This is now the 3rd attempt on 2 different raspis.

Have you put the adminAuth block you are adding inside the module.exports block that starts on line 21 of the default settings file?

The fact it is complaining about line 21 suggests to me you have added this outside of the module.exports block.

If you still can't get to the solution then post the whole settings file here. Use the </> button at the top of the edit window to paste it here.
Also are you sure you are editing the right file? The node-red startup log tells you where it is.

        adminAuth: {
              type: "credentials",
              users: [{
              username: "admin",
              password: "my Hash",
              permissions: "*"
                     }]
        },

That's all that is in the settings

Here is the path:

sudo nano /home/pi/.node-red/settings.js

What happened to the original contents?

Hold on, that doesn't make sense, it is complaining about line 21 but there are not 21 lines in that file.

Edit: Did you run node-red before editing the settings file? If not then move it away and move away the flows file (if there is one) and run node red, I think that will create the basic settings file.

Also, how did you install node-red?

1 Like

Okay - so that's the issue then.

When Node-RED first runs, it copies into ~/.node-red/settings.js the default settings file for you to edit.

Delete the file you've created, run Node-RED so it can create the file, then stop Node-RED and edit the file it has created.

1 Like

That was exactly it.

I always changed the config first instead of starting node red once.

So many hours wasted and the answer was so close.

Many, many thanks for your help!

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