Outline

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