Last active
November 23, 2021 11:14
-
-
Save pawelel/197cb04b184f137488d6cfd72a443032 to your computer and use it in GitHub Desktop.
Get current user data without tracking by UserManager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CascadingParameter] private Task<AuthenticationState> AuthSP { get; set; } | |
[Inject] private NavigationManager NavigationManager { get; set; } | |
string UserId; | |
ApplicationUser CurrentUser = new(); | |
private async Task RedirectToLogin() | |
{ | |
var user = (await AuthSP).User; | |
if (!user.Identity.IsAuthenticated) | |
{ | |
NavigationManager.NavigateTo("Identity/Account/Login", true); | |
} | |
else | |
{ | |
UserId = user.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).First().Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment