How to use @feathersjs/authentication-local - 10 common examples

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 feathers-plus / generator-feathers-plus / test-expands / cumulative-1-mongo.test-expected / src1 / services / users-1 / users-1.hooks.js View on Github external
// ! code: before
    all: [],
    find: [ authenticate('jwt'), mongoKeys(ObjectID, foreignKeys) ],
    get: [ authenticate('jwt') ],
    create: [ hashPassword() ],
    update: [ hashPassword(), authenticate('jwt') ],
    patch: [ hashPassword(), authenticate('jwt') ],
    remove: [ authenticate('jwt') ]
    // !end
  },

  after: {
    // Your hooks should include:
    //   all   : protect('password') /* Must always be the last hook */
    // ! code: after
    all: [ protect('password') /* Must always be the last hook */ ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
    // !end
  },

  error: {
    // ! code: error
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
github feathers-plus / generator-feathers-plus / test-expands / authentication-2.test-expected / src1 / services / users-1 / users-1.hooks.js View on Github external
// ! code: before
    all: [],
    find: [ authenticate('jwt') ],
    get: [ authenticate('jwt') ],
    create: [ hashPassword() ],
    update: [ hashPassword(), authenticate('jwt') ],
    patch: [ hashPassword(), authenticate('jwt') ],
    remove: [ authenticate('jwt') ]
    // !end
  },

  after: {
    // Your hooks should include:
    //   all   : protect('password') /* Must always be the last hook */
    // ! code: after
    all: [ protect('password') /* Must always be the last hook */ ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
    // !end
  },

  error: {
    // ! code: error
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
github feathers-plus / generator-feathers-plus / test-expands / cumulative-6-generators.test-expected / src1 / services / users1 / users1.hooks.js View on Github external
// ! code: before
    all: [],
    find: [ authenticate('jwt') ],
    get: [ authenticate('jwt') ],
    create: [ hashPassword() ],
    update: [ hashPassword(), authenticate('jwt') ],
    patch: [ hashPassword(), authenticate('jwt') ],
    remove: [ authenticate('jwt') ]
    // !end
  },

  after: {
    // Your hooks should include:
    //   all   : protect('password') /* Must always be the last hook */
    // ! code: after
    all: [ protect('password') /* Must always be the last hook */ ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
    // !end
  },

  error: {
    // ! code: error
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
github feathers-plus / generator-feathers-plus / test-expands / cumulative-2-test-auth.test-expected / src1 / services / users1 / users1.hooks.js View on Github external
// ! code: before
    all: [],
    find: [ authenticate('jwt') ],
    get: [ authenticate('jwt') ],
    create: [ hashPassword() ],
    update: [ hashPassword(), authenticate('jwt') ],
    patch: [ hashPassword(), authenticate('jwt') ],
    remove: [ authenticate('jwt') ]
    // !end
  },

  after: {
    // Your hooks should include:
    //   all   : protect('password') /* Must always be the last hook */
    // ! code: after
    all: [ protect('password') /* Must always be the last hook */ ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
    // !end
  },

  error: {
    // ! code: error
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
github feathers-plus / generator-feathers-plus / test-expands / a-gens / ts / test-service.test-expected / src1 / authentication.ts View on Github external
let moduleExports = function (app: App) {
  const config = app.get('authentication');
  // !code: func_init // !end

  // Set up authentication with the secret
  app.configure(authentication(config));
  app.configure(jwt());
  app.configure(local());
  // !code: loc_1 // !end

  app.configure(oauth2(Object.assign({
    name: 'auth0',
    Strategy: Auth0Strategy,
    // !code: auth0_options // !end
  }, config.auth0)));

  app.configure(oauth2(Object.assign({
    name: 'google',
    Strategy: GoogleStrategy,
    // !code: google_options // !end
  }, config.google)));

  app.configure(oauth2(Object.assign({
    name: 'facebook',
github nesterow / frontless / components / server.js View on Github external
enabled: true,
    name: COOKIE_NAME,
    httpOnly: false,
    secure: false
  },
  jwt: {
    header: { typ: 'access' },
    audience: ORIGIN,
    subject: 'authentication',
    issuer: 'frontless',
    algorithm: 'HS256',
    expiresIn: '10d' // the access token expiry
   },
}))

app.configure(local({
  session: true,
  usernameField: 'username',
  passwordField: 'password',
  entityUsernameField: 'username', 
  entityPasswordField: 'password',
  Verifier,
}))

const dir = __dirname + '/..'
app.emit('setup:ssr', app)
app.use('/*@:args',  Frontless(dir, ['styles']))
app.use('/*',  Frontless(dir, ['styles']))

app.use((err, req, res, next) => {
  const {type, code} = err;
  if (type === 'FeathersError') {
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