Skip to content

Instantly share code, notes, and snippets.

View gianlucacini's full-sized avatar
🍯

Gianluca Cini gianlucacini

🍯
View GitHub Profile
@gianlucacini
gianlucacini / IdentityErrorDescriber.cs
Last active October 7, 2024 16:41
Override IdentityErrorDescriber to translate AspNetCore.Identity error messages
//Create a class that inherits IdentityErrorDescriber
using Microsoft.AspNetCore.Identity;
public class ItalianIdentityErrorDescriber : IdentityErrorDescriber
{
public override IdentityError PasswordRequiresUniqueChars(int uniqueChars) => new IdentityError { Code = nameof(PasswordRequiresUniqueChars), Description = $"La password deve essere contenere almeno {uniqueChars} caratteri univoci." };
public override IdentityError RecoveryCodeRedemptionFailed() => new IdentityError { Code = nameof(RecoveryCodeRedemptionFailed), Description = $"Il codice di recupero non è stato utilizzato correttamente." };
public override IdentityError UserNotInRole(string role) => new IdentityError() { Code = nameof(UserNotInRole), Description = $"l'utente non fa parte del ruolo {role}." };
public override IdentityError DefaultError() => new IdentityError { Code = nameof(DefaultError), Description = $"Si è verificato un errore sconosciuto." };