Fix Null Warnings (#874)
* Fixing null warnings * Fix null warnings Fix other compiler warnings
This commit is contained in:
@@ -10,10 +10,10 @@ public static class Dependencies
|
||||
{
|
||||
public static void ConfigureServices(IConfiguration configuration, IServiceCollection services)
|
||||
{
|
||||
var useOnlyInMemoryDatabase = false;
|
||||
bool useOnlyInMemoryDatabase = false;
|
||||
if (configuration["UseOnlyInMemoryDatabase"] != null)
|
||||
{
|
||||
useOnlyInMemoryDatabase = bool.Parse(configuration["UseOnlyInMemoryDatabase"]);
|
||||
useOnlyInMemoryDatabase = bool.Parse(configuration["UseOnlyInMemoryDatabase"]!);
|
||||
}
|
||||
|
||||
if (useOnlyInMemoryDatabase)
|
||||
|
||||
@@ -24,6 +24,9 @@ public class AppIdentityDbContextSeed
|
||||
var adminUser = new ApplicationUser { UserName = adminUserName, Email = adminUserName };
|
||||
await userManager.CreateAsync(adminUser, AuthorizationConstants.DEFAULT_PASSWORD);
|
||||
adminUser = await userManager.FindByNameAsync(adminUserName);
|
||||
await userManager.AddToRoleAsync(adminUser, BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS);
|
||||
if (adminUser != null)
|
||||
{
|
||||
await userManager.AddToRoleAsync(adminUser, BlazorShared.Authorization.Constants.Roles.ADMINISTRATORS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class IdentityTokenClaimService : ITokenClaimsService
|
||||
var tokenHandler = new JwtSecurityTokenHandler();
|
||||
var key = Encoding.ASCII.GetBytes(AuthorizationConstants.JWT_SECRET_KEY);
|
||||
var user = await _userManager.FindByNameAsync(userName);
|
||||
if (user == null) throw new UserNotFoundException(userName);
|
||||
var roles = await _userManager.GetRolesAsync(user);
|
||||
var claims = new List<Claim> { new Claim(ClaimTypes.Name, userName) };
|
||||
|
||||
|
||||
10
src/Infrastructure/Identity/UserNotFoundException.cs
Normal file
10
src/Infrastructure/Identity/UserNotFoundException.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace Microsoft.eShopWeb.Infrastructure.Identity;
|
||||
|
||||
public class UserNotFoundException : Exception
|
||||
{
|
||||
public UserNotFoundException(string userName) : base($"No user found with username: {userName}")
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user