Fix: Sign-in user if exists
This commit is contained in:
@@ -39,16 +39,22 @@ public class GoogleController(
|
||||
FamilyName = claims.FirstOrDefault(c => c.Type == ClaimTypes.Surname)?.Value
|
||||
};
|
||||
|
||||
await userService.CreateUserAsync(userInfo); // TODO: Don't create user if already exists
|
||||
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(new List<Claim>
|
||||
var claimsIdentity = new ClaimsIdentity(new List<Claim>
|
||||
{
|
||||
new(ClaimTypes.Name, userInfo.Name),
|
||||
new(ClaimTypes.Email, userInfo.Email),
|
||||
new(ClaimTypes.GivenName, userInfo.GivenName),
|
||||
new(ClaimTypes.Surname, userInfo.FamilyName)
|
||||
}, CookieAuthenticationDefaults.AuthenticationScheme)));
|
||||
}, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
|
||||
if (await userService.FindUserByEmailAsync(userInfo.Email) != null) // TODO: Do we need to check for null ?
|
||||
{
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
|
||||
return Redirect("/");
|
||||
}
|
||||
|
||||
await userService.CreateUserAsync(userInfo);
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
|
||||
return Redirect("/");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,11 +72,11 @@ builder.Services.AddAuthentication(options =>
|
||||
// Password hashing
|
||||
builder.Services.AddIdentity<ApplicationUser, IdentityRole>(options =>
|
||||
{
|
||||
options.Password.RequireDigit = true;
|
||||
options.Password.RequireDigit = false;
|
||||
options.Password.RequireLowercase = false;
|
||||
options.Password.RequireUppercase = true;
|
||||
options.Password.RequireNonAlphanumeric = true;
|
||||
options.Password.RequiredLength = 8;
|
||||
options.Password.RequireUppercase = false;
|
||||
options.Password.RequireNonAlphanumeric = false;
|
||||
options.Password.RequiredLength = 16;
|
||||
})
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
Reference in New Issue
Block a user