From 23db888c9084c8317d6c16a2b2db51983de7366a Mon Sep 17 00:00:00 2001 From: Stan Wohlwend Date: Sat, 13 Apr 2024 17:52:33 +0200 Subject: [PATCH] Fix: "The provided app JSON does not match the configuration" --- packages/stack-shared/src/utils/objects.tsx | 9 +++++++++ packages/stack/src/components/password-field.tsx | 2 +- packages/stack/src/lib/stack-app.ts | 10 ++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/stack-shared/src/utils/objects.tsx b/packages/stack-shared/src/utils/objects.tsx index 500cb0c77..12d123938 100644 --- a/packages/stack-shared/src/utils/objects.tsx +++ b/packages/stack-shared/src/utils/objects.tsx @@ -66,3 +66,12 @@ export function typedAssign(target: T, source: U): a export function filterUndefined(obj: T): { [k in keyof T]+?: T[k] & ({} | null) } { return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined)) as any; } + + +export function pick(obj: T, keys: K[]): Pick { + return Object.fromEntries(Object.entries(obj).filter(([k]) => keys.includes(k as K))) as any; +} + +export function omit(obj: T, keys: K[]): Omit { + return Object.fromEntries(Object.entries(obj).filter(([k]) => !keys.includes(k as K))) as any; +} diff --git a/packages/stack/src/components/password-field.tsx b/packages/stack/src/components/password-field.tsx index 7f6a1b5ec..46e9bb9f8 100644 --- a/packages/stack/src/components/password-field.tsx +++ b/packages/stack/src/components/password-field.tsx @@ -1,6 +1,6 @@ 'use client'; -import { Input } from "../components-core";; +import { Input } from "../components-core"; import { forwardRef, useRef, useState } from 'react'; import { HiEye, HiEyeOff } from 'react-icons/hi'; import { useDesign } from ".."; diff --git a/packages/stack/src/lib/stack-app.ts b/packages/stack/src/lib/stack-app.ts index bc599fdf0..a953f7dbe 100644 --- a/packages/stack/src/lib/stack-app.ts +++ b/packages/stack/src/lib/stack-app.ts @@ -12,7 +12,7 @@ import { callOAuthCallback, signInWithOAuth } from "./auth"; import { RedirectType, redirect, useRouter } from "next/navigation"; import { ReadonlyJson } from "@stackframe/stack-shared/dist/utils/json"; import { constructRedirectUrl } from "../utils/url"; -import { filterUndefined } from "@stackframe/stack-shared/dist/utils/objects"; +import { filterUndefined, omit, pick } from "@stackframe/stack-shared/dist/utils/objects"; import { neverResolve, resolved, runAsynchronously } from "@stackframe/stack-shared/dist/utils/promises"; import { AsyncCache } from "@stackframe/stack-shared/dist/utils/caches"; import { ApiKeySetBaseJson, ApiKeySetCreateOptions, ApiKeySetFirstViewJson, ApiKeySetJson, ProjectUpdateOptions } from "@stackframe/stack-shared/dist/interface/adminInterface"; @@ -708,10 +708,12 @@ class _StackClientAppImpl( json: StackClientAppJson ): StackClientApp => { + const providedCheckString = JSON.stringify(omit(json, ["currentClientUserJson", "currentProjectJson"])); const existing = allClientApps.get(json.uniqueIdentifier); if (existing) { - const [checkString, clientApp] = existing; - if (checkString !== JSON.stringify(json)) { + const [existingCheckString, clientApp] = existing; + if (existingCheckString !== providedCheckString) { + console.error("The provided app JSON does not match the configuration of the existing client app with the same unique identifier", { providedObj: json, existingString: existingCheckString }); throw new Error("The provided app JSON does not match the configuration of the existing client app with the same unique identifier"); } return clientApp as any; @@ -719,7 +721,7 @@ class _StackClientAppImpl({ ...json, - checkString: JSON.stringify(json), + checkString: providedCheckString, }); } };