Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/full-frogs-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/backend': patch
---

The `instanceof` check in `createClerkRequest` is allowing `Request` instances through, which means the required `cookies` object is never created/set on the instance. This causes an error in the TanStack Start middleware when `AuthenticateContext.getCookie` tries to access `cookies`. Instead of checking `instanceof`, we check for the presence of the `cookies` and `clerkUrl` keys to determine whether or not we're dealing with a `Request` or `ClerkRequest`
7 changes: 6 additions & 1 deletion packages/backend/src/tokens/clerkRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ class ClerkRequest extends Request {
}

export const createClerkRequest = (...args: ConstructorParameters<typeof ClerkRequest>): ClerkRequest => {
return args[0] instanceof ClerkRequest ? args[0] : new ClerkRequest(...args);
const isClerkRequest = args[0] &&
typeof args[0] === 'object' &&
'clerkUrl' in args[0] &&
'cookies' in args[0];

return isClerkRequest ? args[0] as ClerkRequest : new ClerkRequest(...args);
};

export type { ClerkRequest };