Dotnet
Current User

Exercise - Add CurrentUserAsync

Mute
Current Time 0:00
/
Duration Time 0:00
Loaded: 0%
Progress: 0%
Stream TypeLIVE
Remaining Time -0:00
 
PRO

Exercise: Add CurrentUserAsync

In the Conduit.Api Project

Modify the UserController (notice the singular "User")
  • Add the following method
    • Name: CurrentUserAsync
    • Return Type: IActionResult
    • Parameters: n/a
Add the following Attributes to the method
  • HttpGet
  • Authorize (bring in the namespace Microsoft.AspNetCore.Authorization)
Add the following code to the body of the method
User user = await AccountRepo.GetCurrentuserAsync();
return Ok(new { user });
Finally
  • Resolve any namespace errors you're seeing
  • Implement Exception Handling
  • Wrap the code in the body of the method with a try…catch block

Hint: Review the code in the UsersController

 

I finished! On to the next chapter