Closed josephd9 closed 5 years ago
If your user is authenticated, you can call this. I use this in any controller I need that info, where User is the current claims principal:
var user = await _userManager.GetUserAsync(User).ConfigureAwait(false);
You can inject a UserManager to your controller. Example: https://github.com/aws/aws-aspnet-cognito-identity-provider/blob/master/samples/Samples/Areas/Identity/Pages/Account/Register.cshtml.cs#L22
Than call _userManager.GetUserAsync(User) as mentioned by @jlwhitfill .
You actually don't need to be authenticated, however the user you retrieve won't be authenticated either.
Deleting a user is done by calling UserManager.DeleteAsync(). There is no override in the CognitoUserManager class because the base implementation is already working with Cognito
How do i get the current claims principal? I tried var user = ClaimsPrincipal.Current; and it's always null.
I found it, sorry for the bad question. In case anyone else looking for it comes here, I found it here: var user = _signInManager.Context.User;
Title says it all. I can't figure out how to get the current user from my home controller.
I have a 2nd question, I can create a new post for it, but I figured it'd try it here. Is there any existing framework for a user deleting their account? Or do I have to write it myself with UserManager.DeleteAsync(); Just asking so I dont waste anymore time looking for it.
Thanks!