Merge branch 'normalize-username' into 'develop'
Login: strip whitespace around username, strip leading @ See merge request soapbox-pub/soapbox-fe!1655
This commit is contained in:
commit
077b2398ba
2 changed files with 18 additions and 2 deletions
|
@ -207,9 +207,19 @@ export const loadCredentials = (token: string, accountUrl: string) =>
|
||||||
})
|
})
|
||||||
.catch(() => dispatch(verifyCredentials(token, accountUrl)));
|
.catch(() => dispatch(verifyCredentials(token, accountUrl)));
|
||||||
|
|
||||||
|
/** Trim the username and strip the leading @. */
|
||||||
|
const normalizeUsername = (username: string): string => {
|
||||||
|
const trimmed = username.trim();
|
||||||
|
if (trimmed[0] === '@') {
|
||||||
|
return trimmed.slice(1);
|
||||||
|
} else {
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const logIn = (username: string, password: string) =>
|
export const logIn = (username: string, password: string) =>
|
||||||
(dispatch: AppDispatch) => dispatch(getAuthApp()).then(() => {
|
(dispatch: AppDispatch) => dispatch(getAuthApp()).then(() => {
|
||||||
return dispatch(createUserToken(username, password));
|
return dispatch(createUserToken(normalizeUsername(username), password));
|
||||||
}).catch((error: AxiosError) => {
|
}).catch((error: AxiosError) => {
|
||||||
if ((error.response?.data as any).error === 'mfa_required') {
|
if ((error.response?.data as any).error === 'mfa_required') {
|
||||||
// If MFA is required, throw the error and handle it in the component.
|
// If MFA is required, throw the error and handle it in the component.
|
||||||
|
|
|
@ -128,10 +128,13 @@ const Header = () => {
|
||||||
<Input
|
<Input
|
||||||
required
|
required
|
||||||
value={username}
|
value={username}
|
||||||
onChange={(event) => setUsername(event.target.value)}
|
onChange={(event) => setUsername(event.target.value.trim())}
|
||||||
type='text'
|
type='text'
|
||||||
placeholder={intl.formatMessage(messages.username)}
|
placeholder={intl.formatMessage(messages.username)}
|
||||||
className='max-w-[200px]'
|
className='max-w-[200px]'
|
||||||
|
autoComplete='off'
|
||||||
|
autoCorrect='off'
|
||||||
|
autoCapitalize='off'
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
|
@ -141,6 +144,9 @@ const Header = () => {
|
||||||
type='password'
|
type='password'
|
||||||
placeholder={intl.formatMessage(messages.password)}
|
placeholder={intl.formatMessage(messages.password)}
|
||||||
className='max-w-[200px]'
|
className='max-w-[200px]'
|
||||||
|
autoComplete='off'
|
||||||
|
autoCorrect='off'
|
||||||
|
autoCapitalize='off'
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Link to='/reset-password'>
|
<Link to='/reset-password'>
|
||||||
|
|
Loading…
Reference in a new issue