Skip to content
Merged

Dev #88

Changes from 1 commit
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
Prev Previous commit
Next Next commit
apply admin role cond in login api
  • Loading branch information
shristi-sinha committed May 6, 2024
commit c70c7ec306ba07b48e9038aba399d537b60156e2
17 changes: 12 additions & 5 deletions api/src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@ 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?.data?.user?.organizations === undefined) {
return {
data: res?.data,
status: res?.status,
};
} else {
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)
Expand Down