Skip to content

Commit

Permalink
breaking a part the auth providers from main index
Browse files Browse the repository at this point in the history
  • Loading branch information
elylucas committed Jul 13, 2023
1 parent 3f61ccd commit d01682c
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 77 deletions.
45 changes: 45 additions & 0 deletions src/index.auth0.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from "react";
import { createRoot } from "react-dom/client";
import { Router } from "react-router-dom";
import { createTheme, ThemeProvider } from "@material-ui/core";
import { Auth0Provider } from "@auth0/auth0-react";
import AppAuth0 from "./containers/AppAuth0";
import { history } from "./utils/historyUtils";

const theme = createTheme({
palette: {
secondary: {
main: "#fff",
},
},
});

/* istanbul ignore next */
const onRedirectCallback = (appState: any) => {
history.replace((appState && appState.returnTo) || window.location.pathname);
};

const root = createRoot(document.getElementById("root")!);

/* istanbul ignore if */
if (process.env.VITE_APP_AUTH0) {
root.render(
<Auth0Provider
domain={process.env.VITE_APP_AUTH0_DOMAIN!}
clientId={process.env.VITE_APP_AUTH0_CLIENTID!}
redirectUri={window.location.origin}
audience={process.env.VITE_APP_AUTH0_AUDIENCE}
scope={process.env.VITE_APP_AUTH0_SCOPE}
onRedirectCallback={onRedirectCallback}
cacheLocation="localstorage"
>
<Router history={history}>
<ThemeProvider theme={theme}>
<AppAuth0 />
</ThemeProvider>
</Router>
</Auth0Provider>
);
} else {
console.error("Auth0 is not configured.");
}
30 changes: 30 additions & 0 deletions src/index.cognito.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import { createRoot } from "react-dom/client";
import { Router } from "react-router-dom";
import { createTheme, ThemeProvider } from "@material-ui/core";

import AppCognito from "./containers/AppCognito";
import { history } from "./utils/historyUtils";

const theme = createTheme({
palette: {
secondary: {
main: "#fff",
},
},
});

const root = createRoot(document.getElementById("root")!);

if (process.env.VITE_APP_AWS_COGNITO) {
/* istanbul ignore next */
root.render(
<Router history={history}>
<ThemeProvider theme={theme}>
<AppCognito />
</ThemeProvider>
</Router>
);
} else {
console.error("Cogntio is not configured.");
}
30 changes: 30 additions & 0 deletions src/index.google.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import { createRoot } from "react-dom/client";
import { Router } from "react-router-dom";
import { createTheme, ThemeProvider } from "@material-ui/core";

import AppGoogle from "./containers/AppGoogle";
import { history } from "./utils/historyUtils";

const theme = createTheme({
palette: {
secondary: {
main: "#fff",
},
},
});

const root = createRoot(document.getElementById("root")!);

if (process.env.VITE_APP_GOOGLE) {
/* istanbul ignore next */
root.render(
<Router history={history}>
<ThemeProvider theme={theme}>
<AppGoogle />
</ThemeProvider>
</Router>
);
} else {
console.error("Google is not configured.");
}
40 changes: 40 additions & 0 deletions src/index.okta.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";
import { createRoot } from "react-dom/client";
import { Router } from "react-router-dom";
import { createTheme, ThemeProvider } from "@material-ui/core";

// @ts-ignore
import { OktaAuth } from "@okta/okta-auth-js";
import { Security } from "@okta/okta-react";
import { history } from "./utils/historyUtils";
import AppOkta from "./containers/AppOkta";

const theme = createTheme({
palette: {
secondary: {
main: "#fff",
},
},
});

const root = createRoot(document.getElementById("root")!);

if (process.env.VITE_APP_OKTA) {
const oktaAuth = new OktaAuth({
issuer: `https://${process.env.VITE_APP_OKTA_DOMAIN}/oauth2/default`,
clientId: process.env.VITE_APP_OKTA_CLIENTID,
redirectUri: window.location.origin + "/implicit/callback",
});
/* istanbul ignore next */
root.render(
<Router history={history}>
<ThemeProvider theme={theme}>
<Security oktaAuth={oktaAuth}>
<AppOkta />
</Security>
</ThemeProvider>
</Router>
);
} else {
console.error("Okta is not configured.");
}
84 changes: 7 additions & 77 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@ import React from "react";
import { createRoot } from "react-dom/client";
import { Router } from "react-router-dom";
import { createTheme, ThemeProvider } from "@material-ui/core";
import { Auth0Provider } from "@auth0/auth0-react";
/* istanbul ignore next */
// @ts-ignore
import { OktaAuth } from "@okta/okta-auth-js";
import { Security } from "@okta/okta-react";

import App from "./containers/App";
import AppGoogle from "./containers/AppGoogle";
import AppAuth0 from "./containers/AppAuth0";
import AppOkta from "./containers/AppOkta";
import AppCognito from "./containers/AppCognito";
import { history } from "./utils/historyUtils";

const theme = createTheme({
Expand All @@ -23,72 +13,12 @@ const theme = createTheme({
},
});

/* istanbul ignore next */
const onRedirectCallback = (appState: any) => {
history.replace((appState && appState.returnTo) || window.location.pathname);
};

const root = createRoot(document.getElementById("root")!);

/* istanbul ignore if */
if (process.env.VITE_APP_AUTH0) {
root.render(
<Auth0Provider
domain={process.env.VITE_APP_AUTH0_DOMAIN!}
clientId={process.env.VITE_APP_AUTH0_CLIENTID!}
redirectUri={window.location.origin}
audience={process.env.VITE_APP_AUTH0_AUDIENCE}
scope={process.env.VITE_APP_AUTH0_SCOPE}
onRedirectCallback={onRedirectCallback}
cacheLocation="localstorage"
>
<Router history={history}>
<ThemeProvider theme={theme}>
<AppAuth0 />
</ThemeProvider>
</Router>
</Auth0Provider>
);
} else if (process.env.VITE_APP_OKTA) {
const oktaAuth = new OktaAuth({
issuer: `https://${process.env.VITE_APP_OKTA_DOMAIN}/oauth2/default`,
clientId: process.env.VITE_APP_OKTA_CLIENTID,
redirectUri: window.location.origin + "/implicit/callback",
});
/* istanbul ignore next */
root.render(
<Router history={history}>
<ThemeProvider theme={theme}>
<Security oktaAuth={oktaAuth}>
<AppOkta />
</Security>
</ThemeProvider>
</Router>
);
} else if (process.env.VITE_APP_AWS_COGNITO) {
/* istanbul ignore next */
root.render(
<Router history={history}>
<ThemeProvider theme={theme}>
<AppCognito />
</ThemeProvider>
</Router>
);
} else if (process.env.VITE_APP_GOOGLE) {
/* istanbul ignore next */
root.render(
<Router history={history}>
<ThemeProvider theme={theme}>
<AppGoogle />
</ThemeProvider>
</Router>
);
} else {
root.render(
<Router history={history}>
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>
</Router>
);
}
root.render(
<Router history={history}>
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>
</Router>
);

0 comments on commit d01682c

Please sign in to comment.