Skip to content

Commit

Permalink
fix: Types and NextJS 14 support (#1939, #1948) (#1968)
Browse files Browse the repository at this point in the history
* fix(clerk-sdk-node): Fix types of ClerkExpressWithAuth/ClerkExpressRequireAuth args (#1939)

#1938

* fix(backend): Support NextJS 14 (#1948)

* fix(backend): Fix for next 14 fetch bind issue

* fix(nextjs): Use named imports for fetch runtime polyfill

Next14 seems to have changed the way it handles default exports when using the webpack bundler for some of their build variants when using `npm run dev`. This commit ensures that we no longer use the default export in an effort to improve compat between the different nextjs versions.

More information can be found here: https://esbuild.github.io/content-types/#default-interop
and here: #612

* Create late-dolphins-peel.md

---------

Co-authored-by: Nikos Douvlis <nikosdouvlis@gmail.com>

---------

Co-authored-by: George Desipris <73396808+desiprisg@users.noreply.github.com>
Co-authored-by: Nikos Douvlis <nikosdouvlis@gmail.com>
  • Loading branch information
3 people authored Oct 31, 2023
1 parent 8b6b094 commit a605335
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-dolphins-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/backend": minor
---

Add support for NextJS 14
5 changes: 5 additions & 0 deletions .changeset/tasty-countries-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-sdk-node': patch
---

Fix types of ClerkExpressWithAuth/ClerkExpressRequireAuth args
1 change: 1 addition & 0 deletions packages/backend/src/runtime/browser/fetch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const RuntimeHeaders = Headers;
export const RuntimeRequest = Request;
export const RuntimeResponse = Response;
export const RuntimeAbortController = AbortController;
export const RuntimeFetch = fetch;
4 changes: 2 additions & 2 deletions packages/backend/src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import crypto from '#crypto';
import * as fetchApisPolyfill from '#fetch';

const {
default: fetch,
RuntimeFetch,
RuntimeAbortController,
RuntimeBlob,
RuntimeFormData,
Expand All @@ -44,7 +44,7 @@ type Runtime = {
// The globalThis object is supported for Node >= 12.0.
//
// https://github.com/supabase/supabase/issues/4417
const globalFetch = fetch.bind(globalThis);
const globalFetch = RuntimeFetch.bind(globalThis);
// DO NOT CHANGE: Runtime needs to be imported as a default export so that we can stub its dependencies with Sinon.js
// For more information refer to https://sinonjs.org/how-to/stub-dependency/
const runtime: Runtime = {
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/runtime/node/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ module.exports.RuntimeHeaders = Headers;
module.exports.RuntimeRequest = Request;
module.exports.RuntimeResponse = Response;
module.exports.RuntimeAbortController = AbortController;
module.exports.RuntimeFetch = fetch;
4 changes: 2 additions & 2 deletions packages/sdk-node/src/clerkClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ export const clerkClient = new Proxy(clerkClientSingleton, {
/**
* Stand-alone express middlewares bound to the pre-initialised clerkClient
*/
export const ClerkExpressRequireAuth = (...args: any) => {
export const ClerkExpressRequireAuth = (...args: Parameters<ReturnType<typeof createClerkExpressRequireAuth>>) => {
const env = { ...loadApiEnv(), ...loadClientEnv() };
const fn = createClerkExpressRequireAuth({ clerkClient, ...env });
return fn(...args);
};

export const ClerkExpressWithAuth = (...args: any) => {
export const ClerkExpressWithAuth = (...args: Parameters<ReturnType<typeof createClerkExpressWithAuth>>) => {
const env = { ...loadApiEnv(), ...loadClientEnv() };
const fn = createClerkExpressWithAuth({ clerkClient, ...env });
return fn(...args);
Expand Down

0 comments on commit a605335

Please sign in to comment.