fix(auth): use UUID fallback slug when company name produces empty slug (e.g. Chinese-only names)

This commit is contained in:
hailin 2026-03-07 08:07:49 -08:00
parent 550813c772
commit 7dc5881496
1 changed files with 5 additions and 1 deletions

View File

@ -208,11 +208,15 @@ export class AuthService {
phone?: string,
) {
// Generate slug from company name (underscores for valid PostgreSQL schema names)
const slug = companyName
let slug = companyName
.toLowerCase()
.replace(/[^a-z0-9]+/g, '_')
.replace(/(^_|_$)/g, '')
.slice(0, 40);
// If company name is all non-ASCII (e.g. Chinese), slug will be empty — use UUID fallback
if (!slug) {
slug = crypto.randomUUID().replace(/-/g, '').slice(0, 16);
}
// Check slug uniqueness
const existingTenant = await this.tenantRepository.findOneBy({ slug });