Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: decode identity jwt inside try block #6282

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/lib/functions/server.ts
Original file line number Diff line number Diff line change
@@ -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,
4 changes: 4 additions & 0 deletions tests/integration/commands/dev/dev-miscellaneous.test.js
Original file line number Diff line number Diff line change
@@ -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',