From e6d1433cde336738f00c2387ec79e1deabe2efb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20Ara=C3=BAjo?= <4138302+paulo@users.noreply.github.com> Date: Fri, 5 Jan 2024 11:06:28 +0100 Subject: [PATCH] fix: decode identity jwt inside try block (#6282) --- src/lib/functions/server.ts | 20 +++++++++---------- .../commands/dev/dev-miscellaneous.test.js | 4 ++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/lib/functions/server.ts b/src/lib/functions/server.ts index 85b53a2a142..e9637fabefc 100644 --- a/src/lib/functions/server.ts +++ b/src/lib/functions/server.ts @@ -46,17 +46,17 @@ const buildClientContext = function (headers) { // } } - // This data is available on both the context root and under custom.netlify for retro-compatibility. - // In the future it will only be available in custom.netlify. - // @ts-expect-error - const user = jwtDecode(parts[1]) - - const netlifyContext = JSON.stringify({ - identity: identity, - user: user, - }) - try { + // This data is available on both the context root and under custom.netlify for retro-compatibility. + // In the future it will only be available in custom.netlify. + // @ts-expect-error + const user = jwtDecode(parts[1]) + + const netlifyContext = JSON.stringify({ + identity: identity, + user: user, + }) + return { identity: identity, user: user, diff --git a/tests/integration/commands/dev/dev-miscellaneous.test.js b/tests/integration/commands/dev/dev-miscellaneous.test.js index d3a71f4bc83..6d0c0b286a0 100644 --- a/tests/integration/commands/dev/dev-miscellaneous.test.js +++ b/tests/integration/commands/dev/dev-miscellaneous.test.js @@ -173,6 +173,10 @@ describe.concurrent('commands/dev-miscellaneous', () => { }, }).then((res) => res.json()) + t.expect(response.clientContext.identity.url).toEqual( + 'https://netlify-dev-locally-emulated-identity.netlify.com/.netlify/identity', + ) + const netlifyContext = Buffer.from(response.clientContext.custom.netlify, 'base64').toString() t.expect(JSON.parse(netlifyContext).identity.url).toEqual( 'https://netlify-dev-locally-emulated-identity.netlify.com/.netlify/identity',