Base solution for your next web application
Open Closed

Implement logout and delete own user functionality through asp.net core API #9591


User avatar
0
mahendra created

We have a requirement where we have to logout, delete own user(self delete) and then redirect to login page. I have to achieve this functionality through API (in OneEnterprise.iHUB.Application project). Please tell me the best way so that on logout cookies, tokens and everything related to current user are also cleard. Prerequisites product information is given below:

Prerequisites

  • What is your product version? 8.2.0
  • What is your product type (Angular or MVC)? Angular
  • What is product framework type (.net framework or .net core)? .net core

9 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mahendra

    You can directly modify logout endpoint and delete user at the end of the method.

    This endpoint can be consumed by remote endpoints.

  • User Avatar
    0
    mahendra created

    Hi Team,

    Sorry..i am not getting what you do mean by modify endpoint? Do want to say i have to implement exact LogOut() method given in TokenAuthController? If yes then how will i implement it because in our service API (in OneEnterprise.iHUB.Application project), we don't apply api verbs like: [HttpGet] and also lot of these lines could be implemened in controller only like User object of User.Claims belongs to ControllerBase class.

    Our requirement is also that once user is logout and deleted, we have to redirect him to Login page, how can i achieve this things through service API?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mahendra

    I couldn't understand the relation with Http verbs here. When you call the endpoint from Angular app, you can redirect use to login page after server returns a successfull response.

  • User Avatar
    0
    mahendra created

    Hi Team,

    Could you please give me sample code how will write this logic in our service API project (in OneEnterprise.iHUB.Application project). I am not still not getting why do mean by keyword "endpoint " here.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Unfortunately, we can't provide a sample code for this use case. I have shared the link for logout endpoint here.

  • User Avatar
    0
    mahendra created

    Hi Team,

    We have created a custom entity "Business Partner" via asp.net zero power tool and attached one or more abp user(s) to this business partner.

    My requirement is if web user delete this "Business partner" record from the webGUI then behind the sceen through service API we would like to delete all abp user(s) assigned to this business partner including the one with which user is currently logged in.

    So once all abp user(s) are deleted, we have to logout the current user and need to return to login page. Now please let us know in this requirement, what code we need to write to delete, logout current user and list of user(s) we have and then will return to login page.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mahendra

    When you delete a user from AbpUsers page, the logged in user must be logged out when the user tries to execute any operation on the UI.

    If you want to logout user before the user's first action, you can send a SignalR event to a specific user (the deleted user in this case) and redirect user to login page. But, I think this is not necessary because user will be logged out in a short time.

  • User Avatar
    0
    mahendra created

    Hi Team,

    I would like to take this opportunity to explain the business case again.

    We have created a custom entity "Business Partner" via asp.net zero power tool and attached one or more abpuser(s) to this business partner.

    Our requirement is if we delete this "Business partner" record from the WebGUI then behind the sceen through service API we would like to delete all attached abp user(s) assigned to this business partner including the one with which user is currently logged in.

    So once all abp user(s) are deleted, we have to logout the current user and need to return to login page.

    Now please let us know what code we need to write to delete, logout current user and list of user(s) we have and then will return to login page.

    This current user needs to deleted behind the sceen through service api, not on controller apis or direct through Angular Api.

    We are open to have webex session with you. Please let us know the email id where invite can be send.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mahendra

    IF there are many users belonging to a specific Business Partner, you can create a background job and delete users of the deleted business partner, see https://aspnetboilerplate.com/Pages/Documents/Background-Jobs-And-Workers.

    When a user is deleted (even in the background job) and if the user is already logged in, this user will be redirected to login page on the user's first action.

    So, I think you just need to implement a backgroudn job to delete users of a Business Partner.