@azteam/express 1.2.214 → 1.2.215
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/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
|
+
import {ErrorException, TOKEN_EXPIRED, TOKEN_FAILED, UNKNOWN} from '@azteam/error';
|
|
2
3
|
|
|
3
4
|
function systemLogin(userData = null) {
|
|
4
5
|
let user = {};
|
|
@@ -25,14 +26,18 @@ export function authMiddleware(req, res, next) {
|
|
|
25
26
|
if (token) {
|
|
26
27
|
if (token.startsWith('JWT ')) {
|
|
27
28
|
token = token.replace('JWT ', '');
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
req.user = jwt.verify(token, process.env.SECRET_KEY);
|
|
32
32
|
return next();
|
|
33
|
-
})
|
|
33
|
+
} catch (err) {
|
|
34
|
+
if (err.name === 'TokenExpiredError') {
|
|
35
|
+
throw new ErrorException(TOKEN_EXPIRED, err);
|
|
36
|
+
}
|
|
37
|
+
throw new ErrorException(UNKNOWN, err);
|
|
38
|
+
}
|
|
34
39
|
}
|
|
35
|
-
throw new
|
|
40
|
+
throw new ErrorException(TOKEN_FAILED, ['Token type failed']);
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
43
|
|