fix case when req.session is undefined and use correct syntax for authWithSession
This commit is contained in:
@@ -36,7 +36,7 @@ let api = {};
|
||||
api.exportUserHistory = {
|
||||
method: 'GET',
|
||||
url: '/export/history.csv',
|
||||
middlewares: [authWithSession(), cron],
|
||||
middlewares: [authWithSession, cron],
|
||||
async handler (req, res) {
|
||||
let user = res.locals.user;
|
||||
|
||||
@@ -104,7 +104,7 @@ async function _getUserDataForExport (user) {
|
||||
api.exportUserDataJson = {
|
||||
method: 'GET',
|
||||
url: '/export/userdata.json',
|
||||
middlewares: [authWithSession(), cron],
|
||||
middlewares: [authWithSession, cron],
|
||||
async handler (req, res) {
|
||||
let userData = await _getUserDataForExport(res.locals.user);
|
||||
|
||||
@@ -129,7 +129,7 @@ api.exportUserDataJson = {
|
||||
api.exportUserDataXml = {
|
||||
method: 'GET',
|
||||
url: '/export/userdata.xml',
|
||||
middlewares: [authWithSession(), cron],
|
||||
middlewares: [authWithSession, cron],
|
||||
async handler (req, res) {
|
||||
let userData = await _getUserDataForExport(res.locals.user);
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ export function authWithHeaders (optional = false) {
|
||||
// Authenticate a request through a valid session
|
||||
// TODO should use json web token
|
||||
export function authWithSession (req, res, next) {
|
||||
let userId = req.session.userId;
|
||||
let userId = req.session && req.session.userId;
|
||||
|
||||
if (!userId) return next(new NotAuthorized(i18n.t('invalidCredentials')));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user