From a6451aecef0bac578b295b524f1246dede3a7598 Mon Sep 17 00:00:00 2001 From: Bryce Kalow Date: Thu, 9 Nov 2023 14:27:53 -0500 Subject: [PATCH] fix(backend): strip experimental__has from serializable auth object (#2101) * fix(backend): Add experimental__has to properties strip out by makeAuthObjectSerializable * chore(backend): Add test case for makeAuthObjectSerializable * chore(repo): Add changeset --- .changeset/weak-elephants-grin.md | 5 +++++ .../backend/src/tokens/authObjects.test.ts | 18 ++++++++++++++++++ packages/backend/src/tokens/authObjects.ts | 2 +- packages/backend/tests/suites.ts | 2 ++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .changeset/weak-elephants-grin.md create mode 100644 packages/backend/src/tokens/authObjects.test.ts diff --git a/.changeset/weak-elephants-grin.md b/.changeset/weak-elephants-grin.md new file mode 100644 index 0000000000..89b179af58 --- /dev/null +++ b/.changeset/weak-elephants-grin.md @@ -0,0 +1,5 @@ +--- +'@clerk/backend': patch +--- + +Strip `experimental__has` from the auth object in `makeAuthObjectSerializable()`. This fixes an issue in Next.js where an error is being thrown when this function is passed to a client component as a prop. diff --git a/packages/backend/src/tokens/authObjects.test.ts b/packages/backend/src/tokens/authObjects.test.ts new file mode 100644 index 0000000000..0f29fbefcc --- /dev/null +++ b/packages/backend/src/tokens/authObjects.test.ts @@ -0,0 +1,18 @@ +import type QUnit from 'qunit'; + +import { makeAuthObjectSerializable, signedOutAuthObject } from './authObjects'; + +export default (QUnit: QUnit) => { + const { module, test } = QUnit; + + module('makeAuthObjectSerializable', () => { + test('removes non-serializable props', assert => { + const authObject = signedOutAuthObject(); + const serializableAuthObject = makeAuthObjectSerializable(authObject); + + for (const key in serializableAuthObject) { + assert.notStrictEqual(typeof serializableAuthObject[key], 'function'); + } + }); + }); +}; diff --git a/packages/backend/src/tokens/authObjects.ts b/packages/backend/src/tokens/authObjects.ts index c9096b6b85..1822b9c207 100644 --- a/packages/backend/src/tokens/authObjects.ts +++ b/packages/backend/src/tokens/authObjects.ts @@ -192,7 +192,7 @@ export function sanitizeAuthObject>(authObject: T): T export const makeAuthObjectSerializable = >(obj: T): T => { // remove any non-serializable props from the returned object - const { debug, getToken, ...rest } = obj as unknown as AuthObject; + const { debug, getToken, experimental__has, ...rest } = obj as unknown as AuthObject; return rest as unknown as T; }; diff --git a/packages/backend/tests/suites.ts b/packages/backend/tests/suites.ts index 6f9d836936..10ceb49a25 100644 --- a/packages/backend/tests/suites.ts +++ b/packages/backend/tests/suites.ts @@ -4,6 +4,7 @@ import apiTest from './dist/api/factory.test.js'; import factoryTest from './dist/api/factory.test.js'; import exportsTest from './dist/exports.test.js'; import redirectTest from './dist/redirections.test.js'; +import authObjectsTest from './dist/tokens/authObjects.test.js'; import interstitialRequestTest from './dist/tokens/interstitial.test.js'; import jwtAssertionsTest from './dist/tokens/jwt/assertions.test.js'; import cryptoKeysTest from './dist/tokens/jwt/cryptoKeys.test.js'; @@ -19,6 +20,7 @@ import utilsTest from './dist/utils.test.js'; // Add them to the suite array const suites = [ apiTest, + authObjectsTest, exportsTest, jwtAssertionsTest, requestTest,