Skip to content

Commit

Permalink
Merge pull request #181 from thevahidal/180_allow_optional_fields_use…
Browse files Browse the repository at this point in the history
…rs_table

180 allow optional fields users table
  • Loading branch information
IanMayo authored Apr 23, 2024
2 parents dbfee1e + 98d42d5 commit 01a4948
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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.

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.
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.

### Overview

Expand Down Expand Up @@ -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 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/auth/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -156,6 +156,7 @@ const registerUser = async (req, res) => {
salt,
hashed_password: hashedPassword,
is_superuser: 'false',
...optionalFields,
},
});

Expand Down

0 comments on commit 01a4948

Please sign in to comment.