Correcting auth-provider Error handling returns

This commit is contained in:
2025-04-10 11:16:09 +02:00
parent f1fe81a146
commit cda4f5654a

View File

@@ -1,6 +1,7 @@
import isEmpty from 'lodash/isEmpty';
import { AuthProvider } from "@refinedev/core";
import {IUser} from "../interfaces";
import {OnErrorResponse} from "@refinedev/core/src/contexts/auth/types";
const API_URL = "/api/v1";
const LOCAL_STORAGE_USER_KEY = "rpk-gui-current-user";
@@ -140,19 +141,21 @@ export const authProvider: AuthProvider = {
getPermissions: async () => { throw new Error("Not implemented"); },
onError: async (error) => {
if (error?.status === 401) {
forget_user()
return Promise<{
forget_user();
return {
redirectTo: "/login",
logout: true,
error: { message: "Authentication required" },
}>;
} as OnErrorResponse;
}
else if (error?.status === 403) {
return Promise<{
return {
error: { message: "Insufficient credentials" },
}>;
} as OnErrorResponse;
}
return {};
return {
error: { message: "Unexpected authentication error" },
} as OnErrorResponse;
},
};