clerk / javascript

Official Javascript repository for Clerk authentication
https://clerk.com
MIT License
1.12k stars 246 forks source link

Adapt Remix package to run on Cloudflare Workers #127

Closed MedicusIO closed 1 year ago

MedicusIO commented 2 years ago

Package

Description

The rootAuthLoader uses http2 which is a node package. Cloudflare Workers does not have access to Node.js packages, just plain javascript. Can this not be changed to fetch?

nikosdouvlis commented 2 years ago

Thanks for reporting that. A ticket for this issue already exists, so let me get back at you once the fix is deployed - will probably happen soon enough :)

igneel64 commented 2 years ago

Hey @MedicusIO :) Can you please gives us some information on your setup and the packages used ? (an example repo would be even better)

MedicusIO commented 2 years ago

After much soul searching I switched to Fly.IO which runs node (so this is less of an issue to me now). Cloudflare workers run V8 so anything that runs in the browser runs in a worker. The upside is there is no cold start like with lambda. However, you cannot use any node packages which is limiting.

Slooowpoke commented 2 years ago

I've encountered this too I think, even just trying to run miniflare with Clerk doesn't seem to work.

I'm guessing it's because of Clerk only because of this error:

../../node_modules/http2-wrapper/source/index.js:2:22:
      2 │ const http2 = require('http2');
        ╵                       ~~~~~~~
  The package "http2" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

If I search through all the packages in the project for the ones that use http-wrapper, the only one I get is one called "got", which is used in Clerk-node. I'll try and put together a simple reproduction case but it might take until this weekend.

igneel64 commented 2 years ago

Thanks peeps, it would be really helpful for us to start checking the issue based on the setup and give you a resolution.

Slooowpoke commented 2 years ago

Found five minutes this morning and it was actually easier than I thought to reproduce. https://github.com/Slooowpoke/clerk-remix-workers

This is a fresh remix repo with Cloudflare workers set as the deployment target, I've added Clerk's root auth loader, nothing else. If you try to run this, it won't work. If you remove the two lines for Clerk from root.tsx it works. Hope that's helpful.

SokratisVidros commented 2 years ago

clerk-remix depends on clerk-node-sdk that uses got HTTP client. That is, the current version of clerk-remix works for Node runtimes. I will a PR later today using a cross fetch library.

EArazli commented 2 years ago

any update here?

SokratisVidros commented 2 years ago

Still working on it. The latest status is that we need to find an isomorphic HTTP clients and an isomorphic crypto library. The HTTP client we picked for now is cross-fetch. Things are a bit trickier in the crypto world.

EArazli commented 2 years ago

Thanks for the update! Not sure if this helps, but CF workers implements the web crypto api and there seems to be something similar to cross-fetch for that use case. https://www.npmjs.com/package/isomorphic-webcrypto

There also seems to be support for the web crypto API in node directly but the earliest LTS with support seems to be 16 https://nodejs.org/api/webcrypto.html#web-crypto-api

marcus-sa commented 2 years ago

+1 this is also blocking me. Anything we can do to help speed up the process?

marcus-sa commented 2 years ago

Thanks for the update! Not sure if this helps, but CF workers implements the web crypto api and there seems to be something similar to cross-fetch for that use case. https://www.npmjs.com/package/isomorphic-webcrypto

There also seems to be support for the web crypto API in node directly but the earliest LTS with support seems to be 16 https://nodejs.org/api/webcrypto.html#web-crypto-api

According to MDN, it's supported from v15.

SokratisVidros commented 2 years ago

Folks, this is the first PR towards a more isomorphic architecture https://github.com/clerkinc/javascript/pull/290. It's still WIP as I am currently on paternity leave but the direction should be clear. Let us know what you think.

marcus-sa commented 2 years ago

@SokratisVidros any updates or any way to help speed up the process?

marcus-sa commented 2 years ago

Still working on it. The latest status is that we need to find an isomorphic HTTP clients and an isomorphic crypto library. The HTTP client we picked for now is cross-fetch. Things are a bit trickier in the crypto world.

There's https://github.com/sindresorhus/ky-universal by the same people who created got.

SokratisVidros commented 2 years ago

Hey @marcus-sa, the PR introducing fetch will be merged later this week. The next step is to bump to Node 16 and use webcrypto. Apologies this is taking longer than expected but more pressuring tasks came up as we are in the process of releasing ClerkJS V4 with brand new components.

SokratisVidros commented 2 years ago

The first PR about fetch is now merged. Next week we will replace Node crypto with Web crypto.

phpb-com commented 2 years ago

Any update on this? Would be good to be finally able use Clerk with Remix and CF Pages. 🙏

SokratisVidros commented 2 years ago

Apologies for the delay. We are currently working to support Next.js 12.2 Middleware. Cloudflare workers for Remix and other frameworks are next on the list.

phpb-com commented 2 years ago

Is there any sort of timeline that we could refer to?

SokratisVidros commented 1 year ago

We expect this to be resolved in November. As you can see in https://github.com/clerkinc/javascript/pull/460/files we've started rearchitecting our backend SDKS to make them work across web-interoperable runtimes.

aerojeyenth commented 1 year ago

@SokratisVidros May I know the status of this ? Is the support for Remix on Cloudflare workers is still experimental ?

aerojeyenth commented 1 year ago

@dimkl Thank you for tagging this to my comment but I am afraid and believe that these are not related. The document on your website clearly states that Edge runtime including Cloudflare Workers is supported image https://clerk.com/docs/quickstarts/get-started-with-remix

I am not sure if this ticket is still valid. Please kindly help this is a huge blocker for the work which I have planned. Thank you so much in advance.

arjunyel commented 1 year ago

I am currently using Clerk plus Cloudflare Pages so I believe this can be closed

SokratisVidros commented 1 year ago

Yes, Remix is fully supported across all runtimes.

dimkl commented 1 year ago

@aerojeyenth your issue is not related to this. i will reopen the previous issue.