Skip to content

Commit 3ee2751

Browse files
committed
migrate to react-oidc-context
1 parent dcd2ac9 commit 3ee2751

48 files changed

Lines changed: 190 additions & 126 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bun.lockb

-890 Bytes
Binary file not shown.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"@mui/material": "^7.3.9",
2323
"@mui/material-next": "^6.0.0-alpha.126",
2424
"@mui/x-tree-view": "^7.29.10",
25-
"@react-keycloak/web": "^3.4.0",
2625
"@react-three/drei": "^10.7.7",
2726
"@react-three/fiber": "^9.5.0",
2827
"@sanity/eventsource": "^5.0.2",
@@ -39,19 +38,20 @@
3938
"i18next": "^23.16.8",
4039
"i18next-browser-languagedetector": "^7.2.2",
4140
"js-base64": "^3.7.8",
42-
"keycloak-js": "^24.0.5",
4341
"lodash": "^4.17.23",
4442
"million": "latest",
4543
"notistack": "^3.0.2",
4644
"numeral": "^2.0.6",
45+
"oidc-client-ts": "^3.4.1",
4746
"punycode": "^2.3.1",
48-
"react": "^19.2.0",
47+
"react": "^19.2.4",
4948
"react-apexcharts": "^1.9.0",
5049
"react-cookie": "^7.2.2",
5150
"react-copy-to-clipboard": "^5.1.1",
52-
"react-dom": "^19.2.0",
51+
"react-dom": "^19.2.4",
5352
"react-helmet-async": "^2.0.5",
5453
"react-i18next": "^14.1.3",
54+
"react-oidc-context": "^3.3.0",
5555
"react-router-dom": "^6.30.3",
5656
"simplebar": "^6.3.3",
5757
"simplebar-react": "^3.3.2",

src/App.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// keycloak
2-
import { AuthContextWrapperProvider } from "./contexts/AuthContextWrapper";
3-
import { keycloak } from "./keycloak";
2+
import { oidcConfig } from "./keycloak";
3+
import { AuthProvider } from "react-oidc-context";
4+
45
// routes
56
import Router from "./Router";
67
// theme
@@ -18,7 +19,7 @@ import { AdminResourceContextProvider } from "./contexts/AdminResourceContext";
1819

1920
export default function App() {
2021
return (
21-
<AuthContextWrapperProvider authClient={keycloak}>
22+
<AuthProvider {...oidcConfig}>
2223
<AlertContextProvider>
2324
<ResourceContextProvider>
2425
<AdminResourceContextProvider>
@@ -48,6 +49,6 @@ export default function App() {
4849
</AdminResourceContextProvider>
4950
</ResourceContextProvider>
5051
</AlertContextProvider>
51-
</AuthContextWrapperProvider>
52+
</AuthProvider>
5253
);
5354
}

src/Router.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Onboarding from "./pages/onboarding";
1818
import Inbox from "./pages/inbox/Inbox";
1919
import Teams from "./pages/teams/Teams";
2020
import { GPU } from "./pages/gpu/GPU";
21+
import Callback from "./components/Callback";
2122

2223
export default function Router() {
2324
return useRoutes([
@@ -28,6 +29,7 @@ export default function Router() {
2829
{ path: "/", element: <Landing /> },
2930
{ path: "/status", element: <Status /> },
3031
{ path: "tiers", element: <Tiers /> },
32+
{ path: "oauth2/callback", element: <Callback /> },
3133
{
3234
path: "deploy",
3335
element: (

src/components/Callback.tsx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { useEffect } from "react";
2+
import { useNavigate } from "react-router-dom";
3+
import { useAuth } from "react-oidc-context";
4+
5+
import {
6+
Box,
7+
Button,
8+
CircularProgress,
9+
Paper,
10+
Typography,
11+
} from "@mui/material";
12+
import Page from "./Page";
13+
14+
export default function Callback() {
15+
const navigate = useNavigate();
16+
const auth = useAuth();
17+
18+
useEffect(() => {
19+
if (!auth.isLoading) {
20+
if (auth.isAuthenticated) {
21+
// Clean up the URL
22+
const url = new URL(window.location.href);
23+
url.searchParams.delete("code");
24+
url.searchParams.delete("state");
25+
window.history.replaceState({}, document.title, url.pathname);
26+
27+
// Redirect to /deploy
28+
navigate("/deploy", { replace: true });
29+
}
30+
}
31+
}, [auth.isLoading, auth.isAuthenticated, navigate]);
32+
33+
if (auth.isLoading) {
34+
return (
35+
<Page>
36+
<Box component="div" sx={{ minHeight: "100vh" }}>
37+
<CircularProgress />
38+
<Typography mt={2} variant="h6">
39+
Authenticating...
40+
</Typography>
41+
</Box>
42+
</Page>
43+
);
44+
}
45+
46+
if (auth.error) {
47+
return (
48+
<Page>
49+
<Box
50+
display="flex"
51+
justifyContent="center"
52+
alignItems="center"
53+
height="100vh"
54+
>
55+
<Paper
56+
elevation={3}
57+
sx={{ padding: 4, textAlign: "center", maxWidth: 400 }}
58+
>
59+
<Typography variant="h5" color="error" gutterBottom>
60+
Authentication Failed
61+
</Typography>
62+
<Typography variant="body1" sx={{ wordBreak: "break-word" }}>
63+
{auth.error?.message || "Unknown error occurred during login."}
64+
</Typography>
65+
<Button
66+
variant="contained"
67+
color="primary"
68+
sx={{ mt: 2 }}
69+
onClick={() => auth.signinRedirect()}
70+
>
71+
Try Again
72+
</Button>
73+
</Paper>
74+
</Box>
75+
</Page>
76+
);
77+
}
78+
79+
return null;
80+
}

src/components/Logo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Link as RouterLink } from "react-router-dom";
22
import { Box } from "@mui/material";
3-
import { useKeycloak } from "@react-keycloak/web";
3+
import { useKeycloak } from "../hooks/useKeycloak";
44
import { useContext } from "react";
55
import { ThemeModeContext } from "../contexts/ThemeModeContext";
66

src/components/ProtectedRoute.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Navigate } from "react-router-dom";
2-
import { useKeycloak } from "@react-keycloak/web";
2+
import { useKeycloak } from "../hooks/useKeycloak";
33
import LoadingPage from "./LoadingPage";
4-
import { useContext } from "react";
5-
import { AuthContextWrapper } from "../contexts/AuthContextWrapper";
4+
import { useAuth } from "react-oidc-context";
5+
//import { AuthContextWrapper } from "../contexts/AuthContextWrapper";
66

77
const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
8-
const { error } = useContext(AuthContextWrapper);
8+
const { error } = useAuth();
99
const { keycloak, initialized } = useKeycloak();
1010

1111
const renderPage = (children: React.ReactNode) => {

src/components/admin/DRAConfigPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Stack, Typography, Button, Alert, Box } from "@mui/material";
33
import GpuClaimModal from "./GPUClaimModal";
44
import { GpuClaimCreate } from "../../temporaryTypesRemoveMe";
55
import { createGpuClaim } from "../../api/deploy/gpuClaims";
6-
import { useKeycloak } from "@react-keycloak/web";
6+
import { useKeycloak } from "../../hooks/useKeycloak";
77
import { enqueueSnackbar } from "notistack";
88
import useAdmin from "../../hooks/useAdmin";
99

src/contexts/AdminResourceContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import useFilterableResourceState, {
2121
DEFAULT_PAGESIZE,
2222
} from "../hooks/useFilterableResourceState";
23-
import { useKeycloak } from "@react-keycloak/web";
23+
import { useKeycloak } from "../hooks/useKeycloak";
2424
import { getUsers } from "../api/deploy/users";
2525
import { errorHandler } from "../utils/errorHandler";
2626
import { enqueueSnackbar } from "notistack";

src/contexts/AuthContextWrapper.tsx

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)