Copied to clipboard

Flag this post as spam?

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


  • Ras 61 posts 324 karma points
    Nov 20, 2023 @ 10:04
    Ras
    0

    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 1741 posts 6104 karma points MVP c-trib
    Nov 20, 2023 @ 13:53
    Huw Reddick
    100

    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 61 posts 324 karma points
    Nov 21, 2023 @ 07:52
    Ras
    0

    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:

Draft