# Custom user authentication not working

**URL:** <https://discourse.nodered.org/t/custom-user-authentication-not-working/5984>\
**Category:** General\
**Created:** [20 December 2018 13:25 UTC](https://discourse.nodered.org/t/custom-user-authentication-not-working/5984 "2018-12-20T13:25:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdiegosierra](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jdiegosierra/32/6990_2.png) [@jdiegosierra](https://discourse.nodered.org/u/jdiegosierra)\
**Post date:** [20 December 2018 13:25 UTC](https://discourse.nodered.org/t/custom-user-authentication-not-working/5984/1 "2018-12-20T13:25:23Z")

</div>

I'm just trying to use [Custom user authentication](https://nodered.org/docs/security) example.

> ```
> authenticate: function(username,password) {
> return new Promise(function(resolve) {
> // Do whatever work is needed to validate the username/password
> // combination.
> if(username === "test" && password === "password") {
> valid = true;
> }
> else
> valid = false;
> if (valid) {
> console.log("Right");
> // Resolve with the user object. Equivalent to having
> // called users(username);
> var user = { username: "test", permissions: "*" };
> resolve(user);
> } else {
> // Resolve with null to indicate the username/password pair
> // were not valid.
> resolve(null);
> }
> });
> }
> 
> ```

If I write a wrong password I get this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8c96a82ca2ff44b2357d6b233b1631fbd118744e.png)

But if I write a correct password I get this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/06e3b35f19133b33a964e76ffe5c646b201c9c6b.png)

In postman I get the correct answer:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/952835ab49adace0350dda74843a54a00f9d85ff.png)  
And my browser stores the token:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0ec8ecb0ea73283191542e0095cc0c70d5a3b1ad.png)

So is like Node-RED is not storing the token...

is it a bug, or am I doing something wrong?

Thx!

---

<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:** [20 December 2018 14:21 UTC](https://discourse.nodered.org/t/custom-user-authentication-not-working/5984/2 "2018-12-20T14:21:52Z")

</div>

What does your custom auth's `users` function look like?

---

<div class="post-metadata">

**Author:** ![SutharMukesh](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@SutharMukesh](https://discourse.nodered.org/u/SutharMukesh)\
**Post date:** [12 April 2020 04:49 UTC](https://discourse.nodered.org/t/custom-user-authentication-not-working/5984/3 "2020-04-12T04:49:29Z")

</div>

just for understanding,  
what does `users` function do?

---

<div class="post-metadata">

**Author:** ![sabir](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sabir](https://discourse.nodered.org/u/sabir)\
**Post date:** [4 April 2023 06:35 UTC](https://discourse.nodered.org/t/custom-user-authentication-not-working/5984/4 "2023-04-04T06:35:52Z")

</div>

I'm going through exact same issue.  
It is mandatory to define the users function, if yes then can you please give me a look of users function and what it does??

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2023 08:09 UTC](https://discourse.nodered.org/t/custom-user-authentication-not-working/5984/5 "2023-04-04T08:09:15Z")

</div>



---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2023 08:10 UTC](https://discourse.nodered.org/t/custom-user-authentication-not-working/5984/6 "2023-04-04T08:10:10Z")

</div>

Closed this old thread (please continue on your [new thread](https://discourse.nodered.org/t/custom-auth-is-not-working/77233))
