diff --git a/client/modules/User/actions.js b/client/modules/User/actions.js index 69293cc6..0b5a8a2a 100644 --- a/client/modules/User/actions.js +++ b/client/modules/User/actions.js @@ -1,6 +1,7 @@ import * as ActionTypes from '../../constants'; import { browserHistory } from 'react-router'; import axios from 'axios'; +import { showAuthenticationError } from '../IDE/actions/ide'; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; @@ -82,6 +83,23 @@ export function getUser() { }; } +export function validateSession() { + return (dispatch, getState) => { + axios.get(`${ROOT_URL}/session`, { withCredentials: true }) + .then(response => { + const state = getState(); + if (state.user.username !== response.data.username) { + dispatch(showAuthenticationError()); + } + }) + .catch(response => { + if (response.status === 404) { + dispatch(showAuthenticationError()); + } + }); + } +} + export function logoutUser() { return (dispatch) => { axios.get(`${ROOT_URL}/logout`, { withCredentials: true })