From f8fb4b7c7d64d69005df5da92282626cc7c57c13 Mon Sep 17 00:00:00 2001 From: csawatzky Date: Mon, 28 Apr 2025 16:05:12 -0600 Subject: [PATCH] fixing redirect stuff --- src/app/App.tsx | 16 +++++++++++----- src/integrations/CNHi/CNHiAccess.tsx | 14 +++++--------- src/integrations/JohnDeere/JDAccess.tsx | 15 ++++++--------- src/pages/CNHi.tsx | 2 +- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/app/App.tsx b/src/app/App.tsx index e863c63..62b5887 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -45,11 +45,16 @@ function App() { // if (!client_id) client_id = import.meta.env.VITE_AUTH0_CLIENT_ID; //check the url for a code before auth0 causes a login re-direct - if (window.location.pathname !== "/callback") { - //set the code into local storage - let code = new URLSearchParams(window.location.search).get("code"); - sessionStorage.setItem("code", code || "") - } + // if (window.location.pathname !== "/callback") { + // //set the code into local storage + // let code = new URLSearchParams(window.location.search).get("code"); + // sessionStorage.setItem("code", code || "") + // } + + const skipCallbacks = [ + "/johndeere", + "/cnhi" + ] return ( @@ -60,6 +65,7 @@ function App() { audience: or(audience, ""), redirect_uri: window.location.origin + "/callback" }} + skipRedirectCallback={skipCallbacks.includes(window.location.pathname)} useRefreshTokens={true} cacheLocation='localstorage' > diff --git a/src/integrations/CNHi/CNHiAccess.tsx b/src/integrations/CNHi/CNHiAccess.tsx index 9f4c25c..6e74817 100644 --- a/src/integrations/CNHi/CNHiAccess.tsx +++ b/src/integrations/CNHi/CNHiAccess.tsx @@ -14,7 +14,7 @@ import { teamScope, User } from "models"; import { pond } from "protobuf-ts/pond"; import { useSnackbar, useUserAPI, useCNHiProxyAPI } from "providers"; import { useEffect, useState } from "react"; -import { useLocation } from "react-router"; +//import { useLocation } from "react-router"; import TeamSearch from "teams/TeamSearch"; export default function CNHiAccess() { @@ -29,8 +29,8 @@ export default function CNHiAccess() { const cnhiAPI = useCNHiProxyAPI(); //const [dataOps, setDataOps] = useState([]); const { openSnack } = useSnackbar(); - const search = useLocation().search; - const searchParams = new URLSearchParams(search); + //const search = useLocation().search; + //const searchParams = new URLSearchParams(search); //const [{ as }] = useGlobalState(); const client_id = import.meta.env.VITE_CNHI_CLIENT_ID; const auth_url = import.meta.env.VITE_CNHI_AUTHORIZE_URL; @@ -44,10 +44,6 @@ export default function CNHiAccess() { cnhiAPI .addAccount(teamKey, primaryUser, cnhiCode, cnhiUsername) .then(resp => { - //the code was used so remove it from local storage - if (localStorage.getItem("code")) { - localStorage.removeItem("code"); - } openSnack("Added New Case New Holland Account Link"); }) .catch(err => { @@ -66,12 +62,12 @@ export default function CNHiAccess() { }, [teamKey, userAPI]); useEffect(() => { - let code = localStorage.getItem("code"); + let code = new URLSearchParams(window.location.search).get("code"); if (code) { setCNHiCode(code); setOpenDialog(true); } - }, [searchParams, cnhiCode]); + }, [window.location, cnhiCode]); const validate = () => { let invalid = false; diff --git a/src/integrations/JohnDeere/JDAccess.tsx b/src/integrations/JohnDeere/JDAccess.tsx index a38e9d8..0c5e7e8 100644 --- a/src/integrations/JohnDeere/JDAccess.tsx +++ b/src/integrations/JohnDeere/JDAccess.tsx @@ -14,7 +14,7 @@ import { teamScope, User } from "models"; import { pond } from "protobuf-ts/pond"; import { useSnackbar, useUserAPI, useJohnDeereProxyAPI } from "providers"; import { useEffect, useState } from "react"; -import { useLocation } from "react-router"; +//import { useLocation } from "react-router"; import TeamSearch from "teams/TeamSearch"; //const steps = [{label: "General"},{label: "Data Options"}] @@ -31,13 +31,14 @@ export default function JDAccess() { const johnDeereAPI = useJohnDeereProxyAPI(); //const [dataOps, setDataOps] = useState([]); const { openSnack } = useSnackbar(); - const search = useLocation().search; - const searchParams = new URLSearchParams(search); + //const search = useLocation().search; + //const searchParams = new URLSearchParams(search); //const [{ as }] = useGlobalState(); //const MAPBOX_TOKEN = import.meta.env.VITE_MAPBOX_ACCESS_TOKEN; const client_id = import.meta.env.VITE_JD_CLIENT_ID; const auth_url = import.meta.env.VITE_JD_AUTHORIZE_URL; const redirect_url = import.meta.env.VITE_JD_REDIRECT_URI; + //const redirect_url = "http://localhost:5173/johndeere";//local redirect for testing const scopes = import.meta.env.VITE_JD_SCOPES; const state = import.meta.env.VITE_JD_STATE; @@ -48,10 +49,6 @@ export default function JDAccess() { johnDeereAPI .addAccount(teamKey, primaryUser, jdCode, jdUserName) .then(resp => { - //the code was used so remove it from local storage - if (sessionStorage.getItem("code")) { - sessionStorage.removeItem("code"); - } openSnack("Added New John Deere Account Link"); window.open( `https://connections.deere.com/connections/${client_id}/select-organizations` @@ -73,12 +70,12 @@ export default function JDAccess() { }, [teamKey, userAPI]); useEffect(() => { - let code = sessionStorage.getItem("code"); + let code = new URLSearchParams(window.location.search).get("code"); if (code) { setJDCode(code); setOpenDialog(true); } - }, [searchParams, jdCode]); + }, [window.location, jdCode]); const validate = () => { let invalid = false; diff --git a/src/pages/CNHi.tsx b/src/pages/CNHi.tsx index fb4b91e..24be24c 100644 --- a/src/pages/CNHi.tsx +++ b/src/pages/CNHi.tsx @@ -119,7 +119,7 @@ export default function CNHi() { //style={{ maxWidth: 110 }} title="John Deer Account" displayEmpty - disableUnderline={true} + //disableUnderline={true} value={currentOrg} onChange={(event: any) => { setCurrentOrg(event.target.value);