diff --git a/client/modules/IDE/actions/project.js b/client/modules/IDE/actions/project.js index 2f17bf1a..385e55c8 100644 --- a/client/modules/IDE/actions/project.js +++ b/client/modules/IDE/actions/project.js @@ -107,10 +107,16 @@ export function saveProject(autosave = false) { } } }) - .catch(response => dispatch({ - type: ActionTypes.PROJECT_SAVE_FAIL, - error: response.data - })); + .catch(response => { + if (response.status === 403) { + dispatch(showAuthenticationError()); + } else { + dispatch({ + type: ActionTypes.PROJECT_SAVE_FAIL, + error: response.data + }); + } + }); } }; } diff --git a/client/modules/IDE/actions/projects.js b/client/modules/IDE/actions/projects.js index 2b613dc9..43892453 100644 --- a/client/modules/IDE/actions/projects.js +++ b/client/modules/IDE/actions/projects.js @@ -1,5 +1,6 @@ import * as ActionTypes from '../../../constants'; import axios from 'axios'; +import { showAuthenticationError } from './ide'; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; @@ -33,6 +34,16 @@ export function deleteProject(id) { type: ActionTypes.DELETE_PROJECT, id }); + }) + .catch(response => { + if (response.status === 403) { + dispatch(showAuthenticationError()); + } else { + dispatch({ + type: ActionTypes.ERROR, + error: response.data + }); + } }); }; } diff --git a/server/controllers/project.controller.js b/server/controllers/project.controller.js index 0f75ee3c..db401e41 100644 --- a/server/controllers/project.controller.js +++ b/server/controllers/project.controller.js @@ -5,8 +5,12 @@ import request from 'request'; export function createProject(req, res) { + if (!req.user) { + return res.status(403).send({ success: false, message: 'Session does not match owner of project.'}); + } + let projectValues = { - user: req.user ? req.user._id : undefined // eslint-disable-line no-underscore-dangle + user: req.user._id }; projectValues = Object.assign(projectValues, req.body);