fixes / register user
This commit is contained in:
@@ -21,8 +21,15 @@ axios.interceptors.response.use(
|
||||
return axios(error.config);
|
||||
})
|
||||
resolve(response)
|
||||
} else {
|
||||
if(error.response && error.response.status === 403){
|
||||
store.dispatch(logout("Podany użytkownik, lub hasło nie istnieje.", "error"));
|
||||
} else if(error.response && error.response.status === 400) {
|
||||
store.dispatch(logout("Dane nieprawidłowe.", "error"));
|
||||
} else {
|
||||
store.dispatch(logout("Sesja wygasła", "info"));
|
||||
}
|
||||
}
|
||||
store.dispatch(logout());
|
||||
})
|
||||
});
|
||||
|
||||
@@ -196,23 +203,47 @@ export const tryLogin = (username, password) => {
|
||||
axios
|
||||
.post(backend + "user/login", data)
|
||||
.then((response) => {
|
||||
const jwt = response.headers["x-auth-token"];
|
||||
dispatch(
|
||||
if(response.data.isRestaurant === true){
|
||||
const jwt = response.headers["x-auth-token"];
|
||||
dispatch(
|
||||
toggles.setLoggedIn(
|
||||
response.data.firstname,
|
||||
response.data.lastname,
|
||||
jwt,
|
||||
response.data.id,
|
||||
response.data.email,
|
||||
"",
|
||||
response.data.NIP,
|
||||
response.data.adress,
|
||||
response.data.companyName,
|
||||
response.data.restaurants
|
||||
response.data.restaurants,
|
||||
response.data.isRestaurant
|
||||
)
|
||||
);
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification(`Witaj ${response.data.firstname}!`, "success"));
|
||||
dispatch(push("/"));
|
||||
} else {
|
||||
const jwt = response.headers["x-auth-token"];
|
||||
dispatch(
|
||||
toggles.setLoggedIn(
|
||||
"",
|
||||
"",
|
||||
jwt,
|
||||
response.data.id,
|
||||
response.data.email,
|
||||
response.data.login,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
[],
|
||||
response.data.isRestaurant
|
||||
)
|
||||
);
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification(`Witaj ${response.data.login}!`, "success"));
|
||||
dispatch(push("/"));
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
if (!err.response) {
|
||||
@@ -220,7 +251,7 @@ export const tryLogin = (username, password) => {
|
||||
} else if (err.response.status === 404) {
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification("Użytkownik nie istnieje :(", "error"));
|
||||
} else if (err.response.status === 401) {
|
||||
} else if (err.response.status === 403) {
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(notification("Błędne dane logowania :(", "error"));
|
||||
} else {
|
||||
@@ -269,9 +300,13 @@ export const changePassword = (email, password, token) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const logout = () => {
|
||||
export const logout = (message, type) => {
|
||||
return function (dispatch) {
|
||||
dispatch(notification("Wylogowano.", "info"));
|
||||
if(message && type){
|
||||
dispatch(notification(message, type));
|
||||
} else {
|
||||
dispatch(notification("Wylogowano.", "info"));
|
||||
}
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(toggles.setLoggedOut());
|
||||
dispatch(push("/"));
|
||||
@@ -292,6 +327,7 @@ export const tryRegister = (data) => {
|
||||
)
|
||||
);
|
||||
dispatch(toggles.hideBackdrop());
|
||||
dispatch(push("/"))
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
Reference in New Issue
Block a user