jaumard/trailpack-passport

View on GitHub
api/services/protocols/local.js

Summary

Maintainability
A
0 mins
Test Coverage
'use strict'
const _ = require('lodash')

module.exports = (app) => {
  return (req, identifier, password, next) => {
    const criteria = {}
    const id = _.get(app, 'config.passport.strategies.local.options.usernameField')
    criteria[id || 'username'] = identifier

    app.services.PassportService.login(identifier, password)
      .then(user => next(null, user))
      .catch(next)
  }
}