From f6b44d74bfa534f791511d5cd7ea1909ef369e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Zori=C4=87?= Date: Thu, 10 Oct 2024 09:20:53 +0200 Subject: [PATCH 1/4] fix(app): when fetching tenant from local storage it has quotes --- packages/app/src/utils/getTenantId.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/app/src/utils/getTenantId.ts b/packages/app/src/utils/getTenantId.ts index 87d05092269..ce536d11ccb 100644 --- a/packages/app/src/utils/getTenantId.ts +++ b/packages/app/src/utils/getTenantId.ts @@ -10,19 +10,28 @@ export const getTenantId = (): string | null => { // 1. Get tenant via the `__tenant` query param. Useful when doing page previews. let tenant = new URLSearchParams(location.search).get("__tenant"); if (tenant) { + console.log("taking from query param"); return tenant; } // 2. Get tenant via `window.__PS_RENDER_TENANT__`. Used with prerendered pages. tenant = window.__PS_RENDER_TENANT__; if (tenant) { + console.log("__PS_RENDER_TENANT__"); return tenant; } // 3. Get tenant via `window.localStorage.webiny_tenant`. Used within the Admin app. tenant = window.localStorage.webiny_tenant; if (tenant) { - return tenant; + try { + const value = JSON.parse(tenant); + if (value) { + return value; + } + } finally { + return tenant.replace(/"/g, ""); + } } // 4. Finally, for development purposes, we take the `WEBINY_WEBSITE_TENANT_ID` From 079f34eb6616289f6a864a89d9c588e258827d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Zori=C4=87?= Date: Thu, 10 Oct 2024 09:41:50 +0200 Subject: [PATCH 2/4] fix(app): return inside a finally block --- packages/app/src/utils/getTenantId.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/src/utils/getTenantId.ts b/packages/app/src/utils/getTenantId.ts index ce536d11ccb..94f890afedd 100644 --- a/packages/app/src/utils/getTenantId.ts +++ b/packages/app/src/utils/getTenantId.ts @@ -29,7 +29,7 @@ export const getTenantId = (): string | null => { if (value) { return value; } - } finally { + } catch { return tenant.replace(/"/g, ""); } } From ceec6eb487228add56ed70c66452ba852e9b0306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Zori=C4=87?= Date: Thu, 10 Oct 2024 10:33:15 +0200 Subject: [PATCH 3/4] fix(app): remove console logs --- packages/app/src/utils/getTenantId.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/app/src/utils/getTenantId.ts b/packages/app/src/utils/getTenantId.ts index 94f890afedd..918702f6baa 100644 --- a/packages/app/src/utils/getTenantId.ts +++ b/packages/app/src/utils/getTenantId.ts @@ -10,14 +10,12 @@ export const getTenantId = (): string | null => { // 1. Get tenant via the `__tenant` query param. Useful when doing page previews. let tenant = new URLSearchParams(location.search).get("__tenant"); if (tenant) { - console.log("taking from query param"); return tenant; } // 2. Get tenant via `window.__PS_RENDER_TENANT__`. Used with prerendered pages. tenant = window.__PS_RENDER_TENANT__; if (tenant) { - console.log("__PS_RENDER_TENANT__"); return tenant; } From d48ada2fbe00472ee75cbbe8e043bb71d396daab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Zori=C4=87?= Date: Thu, 10 Oct 2024 11:02:49 +0200 Subject: [PATCH 4/4] fix(app): return statement outside of try catch block --- packages/app/src/utils/getTenantId.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/app/src/utils/getTenantId.ts b/packages/app/src/utils/getTenantId.ts index 918702f6baa..3a4f9f94e8c 100644 --- a/packages/app/src/utils/getTenantId.ts +++ b/packages/app/src/utils/getTenantId.ts @@ -28,8 +28,9 @@ export const getTenantId = (): string | null => { return value; } } catch { - return tenant.replace(/"/g, ""); + // do nothing } + return tenant; } // 4. Finally, for development purposes, we take the `WEBINY_WEBSITE_TENANT_ID`