improvement: better token error handling

This commit is contained in:
canove
2020-09-24 14:08:57 -03:00
parent 34a99ade2d
commit f6b5ed389a

View File

@@ -21,6 +21,7 @@ const isAuth = (req: Request, res: Response, next: NextFunction): void => {
const [, token] = authHeader.split(" "); const [, token] = authHeader.split(" ");
try {
const decoded = verify(token, authConfig.secret); const decoded = verify(token, authConfig.secret);
const { id, profile } = decoded as TokenPayload; const { id, profile } = decoded as TokenPayload;
@@ -28,6 +29,9 @@ const isAuth = (req: Request, res: Response, next: NextFunction): void => {
id, id,
profile profile
}; };
} catch (err) {
throw new AppError("Invalid token.", 403);
}
return next(); return next();
}; };