Skip to content

fix: auto-generated username from email prefix can be shorter than 3 chars #54

Closed

Description

@coderabbitai

Summary

In both apps/public-api/src/controllers/userAuth.controller.js and apps/dashboard-api/src/controllers/userAuth.controller.js, the buildAuthUserPayload helper falls back to email.split('@')[0] to generate a username when the field is required but not provided.

This can produce a username as short as 1 character (e.g., a@b.com → "a"), which may fail validation rules elsewhere in the codebase that enforce a minimum length (e.g., Lines 389–393 in the controller).

Suggested Fix

Pad the auto-generated username to meet the minimum length requirement:

const generatedUsername = email.split('@')[0];
const username = generatedUsername.length >= 3
    ? generatedUsername
    : generatedUsername.padEnd(3, '0');

Or alternatively, enforce a minimum length check and return a 400 error asking the client to supply a valid username.

Context

Identified during review of PR #51 (#51 (comment)) as a minor issue deferred for a follow-up.

Requested by @yash-pouranik.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions