Allow user to delete their account (nextjs)
Good afternoon everyone! I am using Kinde in my nextjs app to handle user authentication; I am wondering if there is a way for their account to be deleted on Kinde when they click on the "delete my account" button in my app? The desired behaviour is what when they click on the button, their account is deleted and then they are redirected to the landing page. The login link and register link are so simple to integrate so i was wondering if there is someething similar for allowing a user to delete their account that wouldnt require me to delete it through the admin view on the kinde website? Any tips on this or what the recommended workflow would be? Thanks for a great product.
7 Replies
Hi @Big John,
Thanks for reaching out and elaborating on your request.
You can achieve this through the Delete User API call.
Please let me know if you have any other questions.
Hey Oli, thanks for your detailed response! I must have missed that API call in the docs, my bad.
No worries at all, we are here to help any questions you have.
Please don't hesitate to reach out again if you have any other questions.
Good afternoon @Oli - Kinde Oli or good morning depending on when you read this, I have gone through the steps of obtaining an API key and I have got this working so far. The issue I am facing is that I get an unauthorized erorr when I try to hit any of the endpoints which require an API key. I have two apps under one business on Kinde (one which is for my nextjs app and one m2m app for getting the api token). I am calling the api endpoint to get a token using my m2m credentials and the token is coming back however when i try to use that token to make an api request to get the users of my nextjs application (again this application is under the same lesson plan, i get the unauthorized error). I have set up an environment locally of an endpoint i can hit via postman to get a token and make an api call with that token. Perhaps I am not understanding the connection of how to use the api key correctly with my app, so any clarificiation in that regard would be massively appreciated. I have attached relevant screenshots of that local endpoint i have set up for testing this so you can see what i mean. Thanks for any help you can provide and let me know if you need any other info ofrom my end to help solve this. 🙂
![No description](https://cdn.answeroverflow.com/1182414966075175032/Screenshot_2023-12-07_200938.png)
![No description](https://cdn.answeroverflow.com/1182414966540746804/Screenshot_2023-12-07_200902.png)
![No description](https://cdn.answeroverflow.com/1182414966939209828/Screenshot_2023-12-07_200638.png)
Hey @Big John,
t sounds like you're doing everything right, but let's go through the steps again to make sure nothing was missed.
1. You've created a Machine to Machine (M2M) application in Kinde and obtained the
client_id
and client_secret
for this application.
2. You're using these credentials to call the /oauth2/token
endpoint and obtain an access token. This is done by sending a POST request with the following parameters:
3. You're then using the access token you received to make a request to the /api/v1/users
endpoint. The access token should be included in the Authorization
header of your request, like so:
If you're doing all of this and still getting an unauthorized error, there might be a few things going wrong:
- The client_id
and client_secret
you're using to obtain the access token might be incorrect. Double-check these in your Kinde dashboard.
- The audience
parameter in your token request might be incorrect. It should be https://<your_subdomain>.kinde.com/api
.
- The access token might not be included correctly in your request to the /api/v1/users
endpoint. Make sure it's being sent in the Authorization
header and is prefixed with Bearer
.
If you're still having trouble after checking these things, please let me know and we can troubleshoot further!Hey @Oli - Kinde , thanks for your detailed response regarding this problem. After following your steps, everything is now working - it was just a case of me not including the audience parameter in the post request for the credentials. I think the confusion was coming down to the fact I was getting a token back without the audience paramter, it was just a case of this token not working when I actually try to use it to make a request, but now with the audience parameter, the token is working. (At least that is how I am interpreting the behaviour of the code now). Anyway, thanks so much for your help! it is really appreciated
No worries and thanks for explaining what you did to fix your issue. If anyone else has a similar I know what to suggest to hopefully fix their issue.
Please don't hesitate to reach out if you come across anymore issue or have any other questions.