egg-passport-local
Install
$ npm i egg-passport --save$ npm i egg-passport-local --save
Note: also need egg-passport .
Usage
// {app_root}/config/plugin.jsexportspassport = enable: true package: 'egg-passport'; exportspassportLocal = enable: true package: 'egg-passport-local';
Configuration
// {app_root}/config/config.default.jsexportspassportLocal = // usernameField: 'username', // passwordField: 'password',;
The available options are:
usernameField
- Optional, defaults tousername
passwordField
- Optional, defaults topassword
Both fields define the name of the properties in the POST body that are sent to the server.
see config/config.default.js for more detail.
after login successful, we can redirect to origin url by using ctx.session.returnTo
before go to login page, for example:
ctxsessioinreturnTo = ctxpath;
Example
see fixture for more detail.
// ./controller/home.js async { const ctx = thisctx; ctxbody = ` <div> <h2></h2> <a href="/admin">admin</a> </div> `; } async { const ctx = this; if ctx // show user info else // redirect to origin url by ctx.session.returnTo ctxsessionreturnTo = ctxpath; await ctx; } async { const ctx = thisctx; ctx; ctx; }
// router.jsmodule { approuter; approuter; const localStrategy = apppassport; approuter; approuter;};
see passport example for more detail.
Questions & Suggestions
Please open an issue here.