-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
index.okta.tsx
60 lines (53 loc) · 1.51 KB
/
index.okta.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React from "react";
import { createRoot } from "react-dom/client";
import { Router, withRouter } from "react-router-dom";
import {
createTheme,
ThemeProvider,
Theme,
StyledEngineProvider,
adaptV4Theme,
} from "@mui/material";
// @ts-ignore
import { OktaAuth, toRelativeUrl } from "@okta/okta-auth-js";
import { Security } from "@okta/okta-react";
import { history } from "./utils/historyUtils";
import AppOkta from "./containers/AppOkta";
const theme = createTheme(
adaptV4Theme({
palette: {
secondary: {
main: "#fff",
},
},
})
);
const root = createRoot(document.getElementById("root")!);
if (process.env.VITE_OKTA) {
const oktaAuth = new OktaAuth({
issuer: `https://${process.env.VITE_OKTA_DOMAIN}/oauth2/default`,
clientId: process.env.VITE_OKTA_CLIENTID,
redirectUri: window.location.origin + "/implicit/callback",
});
const AppWithRouter = withRouter(({ history }) => {
const restoreOriginalUri = (_oktaAuth, originalUri) =>
history.replace(toRelativeUrl(originalUri || "/", window.location.origin));
return (
<Security oktaAuth={oktaAuth} restoreOriginalUri={restoreOriginalUri}>
<AppOkta />
</Security>
);
});
/* istanbul ignore next */
root.render(
<Router history={history}>
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
<AppWithRouter />
</ThemeProvider>
</StyledEngineProvider>
</Router>
);
} else {
console.error("Okta is not configured.");
}