/
token-cookie.js
65 lines (50 loc) · 1.53 KB
/
token-cookie.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict'
// external modules
var _ = require('lodash')
// default configuration
var Default_options = require('./default-options.js')
var HapiTokenCookie = require('./lib/hapi-token-cookie')
var ExpressTokenCookie = require('./lib/express-token-cookie')
var error = require('eraro')({
package: 'auth-token-cookie'
})
module.exports = function (options) {
var seneca = this
var internals = {}
internals.accepted_framworks = [
'express',
'hapi'
]
internals.options = _.extend({}, Default_options, options || {})
internals.choose_framework = function () {
if ('express' === internals.options.framework) {
internals.load_express_implementation()
}
else {
internals.load_hapi_implementation()
}
}
internals.check_options = function () {
if (seneca.options().plugin.web && seneca.options().plugin.web.framework) {
internals.options.framework = seneca.options().plugin.web.framework
}
if (_.indexOf(internals.accepted_framworks, internals.options.framework) === -1) {
throw error('Framework type <' + internals.options.framework + '> not supported.')
}
}
internals.load_express_implementation = function () {
ExpressTokenCookie(seneca, internals.options)
}
internals.load_hapi_implementation = function () {
HapiTokenCookie(seneca, internals.options)
}
function init (args, done) {
internals.check_options()
internals.choose_framework()
done()
}
seneca.add('init: auth-token-cookie', init)
return {
name: 'auth-token-cookie'
}
}