Cann’t find current user .NET api throw Angular but can do it with help of Postman
When i send request from Postman all works currect, but when i do it with help of angular request i
have null
Is it my .NET UserService
public async Task<UserDto> Login
(string email, string password)
{
if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password))
{
var user = _userManager.Users.First(x => x.Email == email);
await _signInManager.SignOutAsync();
var result = await _signInManager.PasswordSignInAsync(user, password, true, false);
if (result.Succeeded)
{
CurrentUser = _mapper.Map<User, UserDto>(user);
return CurrentUser;
}
else
{
throw new ValidationException("Cann't login this user");
}
}
else
{
throw new ValidationException("Cann't login this user");
}
}
public async Task<UserDto> GetCurrentUser(System.Security.Principal.IIdentity identity)
{
if (identity.Name != null)
{
return await Task.Run(() => _mapper.Map<User, UserDto>(_userManager.FindByNameAsync(identity.Name).Result));
}
else
{
return new UserDto();
}
}
It is my angular request
ngOnInit(): void {
this.http.get(`https://localhost:44334/api/Account/get-current`).subscribe((user) => console.log(user));
}
Source: Angular Questions