mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 12:19:16 +00:00
improvement: better token error handling
This commit is contained in:
@@ -21,13 +21,17 @@ const isAuth = (req: Request, res: Response, next: NextFunction): void => {
|
||||
|
||||
const [, token] = authHeader.split(" ");
|
||||
|
||||
const decoded = verify(token, authConfig.secret);
|
||||
const { id, profile } = decoded as TokenPayload;
|
||||
try {
|
||||
const decoded = verify(token, authConfig.secret);
|
||||
const { id, profile } = decoded as TokenPayload;
|
||||
|
||||
req.user = {
|
||||
id,
|
||||
profile
|
||||
};
|
||||
req.user = {
|
||||
id,
|
||||
profile
|
||||
};
|
||||
} catch (err) {
|
||||
throw new AppError("Invalid token.", 403);
|
||||
}
|
||||
|
||||
return next();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user