From 152651931f1b8d559b058b5e3a6fdfc08b6c6639 Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Thu, 12 Sep 2024 17:59:51 +0800 Subject: [PATCH] feat(custom-request): add support for API token variable (#5263) * feat(custom-request): add support for API token variable * perf: improve user experience --- .../src/client/components/CustomRequestActionDesigner.tsx | 2 +- .../src/client/hooks/useCustomRequestVariableOptions.ts | 5 +++++ .../plugin-action-custom-request/src/server/actions/send.ts | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/plugins/@nocobase/plugin-action-custom-request/src/client/components/CustomRequestActionDesigner.tsx b/packages/plugins/@nocobase/plugin-action-custom-request/src/client/components/CustomRequestActionDesigner.tsx index 3631fde67..a860e4ef9 100644 --- a/packages/plugins/@nocobase/plugin-action-custom-request/src/client/components/CustomRequestActionDesigner.tsx +++ b/packages/plugins/@nocobase/plugin-action-custom-request/src/client/components/CustomRequestActionDesigner.tsx @@ -70,7 +70,7 @@ export function CustomRequestSettingsItem() { }, }); refresh(); - return message.success(t('Saved successfully')); + message.success(t('Saved successfully')); }} /> diff --git a/packages/plugins/@nocobase/plugin-action-custom-request/src/client/hooks/useCustomRequestVariableOptions.ts b/packages/plugins/@nocobase/plugin-action-custom-request/src/client/hooks/useCustomRequestVariableOptions.ts index 224b6a2af..5b83940d8 100644 --- a/packages/plugins/@nocobase/plugin-action-custom-request/src/client/hooks/useCustomRequestVariableOptions.ts +++ b/packages/plugins/@nocobase/plugin-action-custom-request/src/client/hooks/useCustomRequestVariableOptions.ts @@ -43,6 +43,11 @@ export const useCustomRequestVariableOptions = () => { title: t('Current time', { ns: 'client' }), children: null, }, + { + name: '$nToken', + title: 'API token', + children: null, + }, ]; }, [fields, userFields]); }; diff --git a/packages/plugins/@nocobase/plugin-action-custom-request/src/server/actions/send.ts b/packages/plugins/@nocobase/plugin-action-custom-request/src/server/actions/send.ts index d0beac5af..ce2eccb56 100644 --- a/packages/plugins/@nocobase/plugin-action-custom-request/src/server/actions/send.ts +++ b/packages/plugins/@nocobase/plugin-action-custom-request/src/server/actions/send.ts @@ -143,6 +143,7 @@ export async function send(this: CustomRequestPlugin, ctx: Context, next: Next) }, currentUser, currentTime: new Date().toISOString(), + $nToken: ctx.getBearerToken(), }; const getParsedValue = (value) => {