Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
apply cond on login api if user don't have admin role, then user is n…
…ot able to login
  • Loading branch information
shristi-sinha committed May 3, 2024
commit 47a3139480b6dd042f19295df8d01bf09fbd3ae8
3 changes: 3 additions & 0 deletions api/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion api/src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const login = async (req: Request): Promise<LoginServiceType> => {
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",
},
Expand All @@ -48,6 +48,12 @@ const login = async (req: Request): Promise<LoginServiceType> => {
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 {
Expand Down