Skip to content

Commit 83bc294

Browse files
committed
[DOP-23769] Fix handling auth errors in DummyAuth
1 parent c296756 commit 83bc294

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/auth/dummyAuth.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthProvider } from "react-admin";
1+
import { AuthProvider, HttpError } from "react-admin";
22

33
import { getURL } from "@/dataProvider/utils";
44

@@ -18,7 +18,11 @@ const authProvider: AuthProvider = {
1818
return fetch(getURL("/v1/auth/token"), requestOptions)
1919
.then((response) => {
2020
if (response.status < 200 || response.status >= 300) {
21-
throw new Error(response.statusText);
21+
throw new HttpError(
22+
response.statusText,
23+
response.status,
24+
response.body,
25+
);
2226
}
2327
return response.json();
2428
})
@@ -37,12 +41,12 @@ const authProvider: AuthProvider = {
3741
const status = error.status;
3842
if (status === 401) {
3943
localStorage.removeItem("token");
40-
throw new Error(error.statusText);
44+
throw error;
4145
}
4246
return Promise.resolve();
4347
},
4448
checkAuth: () =>
45-
localStorage.getItem("username") ? Promise.resolve() : Promise.reject(),
49+
localStorage.getItem("token") ? Promise.resolve() : Promise.reject(),
4650
getPermissions: () => Promise.resolve(),
4751
getIdentity: () => {
4852
const user = localStorage.getItem("username");

src/components/login/keycloak/callback.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useLocation } from "react-router-dom";
44
import { CircularProgress } from "@mui/material";
55

66
import { getURL } from "@/dataProvider/utils";
7+
import { HttpError } from "react-admin";
78

89
const KeycloakAuthCallback = () => {
910
const params = useLocation();
@@ -18,7 +19,11 @@ const KeycloakAuthCallback = () => {
1819
fetch(url.toString(), requestOptions)
1920
.then((response) => {
2021
if (response.status < 200 || response.status >= 300) {
21-
throw new Error(response.statusText);
22+
throw new HttpError(
23+
response.statusText,
24+
response.status,
25+
response.body,
26+
);
2227
}
2328
window.location.href = "/";
2429
})

0 commit comments

Comments
 (0)