# How to login user from nodejs

**URL:** <https://community.auth0.com/t/how-to-login-user-from-nodejs/65609>\
**Category:** Get Help\
**Tags:** rules, management-api, login, auth0\
**Created:** [July 5, 2021, 3:28pm UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609 "2021-07-05T15:28:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![alihaider](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alihaider/32/13075_2.png) [@alihaider](https://community.auth0.com/u/alihaider)\
**Post date:** [July 5, 2021, 3:28pm UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609/1 "2021-07-05T15:28:44Z")

</div>

i have created user using this api.

var options = {

```
method: "POST",

url: "https://domail.auth0.com/api/v2/users",

headers: {

  "content-type": "application/json",

  authorization: `Bearer ${token}`,

},

data: {

  email: "abc@example.com",

  password: "abc123",

  name: "test",

  connection: "Username-Password-Authentication",

},

```

};

axios

```
.request(options)

.then(function (response) {

  console.log(response.data);

})

.catch(function (error) {

  console.error(error.response.data);

});

```

now i want login this user using api, is there any way to authenticate this user via nodejs app.?

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [July 6, 2021, 1:06pm UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609/2 "2021-07-06T13:06:53Z")

</div>

Hi @alihaider

You can use ROPG (Resource Owner Password Grant), but note that this is not recommended.

Why do you want to log a user in via API?

John

---

<div class="post-metadata">

**Author:** ![alihaider](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alihaider/32/13075_2.png) [@alihaider](https://community.auth0.com/u/alihaider)\
**Post date:** [July 8, 2021, 3:37am UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609/3 "2021-07-08T03:37:47Z")

</div>

hello @john.gateley  
in my scenario have to get username & password using postman.  
than get these credentials in express app and make a call to auth0 server to authenticate this user.

in response want to set access\_token & refresh\_token in cookies and send response object to postman including userinfo with role details

postman —\> express server —\> auth0

response: {  
name: “abc”,  
role: "superadmin ",  
email: “[abc@g.com](mailto:abc@g.com)”,  
userid: “auth|dsfdsfdsfdsf”  
}

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [July 8, 2021, 1:00pm UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609/4 "2021-07-08T13:00:00Z")

</div>

Hi @alihaider

I don’t think putting user credentials in postman is a good idea.

A better approach (not great, but better) would be to make an app to sign the user in, and have the app expose the access token for postman.

John

---

<div class="post-metadata">

**Author:** ![alihaider](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alihaider/32/13075_2.png) [@alihaider](https://community.auth0.com/u/alihaider)\
**Post date:** [July 9, 2021, 6:10am UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609/5 "2021-07-09T06:10:41Z")

</div>

thanks john.  
but my application flow is  
 → frontend (flutter mobile app)  
 → backend nodejs (express)

there are different roles like super\_admin, restaurant\_owner, restaurant\_manager, restaurant\_staff.

i have to authenticate all actors from auth0 server via express login api that will request to auth0 server and return access\_token n refresh\_token.  
using express return will set these tokens to cookies, after that we have to authorize all request to access express other apis.

there is any way to do this using auth0.

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [July 9, 2021, 1:46pm UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609/6 "2021-07-09T13:46:33Z")

</div>

Hi @alihaider

There are many drawbacks to the approach you are taking. You can do it, via ROPG, but there are many security issues with it.

Instead, you should use the Auth Code + PKCE flow, have the front end redirect to Auth0 for authentication, etc. This is the Industry Standard approach.

John

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 12, 2021, 9:38am UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609/7 "2021-07-12T09:38:13Z")

</div>

Thanks for helping with this one John!

---

<div class="post-metadata">

**Author:** ![alihaider](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alihaider/32/13075_2.png) [@alihaider](https://community.auth0.com/u/alihaider)\
**Post date:** [July 13, 2021, 4:18am UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609/8 "2021-07-13T04:18:15Z")

</div>

thanks for the help.

i have a question what would be the flow for this authentication?  
backend: Express server.  
frontend: Reactapp, android app & ios app.

i want to authenticate users from all plate forms using auth0 universal login.  
what would be the flow?

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [July 13, 2021, 1:04pm UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609/9 "2021-07-13T13:04:28Z")

</div>

Hi @alihaider

If the front end also calls other APIs than the backend, then use Auth Code + PKCE.  
If the front end is ONLY communicating with the backend, then you can use Auth Code.

John

---

<div class="post-metadata">

**Author:** ![alihaider](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alihaider/32/13075_2.png) [@alihaider](https://community.auth0.com/u/alihaider)\
**Post date:** [July 14, 2021, 6:09pm UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609/11 "2021-07-14T18:09:11Z")

</div>

all is good at local host but after deployment /login not redirecting toward the Auth0 universal login.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 29, 2021, 6:09pm UTC](https://community.auth0.com/t/how-to-login-user-from-nodejs/65609/12 "2021-07-29T18:09:14Z")

</div>

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