Click here to Skip to main content
15,845,598 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to learn Angular2

and I am trying to create a simple blog with authentication.

this here is my add a new post method:

C#
[Authorize]
// POST: api/Post
public PostModel Post([FromBody]PostViewModel model)
{             
    var post = new PostModel
    {
        Body = model.Body,
        Title = model.Title,
        AuthorId = IdentityExtensions.GetUserId(User.Identity),
    };
    var res = blogRepo.AddPost(post);
    return res;                 
}

everything works fine, but
C#
IdentityExtension.GetUserId()
do not return the most current logged in user but the first user since the app started.

basically I am looking for a way to make sure that the current user logs out on the server as well as on the client (the client side is just a simple removal of the localStorage.removeItem("jwt");)

also there is a good chance that what I am doing is totally wrong, but I can't access the ApplicationUserManager in this controller.

What I have tried:

best res so far was:
AuthorId = IdentityExtensions.GetUserId(User.Identity)
also
Request.GetOwinContext().Authentication.SignOut();

this last one basically i tried to make a logout method, but I cant call this method for what ever the reasons
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900