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