Skip to content

Commit

Permalink
fix(backend): Polyfill webcrypto for node14 and node12
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdouvlis committed Jan 17, 2023
1 parent bfb1825 commit 329bd6d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/backend/package.json
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@clerk/shared": "^0.9.0-staging.2",
"@clerk/types": "^3.24.0-staging.1",
"@peculiar/webcrypto": "1.4.1",
"@types/node": "16.18.6",
"deepmerge": "^4.2.2",
"node-fetch-native": "0.1.8",
Expand Down
12 changes: 10 additions & 2 deletions packages/backend/src/runtime/node/crypto.js
@@ -1,3 +1,11 @@
const crypto = require('node:crypto');
let webcrypto;
try {
webcrypto = require('node:crypto').webcrypto;
if (!webcrypto) {
webcrypto = new (require('@peculiar/webcrypto').Crypto)();
}
} catch (e) {
webcrypto = new (require('@peculiar/webcrypto').Crypto)();
}

module.exports = crypto.webcrypto;
module.exports = webcrypto;
2 changes: 1 addition & 1 deletion packages/backend/tsup.config.ts
Expand Up @@ -7,7 +7,7 @@ export default defineConfig(overrideOptions => {

return {
entry: ['src/index.ts'],
onSuccess: 'tsc',
onSuccess: 'tsc && npm run build:runtime',
minify: isProd,
sourcemap: true,
format: ['cjs', 'esm'],
Expand Down

0 comments on commit 329bd6d

Please sign in to comment.