Support edge runtime
Checklist
- [X] I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
- [X] I have looked into the API documentation and have not found a suitable solution or answer.
- [X] I have searched the issues and have not found a suitable solution or answer.
- [X] I have searched the Auth0 Community forums and have not found a suitable solution or answer.
- [X] I agree to the terms within the Auth0 Code of Conduct.
Describe the problem you'd like to have solved
This library is not compatible with Vercel's edge runtime (haven't tested others) due to this line: https://github.com/auth0/node-auth0/blob/master/src/utils.ts#L10
Describe the ideal solution
This library to support the edge runtime
Alternatives and current workarounds
Patch the package to not use node.version.
Additional context
No response
I'm having the same issue with Cloudflare Workers.
Even though Cloudflare Workers expose certain parts of the Node runtime, they need to be imported like so:
// Do this:
import { Buffer } from 'node:buffer';
// Do not do this:
import { Buffer } from 'buffer';
Whether this has any further implications, I'm not sure. I'm considering forking this repo and pushing my own package.
Would love to see this, running in to the same issue on Vercel's Edge runtime.
Patch the package to not use node.version.
In the meantime, could you share how you patched the package to fix it?
In the meantime, could you share how you patched the package to fix it?
Sure, here's my patchfile:
diff --git a/dist/cjs/utils.js b/dist/cjs/utils.js
index b616a65f9535b8836a8521d44315811b12e2b959..9614a1452ff37ff0654f1375802bfe5d08b144c5 100644
--- a/dist/cjs/utils.js
+++ b/dist/cjs/utils.js
@@ -9,7 +9,7 @@ const generateClientInfo = () => ({
name: 'node-auth0',
version: version_js_1.version,
env: {
- node: process.version.replace('v', ''),
+ node: typeof EdgeRuntime === 'string' ? 'Edge' : process.version.replace('v', ''),
},
});
exports.generateClientInfo = generateClientInfo;
diff --git a/dist/esm/utils.js b/dist/esm/utils.js
index f9774bdcceeaa2597199fff97b644d104cccfbc0..e10824ecc61864340f966c06bdc57c167e1d7bbd 100644
--- a/dist/esm/utils.js
+++ b/dist/esm/utils.js
@@ -6,7 +6,7 @@ export const generateClientInfo = () => ({
name: 'node-auth0',
version: version,
env: {
- node: process.version.replace('v', ''),
+ node: typeof EdgeRuntime === 'string' ? 'Edge' : process.version.replace('v', ''),
},
});
//# sourceMappingURL=utils.js.map
This snippet works fine for me waiting a better fix to be merged.
// @ts-ignore
process.version = 'cloudflare'
const client = new ManagementClient({
...
})