2019-10-22 07:58:45 +00:00
|
|
|
/* eslint no-param-reassign: 0 */
|
2020-02-16 11:50:38 +00:00
|
|
|
import moment from 'moment';
|
|
|
|
import Cookies from 'js-cookie';
|
|
|
|
import { frontendURL } from '../../helper/URLHelper';
|
2019-10-22 07:58:45 +00:00
|
|
|
|
|
|
|
export const getLoadingStatus = state => state.fetchAPIloadingStatus;
|
|
|
|
export const setLoadingStatus = (state, status) => {
|
|
|
|
state.fetchAPIloadingStatus = status;
|
|
|
|
};
|
2020-02-16 11:50:38 +00:00
|
|
|
|
|
|
|
export const setUser = (userData, expiryDate) =>
|
|
|
|
Cookies.set('user', userData, {
|
|
|
|
expires: expiryDate.diff(moment(), 'days'),
|
|
|
|
});
|
|
|
|
|
|
|
|
export const getHeaderExpiry = response => moment.unix(response.headers.expiry);
|
|
|
|
|
|
|
|
export const setAuthCredentials = response => {
|
|
|
|
const expiryDate = getHeaderExpiry(response);
|
|
|
|
Cookies.set('auth_data', response.headers, {
|
|
|
|
expires: expiryDate.diff(moment(), 'days'),
|
|
|
|
});
|
|
|
|
setUser(response.data.data, expiryDate);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const clearCookiesOnLogout = () => {
|
|
|
|
Cookies.remove('auth_data');
|
|
|
|
Cookies.remove('user');
|
|
|
|
window.location = frontendURL('login');
|
|
|
|
};
|