diff --git a/.changeset/brown-rats-eat.md b/.changeset/brown-rats-eat.md new file mode 100644 index 0000000..eb5b5a9 --- /dev/null +++ b/.changeset/brown-rats-eat.md @@ -0,0 +1,5 @@ +--- +"@saleor/app-sdk": patch +--- + +Registed Handler now prints saleorApiUrl in error response, so its available in dashboard toast diff --git a/.changeset/gold-guests-buy.md b/.changeset/gold-guests-buy.md new file mode 100644 index 0000000..6f3bd58 --- /dev/null +++ b/.changeset/gold-guests-buy.md @@ -0,0 +1,5 @@ +--- +"@saleor/app-sdk": patch +--- + +Wrapped useAuthenticatedFetch with useMemo to avoid re-renders diff --git a/src/app-bridge/fetch.ts b/src/app-bridge/fetch.ts index 2a7477d..3556d37 100644 --- a/src/app-bridge/fetch.ts +++ b/src/app-bridge/fetch.ts @@ -1,3 +1,5 @@ +import { useMemo } from "react"; + import { SALEOR_API_URL_HEADER, SALEOR_AUTHORIZATION_BEARER_HEADER, @@ -17,6 +19,7 @@ export const createAuthenticatedFetch = const { token, domain, saleorApiUrl } = appBridge.getState(); const headers = new Headers(init?.headers); + headers.set(SALEOR_DOMAIN_HEADER, domain); headers.set(SALEOR_AUTHORIZATION_BEARER_HEADER, token ?? ""); headers.set(SALEOR_API_URL_HEADER, saleorApiUrl ?? ""); @@ -39,5 +42,5 @@ export const useAuthenticatedFetch = (fetch = window.fetch): typeof window.fetch throw new Error("useAuthenticatedFetch can be used only in browser context"); } - return createAuthenticatedFetch(appBridge, fetch); + return useMemo(() => createAuthenticatedFetch(appBridge, fetch), [appBridge, fetch]); }; diff --git a/src/handlers/next/create-app-register-handler.ts b/src/handlers/next/create-app-register-handler.ts index 3dbc76d..0650525 100644 --- a/src/handlers/next/create-app-register-handler.ts +++ b/src/handlers/next/create-app-register-handler.ts @@ -190,8 +190,8 @@ export const createAppRegisterHandler = ({ return new Response( createRegisterHandlerResponseBody(false, { code: "UNKNOWN_APP_ID", - message: - "The auth data given during registration request could not be used to fetch app ID. This usually means that App could not connect to Saleor during installation", + message: `The auth data given during registration request could not be used to fetch app ID. + This usually means that App could not connect to Saleor during installation. Saleor URL that App tried to connect: ${saleorApiUrl}`, }), { status: 401,