Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support edge runtime #996

Open
5 tasks done
MorelSerge opened this issue Apr 8, 2024 · 4 comments
Open
5 tasks done

Support edge runtime #996

MorelSerge opened this issue Apr 8, 2024 · 4 comments

Comments

@MorelSerge
Copy link

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • 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

@MrSuttonmann
Copy link

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
Copy link

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
Copy link
Author

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

@emmanuelgautier
Copy link

emmanuelgautier commented Aug 2, 2024

This snippet works fine for me waiting a better fix to be merged.

// @ts-ignore
process.version = 'cloudflare'

const client = new ManagementClient({
  ...
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants