Skip to content

Commit

Permalink
perf(index): use optional chaining (#180)
Browse files Browse the repository at this point in the history
Signed-off-by: Frazer Smith <frazer.dev@icloud.com>
  • Loading branch information
Fdawgs authored Jan 5, 2025
1 parent 2363384 commit 178a535
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function fastifyCsrfProtection (fastify, opts) {
sessionPlugin
} = Object.assign({}, defaultOptions, opts)

const csrfOpts = opts && opts.csrfOpts ? opts.csrfOpts : {}
const csrfOpts = opts?.csrfOpts ? opts.csrfOpts : {}

assert(typeof cookieKey === 'string', 'cookieKey should be a string')
assert(typeof sessionKey === 'string', 'sessionKey should be a string')
Expand All @@ -49,7 +49,7 @@ async function fastifyCsrfProtection (fastify, opts) {

const tokens = new CSRF(csrfOpts)

const isCookieSigned = cookieOpts && cookieOpts.signed
const isCookieSigned = cookieOpts?.signed

if (sessionPlugin === '@fastify/secure-session') {
fastify.decorateReply('generateCsrf', generateCsrfSecureSession)
Expand Down Expand Up @@ -125,7 +125,7 @@ async function fastifyCsrfProtection (fastify, opts) {
}

function getTokenDefault (req) {
return (req.body && req.body._csrf) ||
return req.body?._csrf ||
req.headers['csrf-token'] ||
req.headers['xsrf-token'] ||
req.headers['x-csrf-token'] ||
Expand Down

0 comments on commit 178a535

Please sign in to comment.