From 85a0aaf68af152c5a2cebfeb73ea8c8131a0e742 Mon Sep 17 00:00:00 2001 From: Samox Date: Thu, 20 Oct 2022 16:39:03 +0200 Subject: [PATCH] refactor(Auth): Redirection happens earlier in process --- src/App.tsx | 1 - src/User/LoginOrDisplayUser.tsx | 12 +----------- src/main.tsx | 7 +++++++ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index bd25ae4..324989c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,7 +6,6 @@ const AppFrame = React.lazy( () => import("@pluralsight/ps-design-system-appframe") ); const SkillsTopNav = React.lazy(() => import("./TopNav")); -import * as core from "@pluralsight/ps-design-system-core"; import Theme from "@pluralsight/ps-design-system-theme"; const WebhookList = React.lazy( diff --git a/src/User/LoginOrDisplayUser.tsx b/src/User/LoginOrDisplayUser.tsx index 8408cca..d3c7202 100644 --- a/src/User/LoginOrDisplayUser.tsx +++ b/src/User/LoginOrDisplayUser.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useContext, useEffect } from "react"; +import React, { useCallback } from "react"; import NavUser from "@pluralsight/ps-design-system-navuser"; import { decodeJWT } from "../utils/decode-jwt"; import { ACCESS_TOKEN_KEY, IDENTITY_TOKEN_KEY } from "../local-storage"; @@ -27,16 +27,6 @@ export const LoginOrDisplayUser = () => { window.location.href = "/"; }, []); - useEffect(() => { - const autoredirectOnGithubAuth = - window.location.hostname === "github.webhook.store"; - if (autoredirectOnGithubAuth) { - window.location.href = `${ - import.meta.env.VITE_AUTH_TENANT_URL - }/oauth/login`; - } - }, []); - if (identityToken) { const decodedToken = decodeJWT<{ name: string; picture: string }, any>(identityToken); diff --git a/src/main.tsx b/src/main.tsx index 5b0cc4d..2f1c381 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -6,6 +6,12 @@ import Honeybadger from "@honeybadger-io/js"; import { HoneybadgerErrorBoundary } from "@honeybadger-io/react"; import posthog from "posthog-js"; +const autoRedirectOnGithubAuth = + window.location.hostname === "github.webhook.store"; +if (autoRedirectOnGithubAuth) { + window.location.href = `${import.meta.env.VITE_AUTH_TENANT_URL}/oauth/login`; +} + Honeybadger.configure({ apiKey: import.meta.env.VITE_HONEYBADGER_API_KEY as string, environment: import.meta.env.MODE, @@ -20,6 +26,7 @@ posthog.capture("my event", { property: "value" }); const root = ReactDOM.createRoot( document.getElementById("root") as HTMLElement ); + root.render(