diff --git a/api/src/constants/index.ts b/api/src/constants/index.ts index 4042ff6e6..757db7391 100644 --- a/api/src/constants/index.ts +++ b/api/src/constants/index.ts @@ -70,7 +70,10 @@ export const HTTP_TEXTS = { "Reseting the content mapping is restricted. Please verify the status and review preceding actions.", CONTENTMAPPER_NOT_FOUND: "Sorry, the requested content mapper id does not exists.", + ADMIN_LOGIN_ERROR: + "Sorry, You Don't have admin access in any of the Organisation" }; + export const HTTP_RESPONSE_HEADERS = { "Access-Control-Allow-Origin": "*", "Content-Type": "application/json", diff --git a/api/src/services/auth.service.ts b/api/src/services/auth.service.ts index 8aba3358c..5b551ff1c 100644 --- a/api/src/services/auth.service.ts +++ b/api/src/services/auth.service.ts @@ -24,7 +24,7 @@ const login = async (req: Request): Promise => { method: "POST", url: `${config.CS_API[ userData?.region as keyof typeof config.CS_API - ]!}/user-session`, + ]!}/user-session?include_orgs_roles=true`, headers: { "Content-Type": "application/json", }, @@ -48,6 +48,12 @@ const login = async (req: Request): Promise => { status: err?.response?.status, }; } + const orgs = (res?.data?.user?.organizations || []) + ?.filter((org: any) => org?.org_roles?.some((item: any) => item.admin)) + ?.map(({ uid, name }: any) => ({ org_id: uid, org_name: name })); + if (!orgs.length) { + throw new BadRequestError(HTTP_TEXTS.ADMIN_LOGIN_ERROR); + } if (res?.status === HTTP_CODES.SUPPORT_DOC) return {