UNPKG

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