How to use the @feathersjs/authentication-local.hooks function in @feathersjs/authentication-local

To help you get started, we’ve selected a few @feathersjs/authentication-local examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github feathersjs-ecosystem / authentication / test / fixtures / server.js View on Github external
],
      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 });
  });
github feathers-plus / generator-feathers-plus / test-expands / cumulative-2-test-auth.test-expected / src1 / services / users1 / users1.hooks.js View on Github external
// 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')
github nesterow / frontless / services / users.js View on Github external
},

    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')
     ]
    }
   });
github mariusandra / insights / packages / insights-api / src / services / users / users.hooks.ts View on Github external
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
github nesterow / frontless / services / users.js View on Github external
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')
     ]
    }
   });

}
github silvestreh / feathers-nuxt / src / services / users / users.hooks.js View on Github external
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
github feathers-plus / feathers-authentication-management / src / helpers.js View on Github external
/* 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)
github kalisio / feathers-distributed / example / gateway / src / services / users / users.hooks.js View on Github external
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() ],
github Human-Connection / API / server / services / users / users.hooks.js View on Github external
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',
github ImreC / feathers-verification-emails / src / services / users / users.hooks.js View on Github external
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'),