remove automatic logout after 15min
This commit is contained in:
parent
c74f427fd5
commit
02f0e1cf3c
@ -63,63 +63,56 @@ export const loadUser = () => (dispatch) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var logoutTimerId;
|
|
||||||
const timeToLogout = 14.9 * 60 * 1000; // nearly 15 minutes corresponding to the API
|
|
||||||
|
|
||||||
// Login user
|
// Login user
|
||||||
export const login =
|
export const login =
|
||||||
({ email, password }) =>
|
({ email, password }) =>
|
||||||
(dispatch) => {
|
(dispatch) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: USER_LOADING,
|
type: USER_LOADING,
|
||||||
});
|
|
||||||
// Headers
|
|
||||||
const config = {
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
// Request Body
|
|
||||||
const body = JSON.stringify({ email, password });
|
|
||||||
axios
|
|
||||||
.post(`${process.env.REACT_APP_BLOCKLY_API}/user`, body, config)
|
|
||||||
.then((res) => {
|
|
||||||
// Logout automatically if refreshToken "expired"
|
|
||||||
const logoutTimer = () =>
|
|
||||||
setTimeout(() => dispatch(logout()), timeToLogout);
|
|
||||||
logoutTimerId = logoutTimer();
|
|
||||||
dispatch(setLanguage(res.data.user.language));
|
|
||||||
dispatch({
|
|
||||||
type: LOGIN_SUCCESS,
|
|
||||||
payload: res.data,
|
|
||||||
});
|
|
||||||
dispatch({
|
|
||||||
type: GET_STATUS,
|
|
||||||
payload: res.data.user.status,
|
|
||||||
});
|
|
||||||
dispatch(returnSuccess(res.data.message, res.status, "LOGIN_SUCCESS"));
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
dispatch(
|
|
||||||
returnErrors(
|
|
||||||
err.response.data.message,
|
|
||||||
err.response.status,
|
|
||||||
"LOGIN_FAIL"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
dispatch({
|
|
||||||
type: LOGIN_FAIL,
|
|
||||||
});
|
|
||||||
var status = [];
|
|
||||||
if (window.localStorage.getItem("status")) {
|
|
||||||
status = JSON.parse(window.localStorage.getItem("status"));
|
|
||||||
}
|
|
||||||
dispatch({
|
|
||||||
type: GET_STATUS,
|
|
||||||
payload: status,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
// Headers
|
||||||
|
const config = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
// Request Body
|
||||||
|
const body = JSON.stringify({ email, password });
|
||||||
|
axios
|
||||||
|
.post(`${process.env.REACT_APP_BLOCKLY_API}/user`, body, config)
|
||||||
|
.then((res) => {
|
||||||
|
dispatch(setLanguage(res.data.user.language));
|
||||||
|
dispatch({
|
||||||
|
type: LOGIN_SUCCESS,
|
||||||
|
payload: res.data,
|
||||||
|
});
|
||||||
|
dispatch({
|
||||||
|
type: GET_STATUS,
|
||||||
|
payload: res.data.user.status,
|
||||||
|
});
|
||||||
|
dispatch(returnSuccess(res.data.message, res.status, "LOGIN_SUCCESS"));
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
dispatch(
|
||||||
|
returnErrors(
|
||||||
|
err.response.data.message,
|
||||||
|
err.response.status,
|
||||||
|
"LOGIN_FAIL"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
dispatch({
|
||||||
|
type: LOGIN_FAIL,
|
||||||
|
});
|
||||||
|
var status = [];
|
||||||
|
if (window.localStorage.getItem("status")) {
|
||||||
|
status = JSON.parse(window.localStorage.getItem("status"));
|
||||||
|
}
|
||||||
|
dispatch({
|
||||||
|
type: GET_STATUS,
|
||||||
|
payload: status,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Logout User
|
// Logout User
|
||||||
export const logout = () => (dispatch) => {
|
export const logout = () => (dispatch) => {
|
||||||
@ -144,7 +137,6 @@ export const logout = () => (dispatch) => {
|
|||||||
}
|
}
|
||||||
dispatch(setLanguage(locale));
|
dispatch(setLanguage(locale));
|
||||||
dispatch(returnSuccess(res.data.message, res.status, "LOGOUT_SUCCESS"));
|
dispatch(returnSuccess(res.data.message, res.status, "LOGOUT_SUCCESS"));
|
||||||
clearTimeout(logoutTimerId);
|
|
||||||
},
|
},
|
||||||
error: (err) => {
|
error: (err) => {
|
||||||
dispatch(
|
dispatch(
|
||||||
@ -165,7 +157,6 @@ export const logout = () => (dispatch) => {
|
|||||||
type: GET_STATUS,
|
type: GET_STATUS,
|
||||||
payload: status,
|
payload: status,
|
||||||
});
|
});
|
||||||
clearTimeout(logoutTimerId);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
axios
|
axios
|
||||||
@ -222,10 +213,6 @@ export const authInterceptor = () => (dispatch, getState) => {
|
|||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
clearTimeout(logoutTimerId);
|
|
||||||
const logoutTimer = () =>
|
|
||||||
setTimeout(() => dispatch(logout()), timeToLogout);
|
|
||||||
logoutTimerId = logoutTimer();
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: REFRESH_TOKEN_SUCCESS,
|
type: REFRESH_TOKEN_SUCCESS,
|
||||||
payload: res.data,
|
payload: res.data,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user