community-platform
community-platform copied to clipboard
[feature request] prevent signup if username contains invalid characters
Is your feature request related to a problem? Please describe. Username that is saved is different to the one entered by the user when joining as all special characters are stripped. e.g. if you used [email protected] as the username in the database it would save seanexamplecom
Describe the solution you'd like I think it's preferable to tell users they can only use certain characters for the username and check this as part of the form validation prior to creating the user.
Describe alternatives you've considered request a display name on the user signup form and then use an auto generated username based on the email address in the background. Where the username currently appears in the ui then show the display name.
Additional context N/A
Hey @AlfonsoGhislieri, Shall I work on this?
@professorabhay please do. I'll assign you to the ticket. Thanks for helping out.
Hey @iSCJT, Can you provide some details about invalid username character ? So, that I can make checks for that
@professorabhay currently we use this function to strip out any special characters: https://github.com/ONEARMY/community-platform/blob/954c5a47fcb89094b10e34cdf4659ae9cfc3a588/src/utils/helpers.ts#L7
So anything that doesn't pass this regex we'd want to highlight to the user signing up that it's invalid and prevent the form being submitted. Thanks.
@professorabhay how are you getting on with this one?
Hey @iSCJT, We can add some more checks and throw an error if case not pass.
export const formatLowerNoSpecial = (text: string) => {
const strippedText = stripSpecialCharacters(text);
const lowercaseText = strippedText.toLowerCase();
// Check if the stripped text is equal to the original text,
// indicating that no special characters were present.
if (strippedText !== text) {
// Display an error message to the user or prevent form submission.
// For example:
throw new Error('Invalid characters found in the username. Only letters, numbers, dashes, and underscores are allowed.');
}
return lowercaseText;
}
hey @professorabhay - do you want to start a PR for this one? otherwise will remove you as the assignee so other contributors can pick this up
It didn't look like any existing PR's had been made for this so I put together #2780.
:tada: This issue has been resolved in version 1.104.0 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket: