C#C
C#3y ago
AAA

❔ .Net Core API User.FindFirstValue(ClaimTypes.NameIdentifier) in every action?!

Hi everyone I have the end point below
[HttpPost, Route("stores/new"), Authorize(policy: "client")]
        public async Task<IActionResult> AddNewStore(NewStoreRequestDto store)
        {
            int userId = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));
//do something
        }

now the line where i get the userId is being repeated in every action where i need the userId. is there a better way to have this value saved globally or in the controller scope or something?
Was this page helpful?