This module is for the loopback framework. It add user's companyId to every read request's query.
NOTE! Adding companyId to request require active accessToken. It won't work with unauthorized routes. And you need to add options to request
{
"accepts": [
{
"arg": "options",
"type": "object",
"http": "optionsFromRequest"
}
]
}
npm i loopback-company-context-mixin --S
Add the mixins
property to your server/model-config.json
:
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"../node_modules/loopback-company-context-mixin",
"../common/mixins"
]
}
}
To use with your Models add the mixins
attribute to the definition object of your model config.
{
"name": "Widget",
"properties": {
"name": {
"type": "string",
}
},
"mixins": {
"CompanyContext" : true
}
}
You can use ignore option, if you want that mixin skip some of remote methods.
{
"name": "Member",
"mixins": {
"CompanyContext" : {
"ignore": [
"register",
"login",
"logout",
"resetPassword",
"invitationRequest"
]
}
},
"properties": {
"name": {
"type": "string",
}
},
}