Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const sessionData = await api.session.load(data.connection)
if (!sessionData) { throw new Error('Please log in to continue') }
if (
(data.action.indexOf('resque') < 0) &&
(!data.params.csrfToken || data.params.csrfToken !== sessionData.csrfToken)
) { throw new Error('CSRF error') }
data.session = sessionData
const key = api.session.prefix + data.connection.fingerprint
await redis.expire(key, api.session.ttl)
}
}
}
}
api.actions.addMiddleware(api.session.middleware['logged-in-session'])
api.params.globalSafeParams.push('csrfToken')
}
}
async initialize () {
const middleware = {
name: this.name,
global: true,
preProcessor: async ({ actionTemplate, params }) => {
if (actionTemplate.authenticated === true) {
const match = await api.users.authenticate(params.userName, params.password)
if (!match) { throw Error('Authentication Failed. userName and password required') }
}
}
}
api.actions.addMiddleware(middleware)
}
}
}
}
middleware['ah-resque-ui-proxy-middleware'].postProcessor = async (data) => {
for (const i in api.config['ah-resque-ui'].middleware) {
const middlewareName = api.config['ah-resque-ui'].middleware[i]
const middleware = api.actions.middleware[middlewareName]
if (typeof middleware.postProcessor === 'function') {
await middleware.postProcessor(data)
}
}
}
}
api.actions.addMiddleware(middleware['ah-resque-ui-proxy-middleware'])
}
}