Merge pull request #181 from thevahidal/180_allow_optional_fields_users_table

180 allow optional fields users table
This commit is contained in:
Ian Mayo
2024-04-23 15:30:48 +01:00
committed by GitHub
4 changed files with 8 additions and 5 deletions

View File

@@ -132,4 +132,6 @@ Note that you need to be logged in using a user with a role that has creating us
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.
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.
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.

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "soul-cli",
"version": "0.7.4",
"version": "0.7.5",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "soul-cli",
"version": "0.7.4",
"version": "0.7.5",
"license": "MIT",
"dependencies": {
"bcrypt": "^5.1.1",

View File

@@ -1,6 +1,6 @@
{
"name": "soul-cli",
"version": "0.7.4",
"version": "0.7.5",
"description": "A SQLite REST and Realtime server",
"main": "src/server.js",
"bin": {

View File

@@ -92,7 +92,7 @@ const registerUser = async (req, res) => {
}
*/
const { username, password } = req.body.fields;
const { username, password, ...optionalFields } = req.body.fields;
try {
if (!username) {
@@ -156,6 +156,7 @@ const registerUser = async (req, res) => {
salt,
hashed_password: hashedPassword,
is_superuser: 'false',
...optionalFields,
},
});