diff --git a/app/(prowler)/providers/(set-up-provider)/test-connection/page.tsx b/app/(prowler)/providers/(set-up-provider)/test-connection/page.tsx index 4a3f3a7f15..13cac50f6d 100644 --- a/app/(prowler)/providers/(set-up-provider)/test-connection/page.tsx +++ b/app/(prowler)/providers/(set-up-provider)/test-connection/page.tsx @@ -31,6 +31,9 @@ async function SSRTestConnection({ formData.append("id", searchParams.id); const providerData = await getProvider(formData); + if (providerData.errors) { + redirect("/providers/connect-account"); + } return ( new Promise((resolve) => setTimeout(resolve, ms)); // Helper function to create dictionaries by type -export const createDict = ( - type: string, - data: any, - includedField: string = "included", -) => - Object.fromEntries( - data[includedField] - .filter((item: { type: string }) => item.type === type) - .map((item: { id: string }) => [item.id, item]), +export function createDict(type: string, data: any) { + const includedField = data?.included?.filter( + (item: { type: string }) => item.type === type, ); + if (!includedField || includedField.length === 0) { + return {}; + } + + return Object.fromEntries( + includedField.map((item: { id: string }) => [item.id, item]), + ); +} + export const parseStringify = (value: any) => JSON.parse(JSON.stringify(value)); export const convertFileToUrl = (file: File) => URL.createObjectURL(file);