All files / node-user-accounts-boilerplate-nahid/auth NoAuth.js

100% Statements 8/8
33.33% Branches 1/3
100% Functions 4/4
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49    1x 1x                                 44x         44x                   44x   20x       20x           1x  
"use strict";
 
const Auth = require('./Auth');
const audit = require('../helper/audit');
 
/**
 * Allows login without any form of credential exchange.
 *
 * Meant for testing / developer debugging etc.
 */
class NoAuth extends Auth
{
 
  /**
   * @param {object} options options
   * @param {string} [options.method='nothing'] method name
   * @param {string} options.loginUserId id of user to give access of
   */
  constructor(options = {})
  {
    super(options.method || 'nothing', options);
 
    /**
     * @type string
     */
    this.loginUserId = options.loginUserId;
  }
 
  /**
   * Make any request to /<method>/login.json to gain access.
   *
   * @override
   */
  install(app, prefix)
  {
    app.all(`${prefix}/login.json`, (req, res) =>
    {
      req.login({
        id: this.loginUserId
      }, function (err)
      {
        res.success('Logged in', audit.LOGIN);
      });
    });
  }
}
 
module.exports = NoAuth;