Memo app bridge & improved registerHandler error message (#237)
* Add token exp validaiton * revert lock * Improved registerHandler error message and wrap useAuthenticatedFetch with memo
This commit is contained in:
parent
da351faae9
commit
62e4c39335
4 changed files with 16 additions and 3 deletions
5
.changeset/brown-rats-eat.md
Normal file
5
.changeset/brown-rats-eat.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@saleor/app-sdk": patch
|
||||
---
|
||||
|
||||
Registed Handler now prints saleorApiUrl in error response, so its available in dashboard toast
|
5
.changeset/gold-guests-buy.md
Normal file
5
.changeset/gold-guests-buy.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@saleor/app-sdk": patch
|
||||
---
|
||||
|
||||
Wrapped useAuthenticatedFetch with useMemo to avoid re-renders
|
|
@ -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]);
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue