public override async Task <WhoAmIReply> WhoAmI(Empty request, ServerCallContext context) { AppUser?user = await _userManager.GetUserAsync(context.GetHttpContext().User); WhoAmIReply result = new WhoAmIReply(); SystemSetting?installedSetting = await _authDbContext.SystemSettings .SingleOrDefaultAsync(s => s.Name == "installer.is_installed" && s.Value == "true"); result.IsInstalled = (installedSetting != null); if (user != null) { result.IsAuthenticated = true; result.UserId = user.Id.ToString(); result.Roles.AddRange(await _userManager.GetRolesAsync(user)); if (_profileImageManager.HasProfileImage(user.Id)) { result.ProfilePicture = "/api/profile/image/" + user.Id.ToString(); } result.UserName = user.UserName; } else { result.IsAuthenticated = false; } return(result); }
public override Task<WhoAmIReply> WhoAmI(Empty request, ServerCallContext context) { string? userId = _userManager.GetUserId(context.GetHttpContext().User); WhoAmIReply result; if (userId != null) { result = new WhoAmIReply { IsAuthenticated = true, UserId = userId }; } else { result = new WhoAmIReply { IsAuthenticated = false }; } return Task.FromResult(result); }