Fix login and logout to actually work

Because of several issues the auth token has not been stored,
which lead to severe errors when trying to log out.
This issue has now been solved.
This commit is contained in:
JP1998 2018-12-03 15:20:14 +01:00
parent f85863d965
commit df75387164
1 changed files with 18 additions and 16 deletions

View File

@ -18,6 +18,7 @@ const actiontypes_userinfo = {
'LOGIN_RESULT_ERROR' : 'LOGIN_RESULT_ERROR', 'LOGIN_RESULT_ERROR' : 'LOGIN_RESULT_ERROR',
'LOGOUT' : 'LOGOUT', 'LOGOUT' : 'LOGOUT',
'APPLY_SIGN_OUT' : 'APPLY_SIGN_OUT',
'STORE_AUTH_HEADERS' : 'STORE_AUTH_HEADERS', 'STORE_AUTH_HEADERS' : 'STORE_AUTH_HEADERS',
@ -42,14 +43,14 @@ export function postRequest(state, url, data) {
}); });
} }
export function getRequest(state, url, data) { export function getRequest(state, url) {
return axios.get(api_url + url, data, { return axios.get(api_url + url, {
headers : generateHeaders(state) headers : generateHeaders(state)
}); });
} }
export function deleteRequest(state, url, data) { export function deleteRequest(state, url) {
return axios.delete(api_url + url, data, { return axios.delete(api_url + url, {
headers : generateHeaders(state) headers : generateHeaders(state)
}); });
} }
@ -71,10 +72,10 @@ function storeOptionalToken(response) {
__store.dispatch({ __store.dispatch({
type : actiontypes_userinfo.STORE_AUTH_HEADERS, type : actiontypes_userinfo.STORE_AUTH_HEADERS,
parameters : { parameters : {
accesstoken : resp.headers['access-token'], accesstoken : response.headers['access-token'],
client : resp.headers['client'], client : response.headers['client'],
expiry : resp.headers['expiry'], expiry : response.headers['expiry'],
uid : resp.headers['uid'] uid : response.headers['uid']
} }
}) })
} }
@ -90,7 +91,7 @@ function checkForAuthenticationHeaders(response) {
return false; return false;
} }
} }
return false; return true;
} }
return false; return false;
} }
@ -183,23 +184,24 @@ const reducer_userinfo = (state = defaultstate_userinfo, action) => {
}); });
case actiontypes_userinfo.LOGOUT: case actiontypes_userinfo.LOGOUT:
deleteRequest(state, '/users/sign_out', {}).then((resp) => { deleteRequest(state, '/users/sign_out').then((resp) => {
__store.dispatch({ type : actiontypes_userinfo.APPLY_SIGN_OUT });
}).catch((error) => { }).catch((error) => {
__store.dispatch({ type : actiontypes_userinfo.APPLY_SIGN_OUT });
}); });
/* return Object.assign({}, state, {});
case actiontypes_userinfo.APPLY_SIGN_OUT:
return Object.assign({}, state, { return Object.assign({}, state, {
isSignedIn : false, isSignedIn : false,
username : null, username : null,
error : false,
errorMessages : [],
accesstoken : null, accesstoken : null,
client : null, client : null,
expiry : null, expiry : null,
uid : null uid : null
}); });
*/
case actiontypes_userinfo.STORE_AUTH_HEADERS: case actiontypes_userinfo.STORE_AUTH_HEADERS:
return Object.assign({}, state, { return Object.assign({}, state, {
accesstoken : action.parameters.accesstoken, accesstoken : action.parameters.accesstoken,