Skip to content

Commit

Permalink
Fix subtle crypto import for node versions that ship it natively (> v15)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Jun 7, 2022
1 parent 56d166f commit 653bfc0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

- Fix subtle crypto import for node versions that ship it natively (> v15)

## [0.1.0]

- The backend implementation now uses the web fetch api instead of relying on
Expand Down
7 changes: 5 additions & 2 deletions packages/backend/src/util/JWT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ let subtle =
if (!subtle)
subtle = import('node:crypto')
.then((c: any) => c.webcrypto.subtle)
.catch(() => import('@peculiar/webcrypto'))
.then(c => new c.Crypto().subtle as any)
.catch(() => {
return import('@peculiar/webcrypto').then(
c => new c.Crypto().subtle as any
)
})
.catch(() => undefined)

const algorithms = {
Expand Down

0 comments on commit 653bfc0

Please sign in to comment.