Fix tenant slug collision: append random hex suffix to prevent 23505 on duplicate tenant names
All checks were successful
CI — P2 Drift (Go + Node) / saas (push) Successful in 34s
CI — P2 Drift (Go + Node) / agent (push) Successful in 1m6s
CI — P3 Alert / test (push) Successful in 37s
CI — P5 Cost / test (push) Successful in 29s
CI — P4 Portal / test (push) Successful in 48s
CI — P6 Run / saas (push) Successful in 25s

This commit is contained in:
2026-03-01 22:36:21 +00:00
parent e0d3a3c043
commit 81d03c1735
5 changed files with 5 additions and 5 deletions

View File

@@ -159,7 +159,7 @@ export function registerAuthRoutes(app: FastifyInstance, jwtSecret: string, pool
if (existing.rows[0]) return reply.status(409).send({ error: 'Email already registered' });
const passwordHash = await hashPassword(body.password);
const slug = body.tenant_name.toLowerCase().replace(/[^a-z0-9]+/g, '-').slice(0, 50);
const slug = body.tenant_name.toLowerCase().replace(/[^a-z0-9]+/g, '-').slice(0, 42) + '-' + crypto.randomBytes(3).toString('hex');
const client = await pool.connect();
try {