Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Handle M_INVALID_USERNAME on /register/available #9237

Merged
merged 5 commits into from
Sep 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/views/auth/RegistrationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum UsernameAvailableStatus {
Available,
Unavailable,
Error,
Invalid,
}

export const PASSWORD_MIN_SCORE = 3; // safely unguessable: moderate protection from offline slow-hash scenario.
Expand Down Expand Up @@ -363,7 +364,9 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
const available = await this.props.matrixClient.isUsernameAvailable(value);
return available ? UsernameAvailableStatus.Available : UsernameAvailableStatus.Unavailable;
} catch (err) {
return UsernameAvailableStatus.Error;
return err.errcode === "M_INVALID_USERNAME"
? UsernameAvailableStatus.Invalid
: UsernameAvailableStatus.Error;
}
},
rules: [
Expand All @@ -374,7 +377,8 @@ export default class RegistrationForm extends React.PureComponent<IProps, IState
},
{
key: "safeLocalpart",
test: ({ value }) => !value || SAFE_LOCALPART_REGEX.test(value),
test: ({ value }, usernameAvailable) => (!value || SAFE_LOCALPART_REGEX.test(value))
&& usernameAvailable !== UsernameAvailableStatus.Invalid,
invalid: () => _t("Some characters not allowed"),
},
{
Expand Down