Copied to clipboard

Flag this post as spam?

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


  • bjarnerosendal 11 posts 102 karma points
    Apr 10, 2024 @ 09:58
    bjarnerosendal
    0

    How to check for login status in UmbracoApiController

    I am trying to setup an endpoint that can return information regarding the user login status.

    My method looks like this:

    [HttpGet]
    public ActionResult IsLoggedIn()
    {
         // this always returns false
         bool isLoggedIn = _memberManager.IsLoggedIn();
         if (isLoggedIn)
         {
             return Ok("User is logged in");
         }
         else
         {
             return BadRequest();
         }
    }
    

    For some reason, I cannot seem to be able to get a positive indication that the user is logged in. Even though I am sending along the auth cookie called ".AspNetCore.Identity.Application" that I got returned after the login.

    On the other hand, in my login endpoint, if I check the status right after the succesfull login, the IsLoggedIn method returns true (obviously) 😉

    enter image description here

    Does anyone have a clue what I might be missing in my IsLoggedIn endpoint?

  • bjarnerosendal 11 posts 102 karma points
    Apr 10, 2024 @ 12:45
    bjarnerosendal
    100

    Never mind, I seem to have messed up some configuration in startup.cs. I fixed it by referencing a clean Umbraco 13.2.2 - and changing to minimal hosting model as well 😉

Please Sign in or register to post replies

Write your reply to:

Draft