Creating Login For A Node

I was trying to create a login mechanism for my node. I followed the below page from official documentation.
https://nodered.org/docs/creating-nodes/credentials
But the values are not appearing in the run time. My node is an output category node. From the other nodes available I have seen all of the nodes that uses credential are type of config nodes. Is it must to make the node as config node?
My code snippet

Html file

<script type="text/x-red" data-template-name="out node">
	....................
       .......................
	<div class="form-row">
        <label for="node-config-input-user"><i class="fa fa-user"></i> User name</label>
        <input type="text" id="node-config-input-user" placeholder="user">
	</div>
	<div class="form-row">
        <label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
        <input type="password" id="node-config-input-password" placeholder="password">
    </div>
    ......................
    .......................
</script>
<script type="text/javascript">
	RED.nodes.registerType('out node', {
		category: 'output',
		defaults: {
			.............................
		        .............................
		},
		credentials: {
            user: {type: "text"},
            password: {type: "password"}
        },
		color: .......................,
		.....................................
		label: function() {..............
         }
		oneditprepare: function() {...........
        });

js file


 module.exports = function (RED) {
    "use strict";
function OutNode(config) {
        var node = this;
        var statusVal;
        RED.nodes.createNode(this, config);
        console.log("this " + JSON.stringify(this));
        console.log("config " + JSON.stringify(config));
        console.log("node " + JSON.stringify(node));
        var credentials = this.credentials;
        console.log("Credentials " + JSON.stringify(credentials));
        user = "";
        password = "";
        if(credentials){
            var user = credentials.user;
            var password = credentials.password;
        }
        console.log("User " + user);
        console.log("Password " + password)
       ..........................................................
       ..........................................................
   },
  RED.nodes.registerType("out node",OutNode,{
            credentials: {
            user: {type:"text"},
            password: {type:"password"}
        }
    });
};

In console output I am getting an credentials as empty.

As you are not creating a Configuration node, then the id fields in the html should be node-input-user and node-input-password.

1 Like

Thanks :slight_smile: Now it works fine.