latest work #20

Merged
philipp merged 233 commits from dev into main 2020-12-09 18:49:33 +00:00
Showing only changes of commit f251b7acdb - Show all commits

View File

@ -1,5 +1,6 @@
import * as jwt from "jsonwebtoken";
import { Action, HttpError } from "routing-controllers";
import { Action } from "routing-controllers";
import { IllegalJWTError, NoPermissionError } from './errors/AuthError';
// -----------
const sampletoken = jwt.sign({
"permissions": {
@ -22,7 +23,7 @@ const authchecker = async (action: Action, permissions: string | string[]) => {
try {
jwtPayload = <any>jwt.verify(provided_token, process.env.JWT_SECRET || "secretjwtsecret");
} catch (error) {
throw new HttpError(401, "jwt_illegal")
throw new IllegalJWTError()
}
if (jwtPayload.permissions) {
action.response.local = {}
@ -34,11 +35,11 @@ const authchecker = async (action: Action, permissions: string | string[]) => {
if (actual_accesslevel_for_permission.includes(permission_access_level)) {
return true;
} else {
throw new HttpError(403, "no")
throw new NoPermissionError()
}
});
} else {
throw new HttpError(403, "no")
throw new NoPermissionError()
}
//
try {