From 08d3b19c2829ccdc9f25dfde589e1fde0fca14ba Mon Sep 17 00:00:00 2001 From: Jose Flores Date: Tue, 1 Jul 2025 18:12:19 -0400 Subject: [PATCH 1/2] fix(authorize): return null instead of undefined from getRegion when region is false Fixes React Query error 'Query data cannot be undefined' when useAuthorize hook is called with region: false parameter. Changed getRegion function to return null instead of undefined to comply with React Query requirements. Fixes #1584 --- packages/authorize/src/api.test.ts | 4 ++-- packages/authorize/src/api.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/authorize/src/api.test.ts b/packages/authorize/src/api.test.ts index a7d82e6cb3..a55b864cc7 100644 --- a/packages/authorize/src/api.test.ts +++ b/packages/authorize/src/api.test.ts @@ -16,9 +16,9 @@ describe('authorize api', () => { expect(region).toBe('FL'); }); - test('getRegion returns undefined when given falsey value', async () => { + test('getRegion returns null when given falsey value', async () => { const region = await getRegion(false); - expect(region).toBeUndefined(); + expect(region).toBeNull(); }); test('getRegion returns value when not falsey', async () => { diff --git a/packages/authorize/src/api.ts b/packages/authorize/src/api.ts index 3a1aae1628..9963ec0b60 100644 --- a/packages/authorize/src/api.ts +++ b/packages/authorize/src/api.ts @@ -7,14 +7,14 @@ import type { Permission, RequestedPermissions, RequestedResources } from './typ * * If the region is a string then it will be returned without fetching. */ -export const getRegion = async (region?: boolean | string): Promise => { +export const getRegion = async (region?: boolean | string): Promise => { if (region === true) { const resp = await avRegionsApi.getCurrentRegion(); - return resp?.data?.regions?.[0]?.id; + return resp?.data?.regions?.[0]?.id || null; } - return region || undefined; + return region || null; }; /** From a7df1879ef33460d6476d9bb7fbcefa17e16f80a Mon Sep 17 00:00:00 2001 From: Jose Flores Date: Wed, 2 Jul 2025 10:24:25 -0400 Subject: [PATCH 2/2] fix(authorize): TypeScript build errors --- packages/authorize/src/api.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/authorize/src/api.ts b/packages/authorize/src/api.ts index 9963ec0b60..81af036b5c 100644 --- a/packages/authorize/src/api.ts +++ b/packages/authorize/src/api.ts @@ -22,12 +22,12 @@ export const getRegion = async (region?: boolean | string): Promise> => { if (!permissions) return {}; // TODO: fix these types - const response = await avUserPermissionsApi.getPermissions(permissions as string[], region); + const response = await avUserPermissionsApi.getPermissions(permissions as string[], region || undefined); return response.reduce>((prev, cur) => { prev[cur.id] = cur; @@ -91,7 +91,7 @@ export const checkPermission = ( */ export const checkPermissions = async ( permissions: RequestedPermissions, - region?: string, + region?: string | null, resources?: RequestedResources, organizationId?: string, customerId?: string