catch invalid signature

This commit is contained in:
leca 2025-02-07 00:12:31 +03:00
parent 91d6e64f18
commit 46c475593b
2 changed files with 11 additions and 7 deletions

View File

@ -59,7 +59,7 @@ $(document).ready(async () => {
const sendData = async () => { const sendData = async () => {
const jwt = getCookie("jwt"); const jwt = getCookie("jwt");
const author = await fetch(`/api/getUsername`) const author = (await fetch(`/api/getUsername`)).text()
const content = $("#chat-input").val(); const content = $("#chat-input").val();
const message = { const message = {

View File

@ -7,13 +7,17 @@ import UserService from '../services/user.js';
dotenv.config({path: ".env"}); dotenv.config({path: ".env"});
const authenticate = async (req, res, next) => { const authenticate = async (req, res, next) => {
const token = req.cookies["jwt"]; try {
if (!token || !jwt.verify(token, process.env.SECRET)) { const token = req.cookies["jwt"];
req.session.destroy(); if (!token || !jwt.verify(token, process.env.SECRET)) {
res.clearCookie("jwt"); req.session.destroy();
return res.redirect("/login"); res.clearCookie("jwt");
return res.redirect("/login");
}
next();
} catch(e) {
console.log(e)
} }
next();
}; };
const validateInviteToken = async (req, res, next) => { const validateInviteToken = async (req, res, next) => {