parent
b0a24c6a74
commit
f251b7acdb
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user