parent
b0a24c6a74
commit
f251b7acdb
@ -1,5 +1,6 @@
|
|||||||
import * as jwt from "jsonwebtoken";
|
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({
|
const sampletoken = jwt.sign({
|
||||||
"permissions": {
|
"permissions": {
|
||||||
@ -22,7 +23,7 @@ const authchecker = async (action: Action, permissions: string | string[]) => {
|
|||||||
try {
|
try {
|
||||||
jwtPayload = <any>jwt.verify(provided_token, process.env.JWT_SECRET || "secretjwtsecret");
|
jwtPayload = <any>jwt.verify(provided_token, process.env.JWT_SECRET || "secretjwtsecret");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpError(401, "jwt_illegal")
|
throw new IllegalJWTError()
|
||||||
}
|
}
|
||||||
if (jwtPayload.permissions) {
|
if (jwtPayload.permissions) {
|
||||||
action.response.local = {}
|
action.response.local = {}
|
||||||
@ -34,11 +35,11 @@ const authchecker = async (action: Action, permissions: string | string[]) => {
|
|||||||
if (actual_accesslevel_for_permission.includes(permission_access_level)) {
|
if (actual_accesslevel_for_permission.includes(permission_access_level)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new HttpError(403, "no")
|
throw new NoPermissionError()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new HttpError(403, "no")
|
throw new NoPermissionError()
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user