mirror of
https://github.com/Ravinou/borgwarehouse
synced 2026-03-14 14:25:46 +01:00
refactor: ⚡ username is now allowed from 1 to 40 char. #479
This commit is contained in:
parent
0263edd44f
commit
6acfdbbfa1
3 changed files with 9 additions and 9 deletions
|
|
@ -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.',
|
||||
},
|
||||
})}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -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.)',
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue