You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
export default function (options = {}) {
return function (hook) {
if (hook.type !== 'before') {
throw new Error(The 'associateCurrentUser' hook should only be used as a 'before' hook.);
}
if (!hook.params.user) {
if (!hook.params.provider) {
return hook;
}
throw new Error('There is no current user to associate.');
}
options = Object.assign({}, defaults, hook.app.get('authentication'), options);
const id = get(hook.params.user, options.idField);
if (id === undefined) {
throw new Error(`Current user is missing '${options.idField}' field.`);
}
function setId (obj) {
set(obj, options.as, id);
}
// Handle arrays.
if (Array.isArray(hook.data)) {
hook.data.forEach(setId);
// Handle single objects.
} else {
setId(hook.data);
}
associate-current-user.js
import get from 'lodash.get';
import set from 'lodash.set';
const defaults = {
idField: '_id',
as: 'userId'
};
export default function (options = {}) {
return function (hook) {
if (hook.type !== 'before') {
throw new Error(
The 'associateCurrentUser' hook should only be used as a 'before' hook.
);}
};
}
package .json
{
"name": "newapp",
"description": "",
"version": "0.0.0",
"homepage": "",
"main": "src",
"keywords": [
"feathers"
],
"author": {
"name": "jpca999",
"email": "[email protected]"
},
"contributors": [],
"bugs": {},
"directories": {
"lib": "src",
"test": "test/"
},
"engines": {
"node": ">= 6.0.0",
"yarn": ">= 0.18.0"
},
"scripts": {
"test": "npm run eslint && npm run mocha",
"eslint": "eslint src/. test/. --config .eslintrc.json",
"start": "node src/",
"mocha": "mocha test/ --recursive"
},
"dependencies": {
"body-parser": "^1.18.2",
"compression": "^1.7.1",
"cors": "^2.8.4",
"feathers": "^2.2.3",
"feathers-authentication": "^1.3.0",
"feathers-authentication-hooks": "^0.1.5",
"feathers-authentication-jwt": "^0.3.2",
"feathers-authentication-local": "^0.4.4",
"feathers-configuration": "^0.4.2",
"feathers-errors": "^2.9.2",
"feathers-hooks": "^2.1.1",
"feathers-hooks-common": "^3.10.0",
"feathers-mongodb": "^2.9.1",
"feathers-nedb": "^2.7.0",
"feathers-rest": "^1.8.0",
"feathers-socketio": "^2.0.0",
"helmet": "^3.9.0",
"lodash": "^4.17.4",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
"mongodb": "^2.2.33",
"nedb": "^1.8.0",
"serve-favicon": "^2.4.5",
"winston": "^2.4.0"
},
"devDependencies": {
"eslint": "^4.9.0",
"mocha": "^4.0.1",
"request": "^2.83.0",
"request-promise": "^4.2.2"
}
}
The text was updated successfully, but these errors were encountered: