thevahidal / soul

🕉 A SQLite REST and realtime server
https://thevahidal.github.io/soul/
MIT License
1.45k stars 49 forks source link

Fix Soul crashing when a user tries to login without having a role #182

Closed AbegaM closed 2 months ago

AbegaM commented 2 months ago

Bug Description

There is a bug in the code related to the getUsersRoleAndPermission function in src/controllers/auth/token.js. The function accepts two parameters, userId and res. The bug causes the login API to crash because there are multiple responses being returned, one from the main controller and another from the getUsersRoleAndPermission function.

The error occurs primarily because in Express.js, it is not possible to return a response with two different res objects simultaneously. This causes conflicts and results in the observed error.

Steps to Reproduce

To reproduce the behavior, follow these steps:

  1. Get your users from the /api/table/_users/rows API.

    • Screen Shot 2024-04-26 at 11 35 05 AM
  2. Select one user and remove its role from the _users_roles table by using a GUI DB browser tool.

  1. Attempt to log in with the user whose role you deleted.
  2. Check the error in your console.

Error Screenshots