UNPKG

bootstrap-eileen-koelpin

Version:

A project template using Express.js as a Node.js framework.

27 lines (22 loc) 592 B
const passport = require('passport'); const { BasicStrategy } = require('passport-http'); const Auth = require('./auth'); passport.use( new BasicStrategy((username, password, cb) => { Auth.findByUsername(username, (user) => { if (!user) { return cb(null, false); } if (!user.isValidPassword(password)) { return cb(null, false); } return cb(null, user); }); }), ); const isAuthenticated = passport.authenticate('basic', { session: false }); const init = () => passport.initialize(); module.exports = { isAuthenticated, init };