Commit 7996e578 authored by Matija Obreza's avatar Matija Obreza
Browse files

Logout must delete cookies

parent f8bd9721
......@@ -72,13 +72,13 @@ export const logoutUserAction = () => ({
});
function* logoutUserSaga() {
const token = yield select((state) => state.login.access_token);
yield call(LoginService.logout, token);
// const token = yield select((state) => state.login.access_token);
// yield call(LoginService.logout, token);
clearCookies();
const appTokenData = yield call(loginAppAction);
const appTokenData = yield call(LoginService.loginApp);
const apiUrl = yield select((state) => state.applicationConfig.apiUrl);
saveCookies(appTokenData, appTokenData.exp * 1000 || new Date().getTime() + appTokenData.expires_in * 1000, apiUrl);
saveCookies({ ...appTokenData, ...jwt.decode(appTokenData.access_token) }, appTokenData.exp * 1000 || new Date().getTime() + appTokenData.expires_in * 1000, apiUrl);
window.location.replace('/');
}
......
......@@ -43,17 +43,13 @@ export function saveCookies(resp, expireOn: number, apiUrl: string) {
if (resp.refresh_token) {
cookies.set('refresh_token', resp.refresh_token, { domain, path: '/', expires: expDate });
} else {
document.cookie = `refresh_token=; domain=${domain}; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
cookies.remove('refresh_token');
}
}
export function clearCookies() {
const domain = typeof document !== 'undefined' && document.location.origin.includes('.')
? `.${document.location.origin.split('.').filter((item, index, arr) => index > arr.length - 3).join('.')}`
: 'localhost';
log('Clearing cookies');
['authorities', 'access_token', 'refresh_token'].forEach((key) => document.cookie = `${key}=; domain=${domain}; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`);
['authorities', 'access_token', 'refresh_token'].forEach((key) => cookies.remove(key));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment