Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
],
remove: [
auth.hooks.authenticate('jwt')
]
}
});
// Add a hook to the user service that automatically replaces
// the password with a hash of the password before saving it.
app.service('users').hooks({
before: {
find: [
auth.hooks.authenticate('jwt')
],
create: [
local.hooks.hashPassword({ passwordField: 'password' })
]
}
});
// Create a user that we can use to log in
app.service('users').create(User).catch(console.error);
// Custom Express routes
app.get('/protected', auth.express.authenticate('jwt'), (req, res, next) => {
res.json({ success: true });
});
app.get('/unprotected', (req, res, next) => {
res.json({ success: true });
});
// Hooks for service `users1`. (Can be re-generated.)
const commonHooks = require('feathers-hooks-common');
const { authenticate } = require('@feathersjs/authentication').hooks;
// eslint-disable-next-line no-unused-vars
const { hashPassword, protect } = require('@feathersjs/authentication-local').hooks;
// !code: imports // !end
// ! code: used
// eslint-disable-next-line no-unused-vars
const { iff } = commonHooks;
// eslint-disable-next-line no-unused-vars
const { create, update, patch, validateCreate, validateUpdate, validatePatch } = require('./users1.validate');
// !end
// !code: init // !end
let moduleExports = {
before: {
// Your hooks should include:
// find : authenticate('jwt')
// get : authenticate('jwt')
},
async update() {
return []
},
async remove() {
return []
},
})
app.service('users').hooks({
before: {
create: [
local.hooks.hashPassword(),
]
},
after: local.hooks.protect('password')
})
app.service('authentication').hooks({
before: {
create: [
// You can chain multiple strategies
auth.hooks.authenticate(['local']),
],
remove: [
auth.hooks.authenticate('jwt')
]
}
});
import * as feathersAuthentication from '@feathersjs/authentication';
import * as local from '@feathersjs/authentication-local';
// Don't remove this comment. It's needed to format import lines nicely.
const { authenticate } = feathersAuthentication.hooks;
const { hashPassword, protect } = local.hooks;
export default {
before: {
all: [],
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ hashPassword('password') ],
update: [ hashPassword('password'), authenticate('jwt') ],
patch: [ hashPassword('password'), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
},
after: {
all: [
// Make sure the password field is never sent to the client
// Always must be the last hook
return []
},
async remove() {
return []
},
})
app.service('users').hooks({
before: {
create: [
local.hooks.hashPassword(),
]
},
after: local.hooks.protect('password')
})
app.service('authentication').hooks({
before: {
create: [
// You can chain multiple strategies
auth.hooks.authenticate(['local']),
],
remove: [
auth.hooks.authenticate('jwt')
]
}
});
}
const { authenticate } = require('@feathersjs/authentication').hooks;
const {
hashPassword, protect
} = require('@feathersjs/authentication-local').hooks;
module.exports = {
before: {
all: [],
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [ hashPassword() ],
update: [ hashPassword(), authenticate('jwt') ],
patch: [ hashPassword(), authenticate('jwt') ],
remove: [ authenticate('jwt') ]
},
after: {
all: [
// Make sure the password field is never sent to the client
// Always must be the last hook
/* eslint-env node */
/* eslint no-param-reassign: 0 */
const bcrypt = require('bcryptjs');
const crypto = require('crypto');
const auth = require('@feathersjs/authentication-local').hooks;
const errors = require('@feathersjs/errors');
const debug = require('debug')('authManagement:helpers');
const hashPassword = (app1, password) => {
const hook = {
type: 'before',
data: { password },
params: { provider: null },
app: {
get (str) {
return app1.get(str);
}
}
};
return auth.hashPassword()(hook)
const { authenticate } = require('@feathersjs/authentication').hooks;
const commonHooks = require('feathers-hooks-common');
const { restrictToOwner } = require('feathers-authentication-hooks');
const { hashPassword } = require('@feathersjs/authentication-local').hooks;
const restrict = [
authenticate('jwt'),
restrictToOwner({
idField: '_id',
ownerField: '_id'
})
];
module.exports = {
before: {
all: [],
find: [ authenticate('jwt') ],
get: [ ...restrict ],
create: [ hashPassword() ],
update: [ ...restrict, hashPassword() ],
patch: [ ...restrict, hashPassword() ],
const { restrictToOwner } = require('feathers-authentication-hooks');
const { addVerification, removeVerification } = require('feathers-authentication-management').hooks;
const sendVerificationEmail = require('./hooks/send-verification-email');
const restrictUserRole = require('./hooks/restrict-user-role');
const createAdmin = require('./hooks/create-admin');
const createSlug = require('../../hooks/create-slug');
const thumbnails = require('../../hooks/thumbnails');
const isModerator = require('../../hooks/is-moderator-boolean');
const isSingleItem = require('../../hooks/is-single-item');
const inviteCode = require('./hooks/invite-code')();
const search = require('feathers-mongodb-fuzzy-search');
const isOwnEntry = require('./hooks/is-own-entry');
const removeAllRelatedUserData = require('./hooks/remove-all-related-user-data');
const { hashPassword } = require('@feathersjs/authentication-local').hooks;
const cleanupBasicData = protect('password', '_computed', 'verifyExpires', 'resetExpires', 'verifyChanges');
const cleanupPersonalData = protect('email', 'verifyToken', 'verifyShortToken', 'doiToken', 'systemNotificationsSeen');
const restrict = [
restrictToOwner({
idField: '_id',
ownerField: '_id'
})
];
const badgesSchema = {
include: {
service: 'badges',
nameAs: 'badges',
parentField: 'badgeIds',
const { authenticate } = require('@feathersjs/authentication').hooks;
const verifyHooks = require('feathers-authentication-management').hooks;
const accountService = require('../authmanagement/notifier');
const commonHooks = require('feathers-hooks-common');
const {
hashPassword, protect
} = require('@feathersjs/authentication-local').hooks;
module.exports = {
before: {
all: [],
find: [ authenticate('jwt') ],
get: [ authenticate('jwt') ],
create: [
hashPassword(),
verifyHooks.addVerification()
],
update: [
commonHooks.disallow('external')
],
patch: [
commonHooks.iff(
commonHooks.isProvider('external'),