auth0 / node-auth0

Node.js client library for the Auth0 platform.
MIT License
622 stars 303 forks source link

Support edge runtime #996

Open MorelSerge opened 3 months ago

MorelSerge commented 3 months ago

Checklist

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

MrSuttonmann commented 3 months ago

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';

Source

Whether this has any further implications, I'm not sure. I'm considering forking this repo and pushing my own package.

Jwiggiff commented 2 months ago

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?

MorelSerge commented 2 months ago

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