Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Ras 52 posts 293 karma points
    14 days ago

    Get the currently logged in member in an UmbracoApiController?

    Hi, I'm struggling a bit with this. I have a member with 2fa enabled (if it matters), I'm able to log in and authenticate. I have an UmbracoApiController that performs some things, but before performing any operation in the api I want to check the currently logged in member. (Member, not User!)

    While logged in and authenticated, this does not work:

      var member = _membershipHelper.GetCurrentMemberAsync();

    _memberShipHelper is an instance of IMemberManager. But in this case the Result of member becomes null. Am I going to have to send an id/email/username as a parameter to my api call just to retrieve the currently logged in member? I want to avoid this.

    In fact, this GetCurrentMemberAsync() method works in a razor view, but not in the apicontroller. Why is that?

  • Huw Reddick 1659 posts 5776 karma points MVP c-trib
    1 week ago
    Huw Reddick

    Hi Ras,

    what version of Umbrac are you using?

    In my api controller I use the MemberManager for this (Umbraco 10+)

    var currentMember = _memberManager.GetCurrentMemberAsync()
  • Ras 52 posts 293 karma points
    1 week ago

    Hi Huw,

    Yes, this ended up being the correct method after all. The problem was on my end, as I was sending the API calls through Postman, I guess the system doesn't use the session or something like that? When I made the query through the browser, I was able to retrieve the currently logged in member. I am also on Umbraco 10.

Please Sign in or register to post replies

Write your reply to: