fixed bug auth

This commit is contained in:
Amirhossein Mahmoodi
2024-07-14 10:47:36 +03:30
parent 8fead6db19
commit 6e4adf477f
5 changed files with 22 additions and 13 deletions

View File

@@ -16,9 +16,10 @@ const errorServer = (response, notification, toastContainer) => {
if (notification) errorServerToast(toastContainer);
};
const errorClient = (response, notification, toastContainer) => {
const errorClient = (response, notification, toastContainer, logout) => {
switch (response.status) {
case 401:
logout()
if (notification) errorUnauthorizedToast(toastContainer);
break;
case 422:
@@ -50,11 +51,11 @@ const errorClient = (response, notification, toastContainer) => {
}
};
export const errorResponse = (response, notification, toastContainer) => {
export const errorResponse = (response, notification, toastContainer, logout) => {
if (notification) toast.dismiss({ container: toastContainer });
if (isServerError(response.status)) {
errorServer(response, notification, toastContainer);
} else if (isClientError(response.status)) {
errorClient(response, notification, toastContainer);
errorClient(response, notification, toastContainer, logout);
}
};