# Where should I create ManagementClient instances...or should I just create users via client? (Node / React)

**URL:** <https://community.auth0.com/t/where-should-i-create-managementclient-instances-or-should-i-just-create-users-via-client-node-react/66746>\
**Category:** Get Help\
**Tags:** nodejs, react, express\
**Created:** [July 25, 2021, 12:34pm UTC](https://community.auth0.com/t/where-should-i-create-managementclient-instances-or-should-i-just-create-users-via-client-node-react/66746 "2021-07-25T12:34:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![czbaker](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/czbaker/32/15668_2.png) [@czbaker](https://community.auth0.com/u/czbaker)\
**Post date:** [July 25, 2021, 12:34pm UTC](https://community.auth0.com/t/where-should-i-create-managementclient-instances-or-should-i-just-create-users-via-client-node-react/66746/1 "2021-07-25T12:34:28Z")

</div>

I’m working on my first **real** project using Auth0 as an identity management solution and have run into a bit of a question:

I see that when you use the NodeJS library (`auth0`) that you’re supposed to create an instance of `auth0.ManagementClient` and then use that to complete tasks via the Management API (such as manual creation of users, etc.)

That’s fine, but I also read that if you provide adequate credentials, that you can automatically generate a token to make requests with subject to expiration based on `expires_in` settings, etc.

Do I need to create a new instance of `ManagementClient` **for each request** or is it adequate to create one instance during server startup and export that to places that need it?

It seems to me (correct if wrong) that if I create one instance, then export…things will be fine up until I hit the expiration and then all of my `ManagementClient`-based reqeusts will fail due to an expired token?

I just wanted to ask here and make sure I was right in that thinking so I would know what the best practice was for creating instance(s) of `ManagentClient` before I got to writing user registration code for my new project (I am doing this using a custom form that I built using React for my frontend).

Alternatively: Should I even be doing it this way? I was under the impression that I would **need** to incorporate the Management API (via Express) to handle custom registrations, and that there wasn’t a way to do this in React itself…otherwise I wouldn’t even need to do this in Express?

I read a little bit about the [Authentication REST API](https://auth0.com/docs/api/authentication#signup) and maybe the best way to handle this is just using that API with `axios` on the client?

Thanks in advance for any advice/assistance.

I’m pretty new to Auth0 in general (it’s awesome so far!), and I can’t figure out which is the more optimal/preferred way to deal with these registration requests.

---

<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:** [July 26, 2021, 5:12pm UTC](https://community.auth0.com/t/where-should-i-create-managementclient-instances-or-should-i-just-create-users-via-client-node-react/66746/3 "2021-07-26T17:12:42Z")

</div>

Hi @czbaker,

We provide a signup endpoint. You should use this for custom signup.

> **[Custom Signup](https://auth0.com/docs/libraries/custom-signup)**
>
> How to customize the user signup form with additional fields using Lock or the Auth0 API.

You can make this request with a library like Axios, or you can use the Authentication provider in the auth0-node library. Here is the reference for doing that: [https://auth0.github.io/node-auth0/module-auth.DatabaseAuthenticator.html#signUp](https://auth0.github.io/node-auth0/module-auth.DatabaseAuthenticator.html#signUp)

Also, here is the signup endpoint for reference:

[https://auth0.com/docs/api/authentication#signup](https://auth0.com/docs/api/authentication#signup)

Let me know if you have any questions!

* * *

_Here are answers to some of you other questions, although you may not need to use this info anymore (note: you can use the management API, but the signup endpoint is probably preferred):_

> [@czbaker](#):
>
> Do I need to create a new instance of `ManagementClient` **for each request** or is it adequate to create one instance during server startup and export that to places that need it?

No, you don’t need to make a new instance every time you make a request. Using that same instance for multiple requests is okay.

> [@czbaker](#):
>
> It seems to me (correct if wrong) that if I create one instance, then export…things will be fine up until I hit the expiration and then all of my `ManagementClient` -based reqeusts will fail due to an expired token?

There are two ways to authenticate your management client against your tenant. You can provide a token to the client, **or** you can provide the client credentials, and the client will automatically request a token and handle expiration. Here is the [reference](https://auth0.slack.com/archives/C9YBNE6T0/p1627312893314200).

Providing the client id and secret (client credentials) will put the SDK in charge of requesting tokens and renewing when they expire.

---

<div class="post-metadata">

**Author:** ![czbaker](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/czbaker/32/15668_2.png) [@czbaker](https://community.auth0.com/u/czbaker)\
**Post date:** [July 29, 2021, 11:10am UTC](https://community.auth0.com/t/where-should-i-create-managementclient-instances-or-should-i-just-create-users-via-client-node-react/66746/4 "2021-07-29T11:10:57Z")

</div>

Oh, cool. I should have known that the client **probably** knew to handle token renewal when it expired so it would keep going.

I ended up going with using the signup endpoint via Axios on the client side.

Thank ya!

---

<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:** [July 29, 2021, 3:15pm UTC](https://community.auth0.com/t/where-should-i-create-managementclient-instances-or-should-i-just-create-users-via-client-node-react/66746/5 "2021-07-29T15:15:19Z")

</div>

Great! Glad that resolved it. Let me know if you have any more questions.

---

<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:** [August 13, 2021, 3:16pm UTC](https://community.auth0.com/t/where-should-i-create-managementclient-instances-or-should-i-just-create-users-via-client-node-react/66746/6 "2021-08-13T15:16:08Z")

</div>

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