took out the login page route again, auth redirect forces login page if doing a sign up
This commit is contained in:
parent
c7848a25ef
commit
338b256d13
3 changed files with 23 additions and 20 deletions
|
|
@ -9,7 +9,6 @@ import { getWhitelabel } from "services/whiteLabel";
|
|||
import Ventilation from "pages/VentEditor";
|
||||
import { useGlobalState } from "providers";
|
||||
import DeviceSupport from "pages/DeviceSupport";
|
||||
import Login from "pages/Login";
|
||||
|
||||
const DeviceHistory = lazy(() => import("pages/DeviceHistory"));
|
||||
const DevicePage = lazy(() => import("pages/Device"));
|
||||
|
|
@ -303,7 +302,7 @@ export default function Router() {
|
|||
|
||||
{/* Redirects */}
|
||||
<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="/device/:deviceID" element={<Navigate to="/devices/:devicesID" />} /> */}
|
||||
<Route path="" element={<Navigate to={whiteLabel.homePage ? whiteLabel.homePage : "/devices"} />} />
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
import { RedirectLoginOptions, useAuth0 } from "@auth0/auth0-react";
|
||||
// import { useAuth } from "hooks";
|
||||
import queryString from "query-string";
|
||||
import { useCallback, useEffect } from "react";
|
||||
import { useEffect } from "react";
|
||||
import { useLocation } from "react-router";
|
||||
// import Loading from "./Loading";
|
||||
import LoadingScreen from "app/LoadingScreen";
|
||||
|
||||
interface Props {
|
||||
prevPath?: string;
|
||||
}
|
||||
// interface Props {
|
||||
// prevPath?: string;
|
||||
// }
|
||||
|
||||
export default function Login(props: Props) {
|
||||
const { prevPath } = props;
|
||||
export default function Login() {
|
||||
// const { prevPath } = props;
|
||||
const location = useLocation();
|
||||
const { loginWithRedirect } = useAuth0();
|
||||
|
||||
const setRouteBeforeLogin = useCallback((): Promise<string> => {
|
||||
return new Promise(function(resolve) {
|
||||
localStorage.setItem("routeBeforeLogin", prevPath ? prevPath : "/");
|
||||
return resolve("success");
|
||||
});
|
||||
}, [prevPath]);
|
||||
// const setRouteBeforeLogin = useCallback((): Promise<string> => {
|
||||
// return new Promise(function(resolve) {
|
||||
// localStorage.setItem("routeBeforeLogin", prevPath ? prevPath : "/");
|
||||
// return resolve("success");
|
||||
// });
|
||||
// }, [prevPath]);
|
||||
|
||||
useEffect(() => {
|
||||
const options: RedirectLoginOptions = {
|
||||
|
|
@ -33,6 +33,7 @@ export default function Login(props: Props) {
|
|||
if (parsed.signup === "true") {
|
||||
// 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!.prompt = "login";
|
||||
}
|
||||
|
||||
if (parsed.email && parsed.email !== "") {
|
||||
|
|
@ -41,10 +42,11 @@ export default function Login(props: Props) {
|
|||
}
|
||||
}
|
||||
|
||||
setRouteBeforeLogin().finally(() => {
|
||||
// setRouteBeforeLogin().finally(() => {
|
||||
console.log(options.authorizationParams)
|
||||
loginWithRedirect(options);
|
||||
});
|
||||
}, [location, loginWithRedirect, setRouteBeforeLogin]);
|
||||
// });
|
||||
}, [location, loginWithRedirect]);
|
||||
|
||||
// return <LoadingScreen fullViewport={true} />;
|
||||
return <LoadingScreen message="login redirect" />;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ export default function AuthWrapper(props: Props) {
|
|||
useEffect(() => {
|
||||
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)
|
||||
|
||||
if (isManualLoginPage) {
|
||||
|
|
@ -26,12 +27,13 @@ export default function AuthWrapper(props: Props) {
|
|||
let parsed = queryString.parse(url.search);
|
||||
if (parsed.signup === "true") {
|
||||
options.authorizationParams!.screen_hint = "signup";
|
||||
options.authorizationParams!.prompt = "login";
|
||||
}
|
||||
|
||||
if (parsed.email && parsed.email !== "") {
|
||||
options.authorizationParams!.login_hint = parsed.email.toString(); // prefill email
|
||||
}
|
||||
console.log(options)
|
||||
console.log(options.authorizationParams)
|
||||
loginWithRedirect(options)
|
||||
|
||||
} else if (!isAuthenticated && !isLoading) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue