@loomcore/api 0.2.22 → 0.2.23
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/dist/middleware/is-authorized.js +10 -20
- package/package.json +1 -1
|
@@ -50,29 +50,19 @@ const isAuthorized = (config) => {
|
|
|
50
50
|
throw new UnauthenticatedError();
|
|
51
51
|
}
|
|
52
52
|
const authConfig = getAuthConfig();
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (isAdmin(userContext)) {
|
|
58
|
-
next();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const method = resolveAuthMethod(req);
|
|
62
|
-
if (!method) {
|
|
63
|
-
throw new UnauthorizedError();
|
|
64
|
-
}
|
|
65
|
-
assertFeatureRequirement(userContext, config[method]);
|
|
53
|
+
const rawPayload = jwt.verify(token, authConfig.clientSecret);
|
|
54
|
+
const userContext = getAuthUserContextSpec().decode(rawPayload);
|
|
55
|
+
req.userContext = userContext;
|
|
56
|
+
if (isAdmin(userContext)) {
|
|
66
57
|
next();
|
|
58
|
+
return;
|
|
67
59
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
throw err;
|
|
72
|
-
}
|
|
73
|
-
console.error(err);
|
|
74
|
-
throw new UnauthenticatedError();
|
|
60
|
+
const method = resolveAuthMethod(req);
|
|
61
|
+
if (!method) {
|
|
62
|
+
throw new UnauthorizedError();
|
|
75
63
|
}
|
|
64
|
+
assertFeatureRequirement(userContext, config[method]);
|
|
65
|
+
next();
|
|
76
66
|
};
|
|
77
67
|
};
|
|
78
68
|
export { isAuthorized };
|