Hey, I am currently building a holiday planner application in NextJS and using Auth0 for secure logins and an external database to store user information.
I am currently building the admin functions of my system to add, delete and modify users. I have been currently using the Managment API for this and just copying and pasting the token in to my header to do POST requests for creating users.
Since this token expires every 24 hours, I wanted to add in the API to get the new managment token. I am really struggling to figure out how to do it. I have been currently using this code in my /api/Admin file
I understand that you encountered issues getting a Management API token.
I have inspected your code snippet carefully and noticed that you need to use the application/json content-type rather than the application/x-www-form-urlencoded. See below for clarity:
Out of curiosity what is the other content-type (application/x-www-form-urlencoded) used for?
Also, if I wanted to just have an API for just adding, deleting and editing users, should I create a seperate API in production or is the management API okay?
edit: Unfortunately, you will not be able to create and use a separate API to read, create, update, and delete users. Instead, you must use the Management API Token to make these requests correctly. I have tested and confirmed this.
Hoped this helps!
Please let me know if there’s anything else I can do to help.
Thank you for the clarification, I am very new to the dev space so currently learning new things everyday.
One last question, I have now setup my Get Management API function, at what point is it recommended to update the token, and is this something done on the server side when the application is deployed once a day?
First, I have edited and corrected my first post. You must continue using the Management API to make requests to create, read, update, and delete users.
Additionally, the Management API Token has a default expiration time of 86400 seconds (24hours).
In this case, you will need to renew your token daily to continue usage. Note that there is an option to increase or reduce the Token Expiration.