2max-express-authenticate 中文文档教程
Express authenticate
基于Sequelize的express简单认证。
Install
npm i 2max-express-authenticate --save
Configuration
const express = require('express');
const app = express();
const auth = require('2max-express-authenticate');
async function main(app) {
// Declare auth + configure for persistence
const util = await auth(app, {
'persistence': {
'host': process.env.MYSQL_HOST,
'user': process.env.MYSQL_USER,
'password': process.env.MYSQL_PASSWORD,
'database': process.env.MYSQL_DATABASE,
'dialect': 'mysql'
}
});
// Secure yours routes with auth
util.secure([
'/admin',
'/dashboard',
...
]);
// Override connection method for send custom results
util.override({
'login': (req, res) => {
res.send('Congrats');
},
'logout': (req, res) => {
res.send('OUT');
},
'signup': (req, res) => {
res.send('Good job mother fucker men');
}
});
}
app.listen(80);
Route
Method | endpoint | Body |
---|---|---|
POST | /signup | {username, password} |
POST | /login | {username, password} |
GET | /logout | N/A |
Features
- Crypt password with bcrypt
- Login, logout and signup (cookies + session)
- Persist data (according to sequelize compatibility)
- Give array with route to check session for each route
- Enable middlewares for set response from /login, /logout and /signup
Todo
- Add roles checking (bitmask)
- Secure route according to roles
- User can add role
Express authenticate
Simply authentication for express based on Sequelize.
Install
npm i 2max-express-authenticate --save
Configuration
const express = require('express');
const app = express();
const auth = require('2max-express-authenticate');
async function main(app) {
// Declare auth + configure for persistence
const util = await auth(app, {
'persistence': {
'host': process.env.MYSQL_HOST,
'user': process.env.MYSQL_USER,
'password': process.env.MYSQL_PASSWORD,
'database': process.env.MYSQL_DATABASE,
'dialect': 'mysql'
}
});
// Secure yours routes with auth
util.secure([
'/admin',
'/dashboard',
...
]);
// Override connection method for send custom results
util.override({
'login': (req, res) => {
res.send('Congrats');
},
'logout': (req, res) => {
res.send('OUT');
},
'signup': (req, res) => {
res.send('Good job mother fucker men');
}
});
}
app.listen(80);
Route
Method | endpoint | Body |
---|---|---|
POST | /signup | {username, password} |
POST | /login | {username, password} |
GET | /logout | N/A |
Features
- Crypt password with bcrypt
- Login, logout and signup (cookies + session)
- Persist data (according to sequelize compatibility)
- Give array with route to check session for each route
- Enable middlewares for set response from /login, /logout and /signup
Todo
- Add roles checking (bitmask)
- Secure route according to roles
- User can add role