From 009961513edaba39ad8fb4daacd6dd702a9fedd8 Mon Sep 17 00:00:00 2001 From: ryanwolhuter Date: Wed, 24 Apr 2024 11:58:26 +0200 Subject: [PATCH] feat: handle empty string or wrong formatted string in env var Signed-off-by: ryanwolhuter --- src/hooks/useIsAllowedToCreateDocuments.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hooks/useIsAllowedToCreateDocuments.ts b/src/hooks/useIsAllowedToCreateDocuments.ts index 20fe9eca..4067eca0 100644 --- a/src/hooks/useIsAllowedToCreateDocuments.ts +++ b/src/hooks/useIsAllowedToCreateDocuments.ts @@ -6,9 +6,15 @@ export function useIsAllowedToCreateDocuments() { const createDocumentAllowListEnvString = import.meta.env .VITE_CREATE_DOCUMENT_ALLOW_LIST; - const createDocumentAllowList = - createDocumentAllowListEnvString?.split(','); - if (createDocumentAllowList === undefined) { + if ( + createDocumentAllowListEnvString === undefined || + createDocumentAllowListEnvString === '' + ) { + return true; + } + + const createDocumentAllowList = createDocumentAllowListEnvString.split(','); + if (createDocumentAllowList.length === 0) { return true; }