forked from rjmreis/hapi-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.js
35 lines (30 loc) · 763 Bytes
/
auth.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
exports.register = function (plugin, options, next) {
plugin.auth.strategy('jwt', 'jwt', {
key: 'NeverShareYourSecret', // Secret key
verifyOptions: {
algorithms: ['HS256']
},
// Implement validation function
validateFunc: (decoded, request, callback) => {
// NOTE: This is purely for demonstration purposes!
var users = [
{
id: 1,
name: 'Jon Snow'
}
];
if (users.find(u => u.id === decoded.id)) {
return callback(null, true);
}
else {
return callback(null, false);
}
}
});
// Uncomment this to apply default auth to all routes
//plugin.auth.default('jwt');
next();
};
exports.register.attributes = {
name: 'auth'
};