Skip to content

Commit 01159fe

Browse files
authored
feat: show general error for auth (#3154)
1 parent 242a3ed commit 01159fe

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/containers/Authentication/Authentication.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,11 @@
8686
top: 40px;
8787
right: 40px;
8888
}
89+
&__general-error {
90+
width: 100%;
91+
height: var(--g-text-body-1-line-height);
92+
margin-top: var(--g-spacing-1);
93+
94+
color: var(--g-color-text-danger);
95+
}
8996
}

src/containers/Authentication/Authentication.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {basename} from '../../store';
99
import {authenticationApi} from '../../store/reducers/authentication/authentication';
1010
import {useLoginWithDatabase} from '../../store/reducers/capabilities/hooks';
1111
import {cn} from '../../utils/cn';
12+
import {prepareCommonErrorMessage} from '../../utils/errors';
1213
import {useMetaAuth} from '../../utils/hooks/useMetaAuth';
1314

1415
import {isDatabaseError, isPasswordError, isUserError} from './utils';
@@ -68,23 +69,28 @@ function Authentication({closable = false}: AuthenticationProps) {
6869
const [loginError, setLoginError] = React.useState('');
6970
const [passwordError, setPasswordError] = React.useState('');
7071
const [databaseError, setDatabaseError] = React.useState('');
72+
const [generalError, setGeneralError] = React.useState('');
7173
const [showPassword, setShowPassword] = React.useState(false);
7274

7375
const onLoginUpdate = (value: string) => {
7476
setLogin(value);
7577
setLoginError('');
78+
setGeneralError('');
7679
};
7780
const onDatabaseUpdate = (value: string) => {
7881
setDatabase(value);
7982
setDatabaseError('');
83+
setGeneralError('');
8084
};
8185

8286
const onPassUpdate = (value: string) => {
8387
setPass(value);
8488
setPasswordError('');
89+
setGeneralError('');
8590
};
8691

8792
const onLoginClick = () => {
93+
setGeneralError('');
8894
authenticate({user: login, password, database, useMeta})
8995
.unwrap()
9096
.then(() => {
@@ -93,6 +99,8 @@ function Authentication({closable = false}: AuthenticationProps) {
9399
}
94100
})
95101
.catch((error) => {
102+
const isInputError =
103+
isUserError(error) || isPasswordError(error) || isDatabaseError(error);
96104
if (isUserError(error)) {
97105
setLoginError(error.data.error);
98106
}
@@ -102,6 +110,11 @@ function Authentication({closable = false}: AuthenticationProps) {
102110
if (isDatabaseError(error)) {
103111
setDatabaseError(error.data.error);
104112
}
113+
114+
if (!isInputError) {
115+
const message = prepareCommonErrorMessage(error);
116+
setGeneralError(message);
117+
}
105118
});
106119
};
107120

@@ -184,6 +197,8 @@ function Authentication({closable = false}: AuthenticationProps) {
184197
>
185198
Sign in
186199
</Button>
200+
{/* always preserve place for general error to prevent container height jumping */}
201+
<div className={b('general-error')}>{generalError}</div>
187202
</form>
188203
{closable && history.length > 1 && (
189204
<Button onClick={onClose} className={b('close')}>

0 commit comments

Comments
 (0)