pioneers-token-manager 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -5
- package/package.json +1 -1
- package/client.js +0 -0
- package/config.js +0 -22
- package/utilities/responseHandler.js +0 -13
package/index.js
CHANGED
@@ -11,15 +11,11 @@ class TokenManager {
|
|
11
11
|
}
|
12
12
|
verifyToken = (req, res, next) => {
|
13
13
|
const token = extractToken(req);
|
14
|
-
if (!token) {
|
15
|
-
sendFail(res, c.statusCodes.UNAUTHORIZED, { message: c.messages.invalidToken });
|
16
|
-
return;
|
17
|
-
}
|
18
14
|
try {
|
19
15
|
const decoded = jwt.verify(token, this.tokenKey);
|
20
16
|
req.user = decoded;
|
21
17
|
} catch (err) {
|
22
|
-
|
18
|
+
|
23
19
|
}
|
24
20
|
return next();
|
25
21
|
}
|
package/package.json
CHANGED
package/client.js
DELETED
File without changes
|
package/config.js
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
const statusCodes = {
|
2
|
-
SUCCESS: 200,
|
3
|
-
UNAUTHORIZED: 401
|
4
|
-
};
|
5
|
-
|
6
|
-
const contentTypes = {
|
7
|
-
JSON: 'application/json'
|
8
|
-
};
|
9
|
-
|
10
|
-
const errors = {};
|
11
|
-
|
12
|
-
const messages = {
|
13
|
-
loginFailed: 'Wrong username or password!',
|
14
|
-
invalidToken: 'Invalid token!',
|
15
|
-
};
|
16
|
-
|
17
|
-
module.exports = {
|
18
|
-
statusCodes,
|
19
|
-
contentTypes,
|
20
|
-
errors,
|
21
|
-
messages,
|
22
|
-
};
|
@@ -1,13 +0,0 @@
|
|
1
|
-
const c = require('../config');
|
2
|
-
|
3
|
-
module.exports.sendOk = (res, data) => {
|
4
|
-
res.statusCode = c.statusCodes.SUCCESS;
|
5
|
-
res.setHeader('Content-Type', c.contentTypes.JSON);
|
6
|
-
res.end(JSON.stringify(data));
|
7
|
-
}
|
8
|
-
|
9
|
-
module.exports.sendFail = (res, statusCode, data) => {
|
10
|
-
res.statusCode = statusCode;
|
11
|
-
res.setHeader('Content-Type', c.contentTypes.JSON);
|
12
|
-
res.end(JSON.stringify(data));
|
13
|
-
}
|