From 54a6728f4e045e7b7669cba2d88664059217ce02 Mon Sep 17 00:00:00 2001 From: purocean Date: Thu, 25 Jul 2024 10:53:16 +0800 Subject: [PATCH] fix: fix /api/proxy-fetch transfer Authorization header --- src/main/server/index.ts | 2 +- src/renderer/support/api.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/server/index.ts b/src/main/server/index.ts index ddcdeab2..5f182c7f 100644 --- a/src/main/server/index.ts +++ b/src/main/server/index.ts @@ -38,7 +38,7 @@ const noCache = (ctx: any) => { } const checkPermission = (ctx: any, next: any) => { - const token = ctx.query._token || (ctx.headers['x-yn-authorization'] || ctx.headers.authorization || '').replace('Bearer ', '') + const token = ctx.query._token || (ctx.headers['x-yn-authorization'] ?? (ctx.headers.authorization || '')).replace('Bearer', '').trim() if (ctx.req._protocol || (!token && isLocalhost(ctx.request.ip))) { ctx.req.jwt = { role: 'admin' } diff --git a/src/renderer/support/api.ts b/src/renderer/support/api.ts index 54d2b648..d5507a55 100644 --- a/src/renderer/support/api.ts +++ b/src/renderer/support/api.ts @@ -73,9 +73,7 @@ export async function proxyFetch (url: string, init?: Omit init.body = JSON.stringify(init.body) } - if (JWT_TOKEN) { - init.headers = { ...init.headers, 'x-yn-authorization': 'Bearer ' + JWT_TOKEN } - } + init.headers = { ...init.headers, 'x-yn-authorization': 'Bearer ' + JWT_TOKEN } const res: Response = await fetch(`/api/proxy-fetch/${url}`, init)