Skip to content

Commit

Permalink
Merge pull request #138 from nameczz/fix-auth-login
Browse files Browse the repository at this point in the history
Fix auth login
  • Loading branch information
shanghaikid authored Dec 8, 2022
2 parents 6b60189 + 27ec77a commit 9edb74d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 58 deletions.
2 changes: 2 additions & 0 deletions client/src/i18n/cn/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const commonTrans = {
unAuth: 'Username or password is not correct',
username: 'Username',
password: 'Password',
optional: '(optional)',

ssl: 'SSL',
},
status: {
Expand Down
1 change: 1 addition & 0 deletions client/src/i18n/en/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const commonTrans = {
unAuth: 'Username or password is not correct',
username: 'Username',
password: 'Password',
optional: '(optional)',
ssl: 'SSL',
},
status: {
Expand Down
80 changes: 31 additions & 49 deletions client/src/pages/connect/AuthForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const AuthForm = (props: any) => {
const checkedForm = useMemo(() => {
return formatForm(form);
}, [form]);
const { validation, checkIsValid, disabled } = useFormValidation(checkedForm);
const { validation, checkIsValid } = useFormValidation(checkedForm);

const handleInputChange = (
key: 'address' | 'username' | 'password' | 'ssl',
Expand Down Expand Up @@ -105,56 +105,38 @@ export const AuthForm = (props: any) => {
defaultValue: form.address,
},
];
return showAuthForm
? [
...noAuthConfigs,
{
label: attuTrans.username,
key: 'username',
onChange: (value: string) => handleInputChange('username', value),
variant: 'filled',
className: classes.input,
placeholder: attuTrans.username,
fullWidth: true,
validations: [
{
rule: 'require',
errorText: warningTrans('required', {
name: attuTrans.username,
}),
},
],
defaultValue: form.username,
},
{
label: attuTrans.password,
key: 'password',
onChange: (value: string) => handleInputChange('password', value),
variant: 'filled',
className: classes.input,
placeholder: attuTrans.password,
fullWidth: true,
type: 'password',
validations: [
{
rule: 'require',
errorText: warningTrans('required', {
name: attuTrans.password,
}),
},
],
defaultValue: form.username,
},
]
: noAuthConfigs;
}, [form, attuTrans, warningTrans, classes.input, showAuthForm]);
return [
...noAuthConfigs,
{
label: `${attuTrans.username} ${attuTrans.optional}`,
key: 'username',
onChange: (value: string) => handleInputChange('username', value),
variant: 'filled',
className: classes.input,
placeholder: attuTrans.username,
fullWidth: true,

defaultValue: form.username,
},
{
label: `${attuTrans.password} ${attuTrans.optional}`,
key: 'password',
onChange: (value: string) => handleInputChange('password', value),
variant: 'filled',
className: classes.input,
placeholder: attuTrans.password,
fullWidth: true,
type: 'password',

defaultValue: form.username,
},
];
}, [form, attuTrans, warningTrans, classes.input]);

const handleConnect = async () => {
const address = formatAddress(form.address);
try {
const data = showAuthForm
? { ...form, address }
: { address, ssl: form.ssl };
const data = { ...form, address };
await MilvusHttp.connect(data);
setIsAuth(true);
setAddress(address);
Expand All @@ -172,8 +154,8 @@ export const AuthForm = (props: any) => {
};

const btnDisabled = useMemo(() => {
return showAuthForm ? disabled : form.address.trim().length === 0;
}, [showAuthForm, disabled, form.address]);
return form.address.trim().length === 0;
}, [form.address]);

return (
<section className={classes.wrapper}>
Expand Down
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "attu",
"version": "2.2.0",
"version": "2.2.1",
"license": "MIT",
"author": {
"name": "zilliz",
Expand Down Expand Up @@ -140,4 +140,4 @@
]
}
}
}
}
7 changes: 0 additions & 7 deletions server/src/milvus/milvus.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,6 @@ export class MilvusService {
} catch (error) {
// if milvus is not working, delete connection.
cache.del(milvusAddress);
/**
* When user change the user password, milvus will also return unauthenticated error.
* Need to care it in cloud service.
*/
if (error.toString().includes('unauthenticated')) {
throw HttpErrors(HTTP_STATUS_CODE.UNAUTHORIZED, error);
}
throw HttpErrors(HTTP_STATUS_CODE.BAD_REQUEST, error);
}
}
Expand Down

0 comments on commit 9edb74d

Please sign in to comment.