Skip to content

Commit

Permalink
fix: decode identity jwt inside try block (#6282)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo committed Jan 5, 2024
1 parent 013f7f5 commit e6d1433
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/lib/functions/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/commands/dev/dev-miscellaneous.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

2 comments on commit e6d1433

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,410
  • Package size: 422 MB
  • Number of ts-expect-error directives: 1,189

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,410
  • Package size: 422 MB
  • Number of ts-expect-error directives: 1,189

Please sign in to comment.