mirror of
https://github.com/lovasoa/whitebophir
synced 2024-11-10 06:24:17 +00:00
Refactor to reduce duplication
This commit is contained in:
parent
b0e595bc3b
commit
b534190825
1 changed files with 3 additions and 5 deletions
|
@ -104,22 +104,20 @@ function validateBoardName(boardName) {
|
|||
* @throws {Error} - If no token is provided when it should be
|
||||
*/
|
||||
function checkUserPermission(url) {
|
||||
var isModerator = false;
|
||||
if(config.AUTH_SECRET_KEY != "") {
|
||||
var token = url.searchParams.get("token");
|
||||
if(token) {
|
||||
var payload = jsonwebtoken.verify(token, config.AUTH_SECRET_KEY);
|
||||
var roles = payload.roles;
|
||||
if(roles) {
|
||||
return roles.includes("moderator");
|
||||
} else {
|
||||
return false;
|
||||
isModerator = roles.includes("moderator");
|
||||
}
|
||||
} else { // Error out as no token provided
|
||||
throw new Error("No token provided");
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return isModerator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue