1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-03 21:10:05 +00:00

fix: csrf package is changed to pillarjs-csrf

This commit is contained in:
Saad Jutt
2022-09-29 20:33:30 +05:00
parent 375f924f45
commit fe3e5088f8
13 changed files with 108 additions and 132 deletions

View File

@@ -1,6 +1,5 @@
import path from 'path'
import express, { ErrorRequestHandler } from 'express'
import csrf, { CookieOptions } from 'csurf'
import express, { ErrorRequestHandler, CookieOptions } from 'express'
import cookieParser from 'cookie-parser'
import dotenv from 'dotenv'
@@ -39,15 +38,7 @@ export const cookieOptions: CookieOptions = {
maxAge: 24 * 60 * 60 * 1000 // 24 hours
}
/***********************************
* CSRF Protection *
***********************************/
export const csrfProtection = csrf({ cookie: cookieOptions })
const onError: ErrorRequestHandler = (err, req, res, next) => {
if (err.code === 'EBADCSRFTOKEN')
return res.status(400).send('Invalid CSRF token!')
console.error(err.stack)
res.status(500).send('Something broke!')
}