Merge branch 'auth_stuff' into dev_environment

This commit is contained in:
Carter 2025-06-25 11:04:33 -06:00
commit b4877038f1
3 changed files with 23 additions and 20 deletions

View file

@ -9,7 +9,6 @@ import { getWhitelabel } from "services/whiteLabel";
import Ventilation from "pages/VentEditor"; import Ventilation from "pages/VentEditor";
import { useGlobalState } from "providers"; import { useGlobalState } from "providers";
import DeviceSupport from "pages/DeviceSupport"; import DeviceSupport from "pages/DeviceSupport";
import Login from "pages/Login";
const DeviceHistory = lazy(() => import("pages/DeviceHistory")); const DeviceHistory = lazy(() => import("pages/DeviceHistory"));
const DevicePage = lazy(() => import("pages/Device")); const DevicePage = lazy(() => import("pages/Device"));
@ -303,7 +302,7 @@ export default function Router() {
{/* Redirects */} {/* Redirects */}
<Route path="/callback" element={<Navigate to="/" />} /> <Route path="/callback" element={<Navigate to="/" />} />
<Route path="/login" element={<Login />} /> {/* <Route path="/login" element={<Login />} /> */}
{/* <Route path="/team/:teamID" element={<Navigate to="/teams/:teamID" />} /> */} {/* <Route path="/team/:teamID" element={<Navigate to="/teams/:teamID" />} /> */}
{/* <Route path="/device/:deviceID" element={<Navigate to="/devices/:devicesID" />} /> */} {/* <Route path="/device/:deviceID" element={<Navigate to="/devices/:devicesID" />} /> */}
<Route path="" element={<Navigate to={whiteLabel.homePage ? whiteLabel.homePage : "/devices"} />} /> <Route path="" element={<Navigate to={whiteLabel.homePage ? whiteLabel.homePage : "/devices"} />} />

View file

@ -1,26 +1,26 @@
import { RedirectLoginOptions, useAuth0 } from "@auth0/auth0-react"; import { RedirectLoginOptions, useAuth0 } from "@auth0/auth0-react";
// import { useAuth } from "hooks"; // import { useAuth } from "hooks";
import queryString from "query-string"; import queryString from "query-string";
import { useCallback, useEffect } from "react"; import { useEffect } from "react";
import { useLocation } from "react-router"; import { useLocation } from "react-router";
// import Loading from "./Loading"; // import Loading from "./Loading";
import LoadingScreen from "app/LoadingScreen"; import LoadingScreen from "app/LoadingScreen";
interface Props { // interface Props {
prevPath?: string; // prevPath?: string;
} // }
export default function Login(props: Props) { export default function Login() {
const { prevPath } = props; // const { prevPath } = props;
const location = useLocation(); const location = useLocation();
const { loginWithRedirect } = useAuth0(); const { loginWithRedirect } = useAuth0();
const setRouteBeforeLogin = useCallback((): Promise<string> => { // const setRouteBeforeLogin = useCallback((): Promise<string> => {
return new Promise(function(resolve) { // return new Promise(function(resolve) {
localStorage.setItem("routeBeforeLogin", prevPath ? prevPath : "/"); // localStorage.setItem("routeBeforeLogin", prevPath ? prevPath : "/");
return resolve("success"); // return resolve("success");
}); // });
}, [prevPath]); // }, [prevPath]);
useEffect(() => { useEffect(() => {
const options: RedirectLoginOptions = { const options: RedirectLoginOptions = {
@ -33,6 +33,7 @@ export default function Login(props: Props) {
if (parsed.signup === "true") { if (parsed.signup === "true") {
// if (options.authorizationParams) options.authorizationParams.screen_hint = "signup"; // 'signup' tells Auth0 to show the signup tab // if (options.authorizationParams) options.authorizationParams.screen_hint = "signup"; // 'signup' tells Auth0 to show the signup tab
options.authorizationParams!.screen_hint = "signup"; // 'signup' tells Auth0 to show the signup tab options.authorizationParams!.screen_hint = "signup"; // 'signup' tells Auth0 to show the signup tab
options.authorizationParams!.prompt = "login";
} }
if (parsed.email && parsed.email !== "") { if (parsed.email && parsed.email !== "") {
@ -41,10 +42,11 @@ export default function Login(props: Props) {
} }
} }
setRouteBeforeLogin().finally(() => { // setRouteBeforeLogin().finally(() => {
loginWithRedirect(options); console.log(options.authorizationParams)
}); loginWithRedirect(options);
}, [location, loginWithRedirect, setRouteBeforeLogin]); // });
}, [location, loginWithRedirect]);
// return <LoadingScreen fullViewport={true} />; // return <LoadingScreen fullViewport={true} />;
return <LoadingScreen message="login redirect" />; return <LoadingScreen message="login redirect" />;

View file

@ -15,7 +15,8 @@ export default function AuthWrapper(props: Props) {
useEffect(() => { useEffect(() => {
const url = new URL(window.location.href); const url = new URL(window.location.href);
const isManualLoginPage = url.pathname === "/login"; const isManualLoginPage = url.pathname.includes("/login");
console.log(url.pathname)
console.log(isManualLoginPage) console.log(isManualLoginPage)
if (isManualLoginPage) { if (isManualLoginPage) {
@ -26,12 +27,13 @@ export default function AuthWrapper(props: Props) {
let parsed = queryString.parse(url.search); let parsed = queryString.parse(url.search);
if (parsed.signup === "true") { if (parsed.signup === "true") {
options.authorizationParams!.screen_hint = "signup"; options.authorizationParams!.screen_hint = "signup";
options.authorizationParams!.prompt = "login";
} }
if (parsed.email && parsed.email !== "") { if (parsed.email && parsed.email !== "") {
options.authorizationParams!.login_hint = parsed.email.toString(); // prefill email options.authorizationParams!.login_hint = parsed.email.toString(); // prefill email
} }
console.log(options) console.log(options.authorizationParams)
loginWithRedirect(options) loginWithRedirect(options)
} else if (!isAuthenticated && !isLoading) { } else if (!isAuthenticated && !isLoading) {