attempt at fixing persistent 'invalid csrf token' error on some browsers

This commit is contained in:
nai-degen 2024-12-03 19:49:16 -06:00
parent 8a325a1e0b
commit 5072638ec2
1 changed files with 6 additions and 1 deletions

View File

@ -32,9 +32,14 @@ userRouter.use(
_next: express.NextFunction
) => {
const data: any = { message: err.message, stack: err.stack, status: 500 };
const isCsrfError = err.message === "invalid csrf token";
if (isCsrfError) {
res.clearCookie("csrf");
req.session.csrf = undefined;
}
if (req.accepts("json", "html") === "json") {
const isCsrfError = err.message === "invalid csrf token";
const message = isCsrfError
? "CSRF token mismatch; try refreshing the page"
: err.message;