fix(auth): use UUID fallback slug when company name produces empty slug (e.g. Chinese-only names)
This commit is contained in:
parent
550813c772
commit
7dc5881496
|
|
@ -208,11 +208,15 @@ export class AuthService {
|
||||||
phone?: string,
|
phone?: string,
|
||||||
) {
|
) {
|
||||||
// Generate slug from company name (underscores for valid PostgreSQL schema names)
|
// Generate slug from company name (underscores for valid PostgreSQL schema names)
|
||||||
const slug = companyName
|
let slug = companyName
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/[^a-z0-9]+/g, '_')
|
.replace(/[^a-z0-9]+/g, '_')
|
||||||
.replace(/(^_|_$)/g, '')
|
.replace(/(^_|_$)/g, '')
|
||||||
.slice(0, 40);
|
.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
|
// Check slug uniqueness
|
||||||
const existingTenant = await this.tenantRepository.findOneBy({ slug });
|
const existingTenant = await this.tenantRepository.findOneBy({ slug });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue