reject request if token not in db
This commit is contained in:
parent
c2e4aacb28
commit
9c6654182b
|
|
@ -24,8 +24,8 @@ const checkAuth = (req: Request, res: Response, next: NextFunction) => {
|
|||
req.userId = decodedToken;
|
||||
next();
|
||||
})
|
||||
.catch(() => {
|
||||
return res.status(401).send('Invalid token');
|
||||
.catch((error) => {
|
||||
return res.status(401).send(error);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,13 @@ const genToken = (userId: number) => {
|
|||
});
|
||||
};
|
||||
|
||||
const verifyToken = (token: string): Promise<number> => {
|
||||
const verifyToken = async (token: string): Promise<number> => {
|
||||
const prismaToken = await prisma.token.findUnique({
|
||||
where: { token },
|
||||
});
|
||||
if (prismaToken === null) {
|
||||
throw 'Token not found';
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
jwt.verify(token, config.JWT_SECRET, (err?, decoded?: jwt.JwtPayload | string) => {
|
||||
if (err) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue