mirror of
https://github.com/lovasoa/whitebophir
synced 2024-11-10 06:24:17 +00:00
Bug fixes for role checking
This commit is contained in:
parent
6f7068ab4b
commit
b0e595bc3b
2 changed files with 9 additions and 2 deletions
|
@ -359,6 +359,8 @@ function isModerator(token) {
|
|||
var roles = payload.roles;
|
||||
if(roles) {
|
||||
return roles.includes("moderator");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -98,9 +98,10 @@ function validateBoardName(boardName) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Throws an error if the user does not have permission
|
||||
* Validates jwt and returns whether user is a moderator
|
||||
* @param {URL} url
|
||||
* @throws {Error}
|
||||
* @returns {boolean} - True if user is a moderator, else false
|
||||
* @throws {Error} - If no token is provided when it should be
|
||||
*/
|
||||
function checkUserPermission(url) {
|
||||
if(config.AUTH_SECRET_KEY != "") {
|
||||
|
@ -110,10 +111,14 @@ function checkUserPermission(url) {
|
|||
var roles = payload.roles;
|
||||
if(roles) {
|
||||
return roles.includes("moderator");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else { // Error out as no token provided
|
||||
throw new Error("No token provided");
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue