add validate session action
This commit is contained in:
parent
1a22998ff8
commit
c42de5b2ae
1 changed files with 18 additions and 0 deletions
|
@ -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 })
|
||||
|
|
Loading…
Reference in a new issue