Simply authentication for express based on Sequelize.
npm i 2max-express-authenticate --save
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);
Method | endpoint | Body |
---|---|---|
POST | /signup | {username, password} |
POST | /login | {username, password} |
GET | /logout | N/A |
- 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
- Add roles checking (bitmask)
- Secure route according to roles
- User can add role