mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-23 08:56:42 +08:00
fix(web): preserve MCP authorization token across edits (#17177)
This commit is contained in:
@@ -39,8 +39,13 @@ const DefaultValues = {
|
|||||||
name: '',
|
name: '',
|
||||||
server_type: ServerType.SSE,
|
server_type: ServerType.SSE,
|
||||||
url: '',
|
url: '',
|
||||||
|
authorization_token: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Mask shown in the token field when editing an existing server that already
|
||||||
|
// has a token, so the user knows a secret is stored without exposing it.
|
||||||
|
const TokenMask = '********';
|
||||||
|
|
||||||
export function EditMcpDialog({
|
export function EditMcpDialog({
|
||||||
hideModal,
|
hideModal,
|
||||||
loading,
|
loading,
|
||||||
@@ -78,9 +83,15 @@ export function EditMcpDialog({
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleOk = async (values: z.infer<typeof FormSchema>) => {
|
const handleOk = async (values: z.infer<typeof FormSchema>) => {
|
||||||
|
// When the field still holds the mask, the user did not change the token;
|
||||||
|
// send the previously stored token so it is not overwritten with empty.
|
||||||
|
const token =
|
||||||
|
values.authorization_token === TokenMask
|
||||||
|
? data.variables?.authorization_token
|
||||||
|
: values.authorization_token;
|
||||||
const nextValues = {
|
const nextValues = {
|
||||||
...omit(values, 'authorization_token'),
|
...omit(values, 'authorization_token'),
|
||||||
variables: { authorization_token: values.authorization_token },
|
variables: { authorization_token: token },
|
||||||
headers: { Authorization: 'Bearer ${authorization_token}' },
|
headers: { Authorization: 'Bearer ${authorization_token}' },
|
||||||
};
|
};
|
||||||
if (isTriggeredBySaving) {
|
if (isTriggeredBySaving) {
|
||||||
@@ -95,7 +106,12 @@ export function EditMcpDialog({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isEmpty(data)) {
|
if (!isEmpty(data)) {
|
||||||
form.reset(pick(data, ['name', 'server_type', 'url']));
|
form.reset({
|
||||||
|
...pick(data, ['name', 'server_type', 'url']),
|
||||||
|
authorization_token: data.variables?.authorization_token
|
||||||
|
? TokenMask
|
||||||
|
: '',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [data, form]);
|
}, [data, form]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user