Hello.
I want the user to be able to delete his/her account, but I'm not sure how I should do this. I'm trying to add a public method to the AccountController that is similar to the logout method. But the class does'nt implement a appservice interface, so the method is not visible in the api. How can I make this method visible? Do I need to sign out the user before I delete the record from db? Or how is the best way to do this?
7 Answer(s)
-
0
But the class does'nt implement a appservice interface, so the method is not visible in the api. How can I make this method visible?
Swagger needs a HTTP method and a route, so add [HttpPost] and [Route] attributes.
Do I need to sign out the user before I delete the record from db?
Yes, otherwise the browser will attempt to use the invalid cookie and then get an error.
Or how is the best way to do this?
Do this:
[HttpPost] [Route(nameof(DeleteMe))] public async Task<RedirectToActionResult> DeleteMe() { await _signInManager.SignOutAsync(); var user = await _userManager.GetUserByIdAsync(AbpSession.UserId.Value); await _userManager.DeleteAsync(user); return RedirectToAction("Login"); }
More info:
- You need to cascade soft deletes yourself.
- You may want to disable soft delete.
-
0
I have copied your code into the AccountController class, but it still not shows in AppAuthService. It is only logout that is available. And the logout method is not marked with [HttpPost] or [Route] attributes. I have run the refresh.bat file but with no luck :?
-
0
Hi @affern, why don't use AccountAppService instead of AccountController? What is your project type? Angular or mvc?
-
0
<cite>alirizaadiyahsi: </cite> Hi @affern, why don't use AccountAppService instead of AccountController? What is your project type? Angular or mvc?
My project type is Angular. Maybe I can use AccountAppService. But I don't think it works to redirect to login in Angular after I have deleted the user. I tried to put the DeleteMe method in my own service and do the redirect in Angular after, but I did'nt get it to work. The AccountAppService can't return RedirectToAction result, so how do you solve this?
-
0
Hi @affern,
If you use app service approach, then you can remove the auth token on angular client and then reload the page using regular javascript.
You can check logout method of angular app to remove token.
-
0
<cite>ismcagdas: </cite> Hi @affern,
If you use app service approach, then you can remove the auth token on angular client and then reload the page using regular javascript.
You can check logout method of angular app to remove token.
Thanks, @ismcagdas! I called the logout method in AppAuthService after the DeleteMe method. It works fine.
-
0
Great :)