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)