Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
isProvider();
// $ExpectType Hook>
keep('abc', 'def');
// $ExpectType Hook>
keepInArray('array', ['fieldName', 'fieldName']);
// $ExpectType Hook>
keepQuery('name', 'address.city');
// $ExpectType Hook>
keepQueryInArray('array', ['fieldName', 'fieldName']);
// $ExpectType Hook>
lowerCase('email', 'username', 'div.dept');
// $ExpectType Params
makeCallingParams(
context1,
{ id: { $in: [1, 2, 3] } },
'user',
{ _populate: false, mongoose: {} }
);
// tslint:disable-next-line
class ObjId {
// tslint:disable-next-line
constructor(id?: string | number) { }
}
// $ExpectType Hook>
module.exports = function () {
const app = this;
const config = app.get('authentication');
// Set up authentication with the secret
app.configure(authentication(config));
app.configure(jwt());
app.configure(local(config.local));
// The `authentication` service is used to create a JWT.
// The before `create` hook registers strategies that can be used
// to create a new valid JWT (e.g. local or oauth2)
app.service('authentication').hooks({
before: {
create: [
lowerCase('email', 'username'),
authentication.hooks.authenticate(config.strategies)
],
remove: [
authentication.hooks.authenticate('jwt')
]
}
});
app.on('login', (result, meta) => {
try {
if (meta.connection && meta.connection.user) {
// update last active timestamp on loggedin user
app.service('users').patch(meta.connection.user, {
lastActiveAt: new Date()
});
}
saveRemoteImages(['avatar', 'coverImg'])
],
update: [
...restrict,
hashPassword(),
disableMultiItemChange(),
lowerCase('email', 'username'),
when(isProvider('external'),
restrictUserRole()
),
saveRemoteImages(['avatar', 'coverImg'])
],
patch: [
...restrict,
disableMultiItemChange(),
lowerCase('email', 'username'),
// Only set slug once
when(
hook => {
return hook.params && hook.params.user && !hook.params.user.slug;
},
createSlug({ field: 'name' })
),
when(isProvider('external'),
restrictUserRole()
),
saveRemoteImages(['avatar', 'coverImg'])
],
remove: [
...restrict,
disableMultiItemChange(),
removeAllRelatedUserData()
auth.populateUser(),
auth.restrictToAuthenticated(),
globalHooks.isEnabled(),
globalHooks.hasPermission('manageUsers')
],
get: [
auth.verifyToken(),
auth.populateUser(),
auth.restrictToAuthenticated(),
globalHooks.isEnabled(),
globalHooks.hasPermission('manageUsers')
// auth.restrictToOwner({ ownerField: '_id' })
],
create: [
auth.hashPassword(),
common.lowerCase('email'),
verifyHooks.addVerification(),
globalHooks.setDefaultRole(),
globalHooks.setFirstUserToRole({role: 'admin'})
],
update: [
auth.verifyToken(),
auth.populateUser(),
auth.restrictToAuthenticated(),
globalHooks.isEnabled(),
globalHooks.hasPermissionOrRestrictChanges('manageUsers', {
restrictOn: ['role', 'isEnabled']
}),
globalHooks.preventDisabledAdmin()
],
patch: [
auth.verifyToken(),
const isAdmin = require('../../hooks/is-admin');
const sendInviteEmail = require('./hooks/send-invite-email');
const restrictAPIToAdmin = when(isProvider('external'),
isAdmin()
);
module.exports = {
before: {
all: [
restrictAPIToAdmin
],
find: [],
get: [],
create: [
lowerCase('email', 'username')
],
update: [],
patch: [],
remove: []
},
after: {
all: [],
find: [],
get: [],
create: [
sendInviteEmail()
],
update: [],
patch: [],
remove: []