soul-cli 0.7.4 → 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/docs/auth.md +3 -1
- package/package.json +1 -1
- package/src/controllers/auth/token.js +25 -15
- package/src/controllers/auth/user.js +2 -1
package/docs/auth.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Soul incorporates a robust user authentication system that handles user accounts, groups, permissions, and cookie-based user sessions. This section provides an overview of how the default implementation works.
|
|
4
4
|
|
|
5
|
-
Authentication is switched off by default in Soul, but is enabled when either of the `-a` or
|
|
5
|
+
Authentication is switched off by default in Soul, but is enabled when either of the `-a` or `--auth` flags are provided at the command line.
|
|
6
6
|
|
|
7
7
|
### Overview
|
|
8
8
|
|
|
@@ -132,4 +132,6 @@ Note that you need to be logged in using a user with a role that has creating us
|
|
|
132
132
|
|
|
133
133
|
Additionally, it's important to note that the `/api/tables/_users/rows/` endpoint functions slightly differently compared to other `/api/tables/<table_name>/rows/` endpoints. When creating or updating user data through this endpoint, we need to provide the raw passwords, which are then automatically hashed before being stored in the `_hashed_password` field. This extra step enhances the security of the stored passwords.
|
|
134
134
|
|
|
135
|
+
When creating a user, the required fields are `username` and `password`. However, you also have the flexibility to include additional optional fields. To do this, you will need to modify the schema of the `_users` table in your database using a suitable database editor GUI tool. Simply add the desired field(s) to the database schema for the `_users` table. Once the schema is updated, you can pass the optional field(s) from your client application during user creation.
|
|
136
|
+
|
|
135
137
|
Furthermore, when retrieving user data, the endpoint automatically filters out sensitive information such as the `_hashed_password` and `_salt` fields. This precautionary measure is in place to address security concerns and ensure that only necessary and non-sensitive information is included in the returned results.
|
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
|
|
|
@@ -92,7 +92,7 @@ const registerUser = async (req, res) => {
|
|
|
92
92
|
}
|
|
93
93
|
*/
|
|
94
94
|
|
|
95
|
-
const { username, password } = req.body.fields;
|
|
95
|
+
const { username, password, ...optionalFields } = req.body.fields;
|
|
96
96
|
|
|
97
97
|
try {
|
|
98
98
|
if (!username) {
|
|
@@ -156,6 +156,7 @@ const registerUser = async (req, res) => {
|
|
|
156
156
|
salt,
|
|
157
157
|
hashed_password: hashedPassword,
|
|
158
158
|
is_superuser: 'false',
|
|
159
|
+
...optionalFields,
|
|
159
160
|
},
|
|
160
161
|
});
|
|
161
162
|
|