K
Kinde3w ago
IsaacT

How to Get and Delete Users in Kinde Using a Backend Web Application (Next.js + Kinde Provider)

Hello guys. I built a NextJs app with a Kinde provider for an authentication. Now on Kinde I created an Application using Back-end web. I am implementing a functionality to delete user from Kinde, and how could I get user from here after creating a Back-end web application. Sources I get on Kinde is related to applications created with Machine-to-Machine. I need your support here.
5 Replies
Patrick Cahulao
Hi Isaac, You can manage users in your Next.js backend by calling the Kinde Management API with an M2M token. Here’s a streamlined approach: 1. Create an M2M App - In Kinde Dashboard → Settings → Applications, add a Machine-to-Machine app. - Note its Client ID and Client Secret. 2. Grant the Right Scopes - In that M2M app’s settings, enable the Management API and add users:read and users:delete scopes. 3. Get an M2M Token
POST https://<your-subdomain>.kinde.com/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
&client_id=<M2M_CLIENT_ID>
&client_secret=<M2M_CLIENT_SECRET>
&audience=https://<your-subdomain>.kinde.com/api/v1

POST https://<your-subdomain>.kinde.com/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
&client_id=<M2M_CLIENT_ID>
&client_secret=<M2M_CLIENT_SECRET>
&audience=https://<your-subdomain>.kinde.com/api/v1

4. List Users
GET https://<your-subdomain>.kinde.com/api/v1/users
Authorization: Bearer <ACCESS_TOKEN>

GET https://<your-subdomain>.kinde.com/api/v1/users
Authorization: Bearer <ACCESS_TOKEN>

5. Delete a User
DELETE https://<your-subdomain>.kinde.com/api/v1/users/{user_id}
Authorization: Bearer <ACCESS_TOKEN>

DELETE https://<your-subdomain>.kinde.com/api/v1/users/{user_id}
Authorization: Bearer <ACCESS_TOKEN>

Use these raw URLs in your Next.js API routes to fetch and delete users as needed.
Let me know if you need sample code or run into any issues
IsaacT
IsaacTOP3w ago
Thank you very much. But my question was rather than creating an M2M application first, I did create a backend web application. So my list of users are inside the backend web application. How do I now fetch users? if it were an M2M application I would have done it in the way you stated above, but how about for this?
No description
IkiTg07
IkiTg073w ago
Hello, so you can’t use the NextJs SDK to retrieve and delete your users in kinde you have to go with M2M. To make it easier Kinde have a package @kinde/management-api-js that helps you do that and much more See here: https://docs.kinde.com/developer-tools/kinde-api/connect-to-kinde-api/
Kinde docs
Set up Kinde Management API access
Our developer tools provide everything you need to get started with Kinde.
IsaacT
IsaacTOP3w ago
Problem solved. Thank you very much! I just created M2M application and proceed with the api.
Patrick Cahulao
Hi Isaac, Glad to hear the issue is resolved. If you need assistance with anything else, feel free to reach out.
Have a great day

Did you find this page helpful?