added login redirect
This commit is contained in:
parent
e9dce3abc3
commit
2a020eb6e7
5 changed files with 127 additions and 21 deletions
53
src/pages/Login.tsx
Normal file
53
src/pages/Login.tsx
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { RedirectLoginOptions, useAuth0 } from "@auth0/auth0-react";
|
||||
// import { useAuth } from "hooks";
|
||||
import queryString from "query-string";
|
||||
import { useCallback, useEffect } from "react";
|
||||
import { useLocation } from "react-router";
|
||||
// import Loading from "./Loading";
|
||||
import LoadingScreen from "app/LoadingScreen";
|
||||
|
||||
interface Props {
|
||||
prevPath?: string;
|
||||
}
|
||||
|
||||
export default function Login(props: Props) {
|
||||
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]);
|
||||
|
||||
useEffect(() => {
|
||||
const options: RedirectLoginOptions = {
|
||||
authorizationParams: {} // Initialize here
|
||||
};
|
||||
console.log(location)
|
||||
if (location && location.search) {
|
||||
let parsed = queryString.parse(location.search);
|
||||
|
||||
console.log(parsed.signup)
|
||||
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
|
||||
console.log(options)
|
||||
}
|
||||
|
||||
if (parsed.email && parsed.email !== "") {
|
||||
// if (options.authorizationParams) options.authorizationParams.login_hint = parsed.email.toString(); // prefill email
|
||||
options.authorizationParams!.login_hint = parsed.email.toString(); // prefill email
|
||||
}
|
||||
}
|
||||
|
||||
setRouteBeforeLogin().finally(() => {
|
||||
loginWithRedirect(options);
|
||||
});
|
||||
}, [location, loginWithRedirect, setRouteBeforeLogin]);
|
||||
|
||||
// return <LoadingScreen fullViewport={true} />;
|
||||
return <LoadingScreen message="login redirect" />;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue