🔒️ 401 if no user could be found from token

This commit is contained in:
Timur Ercan
2023-03-09 11:57:33 +01:00
parent d4c6732772
commit 1550e59426

View File

@ -12,12 +12,12 @@ export async function getUserFromToken(
const tokenEmail = token?.email?.toString();
if (!token) {
res.status(401).send("No token found for request.");
res.status(401).send("No session token found for request.");
return null;
}
if (!tokenEmail) {
res.status(400).send("No email found in token.");
res.status(400).send("No email found in session token.");
return null;
}
@ -25,5 +25,10 @@ export async function getUserFromToken(
where: { email: tokenEmail },
});
if (!user) {
res.status(401).end();
return null;
}
return user;
}