refactor: username is now allowed from 1 to 40 char. #479

This commit is contained in:
Ravinou 2025-06-01 11:02:31 +02:00
commit 6acfdbbfa1
No known key found for this signature in database
GPG key ID: EEEE670C40F6A4D7
3 changed files with 9 additions and 9 deletions

View file

@ -90,16 +90,16 @@ export default function UsernameSettings(props: UsernameSettingDTO) {
{...register('username', {
required: 'A username is required.',
pattern: {
value: /^[a-z]{5,15}$/,
value: /^[a-z]{1,40}$/,
message: 'Only a-z characters are allowed',
},
maxLength: {
value: 10,
message: '15 characters max.',
value: 40,
message: '40 characters max.',
},
minLength: {
value: 5,
message: '5 characters min.',
value: 1,
message: '1 characters min.',
},
})}
/>

View file

@ -49,14 +49,14 @@ describe('PUT /api/account/updateUsername', () => {
const { req, res } = createMocks({
method: 'PUT',
body: { username: 'Too$hort!' },
body: { username: '' },
});
await handler(req, res);
expect(res._getStatusCode()).toBe(422);
expect(res._getJSONData()).toEqual({
message: 'Only a-z characters are allowed (5 to 15 char.)',
message: 'Only a-z characters are allowed (1 to 40 char.)',
});
});

View file

@ -24,10 +24,10 @@ export default async function handler(
if (typeof username !== 'string') {
return res.status(422).json({ message: 'Unexpected data' });
}
const usernameRegex = new RegExp(/^[a-z]{5,15}$/);
const usernameRegex = new RegExp(/^[a-z]{1,40}$/);
if (!usernameRegex.test(username)) {
res.status(422).json({
message: 'Only a-z characters are allowed (5 to 15 char.)',
message: 'Only a-z characters are allowed (1 to 40 char.)',
});
return;
}