clerk / javascript

Official Javascript repository for Clerk authentication
https://clerk.com
MIT License
957 stars 211 forks source link

`@clerk/backend` throws: `Invalid URL string` #2706

Closed dan-lee closed 5 months ago

dan-lee commented 5 months ago

Preliminary Checks

Reproduction / Replay Link

n/a

Publishable key

n/a

Description

Steps to reproduce:

Create a clerk client with the latest beta version (1.0.0-beta-v5.18) and get an organization.

import { createClerkClient } from '@clerk/backend' 

const clerk = createClerkClient({
  secretKey: env.CLERK_SECRET_KEY,
})

const org = await ctx.clerk.organizations.getOrganization({ 
  organizationId: 'org_xxxxxxxxxxxxxxxxx',  
})

Expected behavior:

Get back org correctly

Actual behavior:

It throws an error with Invalid URL string.


I tried to hunt it down and maybe found the problem:

https://github.com/clerk/javascript/blob/9289aafd0ac5178bef355a3410e3d7e120e51482/packages/backend/src/api/request.ts#L64-L67

joinPaths is responsible to remove double path joiners (when is it ever not a slash?):

https://github.com/clerk/javascript/blob/9289aafd0ac5178bef355a3410e3d7e120e51482/packages/backend/src/util/path.ts#L7-L10

Now the args of joinPaths look something like this: ["https://api.clerk.com", "v1", "/organizations/org_xxxxxxxxxxxxxxxxx"]

Unfortunately, the protocol contains a double slash as well and the result of url is:

https:/api.clerk.com/v1/organizations/org_xxxxxxxxxxxxxxxxx

Notice the https:/. new URL will throw with this input

mbuxmann commented 5 months ago

Also noticed this and reported in the Discord. However i am using "@clerk/backend": "^0.37.3", for what it is worth. Lets me believe i should maybe downgrade my version and see if that works.

https://discord.com/channels/856971667393609759/1202572778792816670

panteliselef commented 5 months ago

@dan-lee Any chance the code is running in an edge-runtime ?

dan-lee commented 5 months ago

@panteliselef Yeah that's right, the code is running a Cloudflare Worker