egg-passport-local

local passport plugin for eggjs


Keywords
egg, eggPlugin, egg-plugin, egg-passport, passport
License
MIT
Install
npm install egg-passport-local@1.2.1

Documentation

egg-passport-local

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-passport-local --save

Usage

// {app_root}/config/plugin.js
exports.passport = {
    enable: true,
    package: 'egg-passport',
};

exports.passportLocal = {
    enable: true,
    package:'egg-passport-local',
};

// {app_root}/app.js
module.exports = app => {
    app.passport.verify(function* (ctx, user) {
        // 假设login请求是由form发送,带有参数username, password
        var user = yield ctx.service.user.findOne({name:user.username, pass:user.password});
        return user;
    });
};

// {app_root}/router.js
module.exports = app => {
    const options = {
        successRedirect:'/auth/admin',
        failureRedirect: '/login'
    };
    const local = app.passport.authenticate('local', options);
    app.post('/login', local);
};

License

MIT