auto-populate missing username field with email local-part

This commit is contained in:
2026-03-17 19:27:41 +08:00
parent 7b4d2e789f
commit 32746756d4
7 changed files with 215 additions and 11 deletions

View File

@@ -28,3 +28,19 @@ export function asProviderName(value: SsoProvider): 'GOOGLE' | 'DISCORD' {
export function normalizeEmail(email: string): string {
return email.trim().toLowerCase();
}
export function normalizeUsername(value: string): string {
return value
.trim()
.toLowerCase()
.normalize('NFKD')
.replace(/[\u0300-\u036f]/g, '')
.replace(/[^a-z0-9]+/g, '_')
.replace(/^_+|_+$/g, '')
.slice(0, 24);
}
export function usernameFromEmail(email: string): string {
const localPart = normalizeEmail(email).split('@')[0] ?? '';
return normalizeUsername(localPart);
}