Can one write a function for the `users` parameter in adminAuth section for the settings.js?

Would a function actually work when trying to log into node-red admin ui:

 adminAuth: {
           type: "credentials",
           users: function() {
             const creds = require("fs").readFileSync('/run/secrets/nodered-credentials', 'utf-8').split('\n')
             console.log(creds)
             let users = []
             creds.forEach(usercreds => {
               users.push(
                 {
                   username: usercreds.toString().slice(0, usercreds.indexOf(':')),
                   password: usercreds.toString().slice(usercreds.indexOf(':') + 1).replace("$2y","$2b"),
                   permissions: "*"
                 }
               )
             })
             return users
           }
        },

The value under /run/secrets/nodered-credentials is an htpasswd something that looks like:

admin:$2y$08$x9dYJIaLtdGXFydW2AL9s.YodrBDT3QxYHTcOliBuYSBPAUfHGpjO

At the moment in my settings.js file I can console log the values but I cannot log myself in

The console log for users

secure_nodered  | [
secure_nodered  |   {
secure_nodered  |     username: 'admin',
secure_nodered  |     password: '$2b$08$x9dYJIaLtdGXFydW2AL9s.YodrBDT3QxYHTcOliBuYSBPAUfHGpjO',
secure_nodered  |     permissions: '*'
secure_nodered  |   }
secure_nodered  | ]

Hi!
Are you aware of this documentation?

Yes, it does - when setup accordingly.

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