# Cannot login user after creating user

**URL:** <https://community.auth0.com/t/cannot-login-user-after-creating-user/92495>\
**Category:** Get Help\
**Tags:** api, management-api, login\
**Created:** [October 17, 2022, 1:09am UTC](https://community.auth0.com/t/cannot-login-user-after-creating-user/92495 "2022-10-17T01:09:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![havuser52](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/havuser52/32/33258_2.png) [@havuser52](https://community.auth0.com/u/havuser52)\
**Post date:** [October 17, 2022, 1:09am UTC](https://community.auth0.com/t/cannot-login-user-after-creating-user/92495/1 "2022-10-17T01:09:51Z")

</div>

Hi there,

I’m trying to add auto-login to my application using the Resource Owner Password Flow.

I have already added custom registration with the API, first retrieving a token and then creating the new user.

When the new user have been created, I want to automatically login. This request keep giving me the error:

```auto
 {
  error: 'invalid_scope',
  error_description: 'User is not authorized to the audience for those scopes'
}

```

And this is the code for the request:

```auto
const loginOptions = {
  method: 'POST',
  headers: {'content-type': 'application/x-www-form-urlencoded'},
  body: new URLSearchParams({
    grant_type: 'password',
    username: req.body.email,
    email: req.body.email,
    password: req.body.password,
    audience: `${process.env.AUTH0_ISSUER_BASE_URL}/api/v2/`,
    scope: 'read:users',
    client_id: process.env.AUTH0_CLIENT_ID,
    client_secret: process.env.AUTH0_CLIENT_SECRET,
  })
};

const loginResponse = await fetch(`${process.env.AUTH0_ISSUER_BASE_URL}/oauth/token`, loginOptions)
const loginResult = await loginResponse.json()

console.log(loginResult);

```

I have added the grant type Password for the Application (in Advanced Settings).

I have also added all Permissions in the Management API → Machine To Machine Applications.

I’m out of ideas, anyone else have one?

Thank you!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 27, 2022, 6:41pm UTC](https://community.auth0.com/t/cannot-login-user-after-creating-user/92495/3 "2022-10-27T18:41:34Z")

</div>

Hi @havuser52,

Have you read through this thread?

> [@Management API get token throws "User is not authorized to the audience for those scopes"](https://community.auth0.com/t/management-api-get-token-throws-user-is-not-authorized-to-the-audience-for-those-scopes/37001):
>
> I have to call the Management API from one of our services. The first question is, can we use password grant to get tokens for Management API? Though I have been successful in authenticating and getting token back for Management API using password credentials, I have used the client id and client secret from a regular Web Application and not an M2M account. But when I try to get the access token with “read:users” scope using a username/password and client id/secret from the Web App, it throws U…

If that doesn’t answer it for you, you can DM me your tenant name and I will take a look. Thanks.

---

<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:** [November 28, 2022, 8:54pm UTC](https://community.auth0.com/t/cannot-login-user-after-creating-user/92495/4 "2022-11-28T20:54:56Z")

</div>

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