soul-cli 0.7.5 → 0.7.6
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 +1 -1
- package/src/controllers/auth/token.js +25 -15
package/package.json
CHANGED
|
@@ -59,12 +59,18 @@ const obtainAccessToken = async (req, res) => {
|
|
|
59
59
|
|
|
60
60
|
// if the user is not a superuser get the role and its permission from the DB
|
|
61
61
|
if (!toBoolean(user.is_superuser)) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
try {
|
|
63
|
+
const roleData = getUsersRoleAndPermission({
|
|
64
|
+
userId: user.id,
|
|
65
|
+
res,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
roleIds = roleData.roleIds;
|
|
69
|
+
} catch (err) {
|
|
70
|
+
return res
|
|
71
|
+
.status(401)
|
|
72
|
+
.send({ message: errorMessage.ROLE_NOT_FOUND_ERROR });
|
|
73
|
+
}
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
const payload = {
|
|
@@ -162,12 +168,17 @@ const refreshAccessToken = async (req, res) => {
|
|
|
162
168
|
|
|
163
169
|
// if the user is not a superuser get the role and its permission from the DB
|
|
164
170
|
if (!toBoolean(user.is_superuser)) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
+
try {
|
|
172
|
+
const roleData = getUsersRoleAndPermission({
|
|
173
|
+
userId: user.id,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
roleIds = roleData.roleIds;
|
|
177
|
+
} catch (err) {
|
|
178
|
+
return res
|
|
179
|
+
.status(401)
|
|
180
|
+
.send({ message: errorMessage.ROLE_NOT_FOUND_ERROR });
|
|
181
|
+
}
|
|
171
182
|
}
|
|
172
183
|
|
|
173
184
|
const newPayload = {
|
|
@@ -271,11 +282,10 @@ const removeRevokedRefreshTokens = () => {
|
|
|
271
282
|
});
|
|
272
283
|
};
|
|
273
284
|
|
|
274
|
-
const getUsersRoleAndPermission = ({ userId
|
|
285
|
+
const getUsersRoleAndPermission = ({ userId }) => {
|
|
275
286
|
const userRoles = authService.getUserRoleByUserId({ userId });
|
|
276
287
|
|
|
277
|
-
if (userRoles <= 0) {
|
|
278
|
-
res.status(401).send({ message: errorMessage.ROLE_NOT_FOUND_ERROR });
|
|
288
|
+
if (userRoles.length <= 0) {
|
|
279
289
|
throw new Error(errorMessage.ROLE_NOT_FOUND_ERROR);
|
|
280
290
|
}
|
|
281
291
|
|