seneca-local-auth

raw JSON →
0.1.2 verified Sat Apr 25 auth: no javascript maintenance

Local authentication plugin for Seneca.js, providing local strategy support via PassportJS. Current stable version 0.1.2. This plugin is designed to be used with seneca-auth and Seneca toolkit. It handles username/password authentication, session management, and user registration. Tested on Seneca 0.8 and 0.9, Node 4 and 5. Key differentiator: integrates seamlessly with seneca-auth's plugin architecture and message patterns for authentication.

error Error: Cannot find module 'seneca-auth'
cause Missing required peer dependency seneca-auth.
fix
Run 'npm install seneca-auth seneca' in your project.
error Error: role:auth, cmd:login - No handler for role:auth, cmd:login
cause seneca-auth plugin not registered before using local-auth.
fix
Ensure the 'auth' plugin is used before 'local-auth': seneca.use('auth').use('local-auth')
breaking Plugin is only compatible with Seneca 0.8, 0.9 and Node 4, 5. Not updated for newer versions.
fix Consider migrating to seneca-auth with a different strategy or updating the plugin code for newer Seneca.
deprecated Package has not been updated since 2014-2015. Low maintenance.
fix Evaluate alternatives or consider forking the project.
gotcha Requires seneca-auth as a peer dependency; must call seneca.use('auth') before seneca.use('local-auth').
fix Always register 'auth' plugin before 'local-auth'.
npm install seneca-local-auth
yarn add seneca-local-auth
pnpm add seneca-local-auth

Demonstrates how to set up and use local authentication with seneca-auth and seneca-local-auth, including user registration and login.

const Seneca = require('seneca');
const seneca = Seneca();

seneca.use('auth', {
  redirect: {
    login: '/login',
    register: '/register'
  }
});

seneca.use('local-auth', {
  login: {
    fields: ['username', 'password']
  },
  register: {
    fields: ['username', 'password'],
    confirm: true
  }
});

seneca.act('role:auth, cmd:register', {
  username: 'admin',
  password: process.env.PASSWORD || 'secret'
}, (err, user) => {
  if (err) console.error(err);
  else console.log('User registered');
});

seneca.act('role:auth, cmd:login', {
  username: 'admin',
  password: process.env.PASSWORD || 'secret'
}, (err, login) => {
  if (err) console.error(err);
  else console.log('Login successful', login);
});