grpc-shared
Advanced tools
Comparing version 1.0.38 to 1.0.39
@@ -0,1 +1,2 @@ | ||
import { OrganizationModel } from "@alpha.apps/pemo-proto/lib/organization/organization.pb"; | ||
import { UserModel } from "@alpha.apps/pemo-proto/lib/user/user.pb"; | ||
@@ -5,3 +6,3 @@ import { Metadata } from "@grpc/grpc-js"; | ||
export declare function getUserFromMetadata(metadata: Metadata): UserModel; | ||
export declare function getOrganizationFromMetadata(metadata: Metadata): import("@grpc/grpc-js").MetadataValue; | ||
export declare function getOrganizationFromMetadata(metadata: Metadata): OrganizationModel; | ||
export declare function getIsBackOfficeFromMetadata(metadata: Metadata): any; |
@@ -23,7 +23,23 @@ "use strict"; | ||
function getOrganizationFromMetadata(metadata) { | ||
const [subdomain] = metadata.get(constants_1.SUBDOMAIN); | ||
if (!subdomain) { | ||
// no sub domain presented exception | ||
const [isBackoffice] = metadata.get(constants_1.IS_BACKOFFICE); | ||
if (isBackoffice) { | ||
const [org] = metadata.get('organization'); | ||
if (!org) { | ||
throw new grpc_exceptions_1.UnauthorizedException(); | ||
} | ||
return JSON.parse(org); | ||
} | ||
return subdomain; | ||
const [subdomain] = metadata.get('subdomain'); | ||
const [striginfiedUser] = metadata.get('user'); | ||
if (!striginfiedUser) { | ||
throw new grpc_exceptions_1.UnauthenticatedException(); | ||
} | ||
const user = JSON.parse(striginfiedUser); | ||
const organization = user.organizations.filter((organization) => { | ||
return organization.businessName === subdomain; | ||
})[0]; | ||
if (!organization) { | ||
throw new grpc_exceptions_1.UnauthorizedException(); | ||
} | ||
return organization; | ||
} | ||
@@ -30,0 +46,0 @@ exports.getOrganizationFromMetadata = getOrganizationFromMetadata; |
{ | ||
"name": "grpc-shared", | ||
"version": "1.0.38", | ||
"version": "1.0.39", | ||
"description": "shared logic between services", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
17646
376