Merge pull request #183 from thevahidal/182_fix_login_crash_error

Fix soul crashing error due to sending response with two res objects
This commit is contained in:
Ian Mayo
2024-04-26 11:52:08 +01:00
committed by GitHub
3 changed files with 26 additions and 16 deletions

4
package-lock.json generated
View File

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

View File

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

View File

@@ -59,12 +59,18 @@ const obtainAccessToken = async (req, res) => {
// if the user is not a superuser get the role and its permission from the DB
if (!toBoolean(user.is_superuser)) {
const roleData = getUsersRoleAndPermission({
userId: user.id,
res,
});
try {
const roleData = getUsersRoleAndPermission({
userId: user.id,
res,
});
roleIds = roleData.roleIds;
roleIds = roleData.roleIds;
} catch (err) {
return res
.status(401)
.send({ message: errorMessage.ROLE_NOT_FOUND_ERROR });
}
}
const payload = {
@@ -162,12 +168,17 @@ const refreshAccessToken = async (req, res) => {
// if the user is not a superuser get the role and its permission from the DB
if (!toBoolean(user.is_superuser)) {
const roleData = getUsersRoleAndPermission({
userId: user.id,
res,
});
try {
const roleData = getUsersRoleAndPermission({
userId: user.id,
});
roleIds = roleData.roleIds;
roleIds = roleData.roleIds;
} catch (err) {
return res
.status(401)
.send({ message: errorMessage.ROLE_NOT_FOUND_ERROR });
}
}
const newPayload = {
@@ -271,11 +282,10 @@ const removeRevokedRefreshTokens = () => {
});
};
const getUsersRoleAndPermission = ({ userId, res }) => {
const getUsersRoleAndPermission = ({ userId }) => {
const userRoles = authService.getUserRoleByUserId({ userId });
if (userRoles <= 0) {
res.status(401).send({ message: errorMessage.ROLE_NOT_FOUND_ERROR });
if (userRoles.length <= 0) {
throw new Error(errorMessage.ROLE_NOT_FOUND_ERROR);
}