Web: Fixed redirection after login

This commit is contained in:
Akmal Isomadinov 2022-12-23 15:56:42 +05:00
parent fdb74c23af
commit c62000f3f5
3 changed files with 10 additions and 5 deletions

View File

@ -55,6 +55,11 @@ const PrivateRoute = ({ component: Component, ...rest }) => {
console.log("PrivateRoute render Redirect to login", rest);
const redirectPath = wizardCompleted ? "/login" : "/wizard";
if (wizardCompleted && props.location.pathname !== "/") {
sessionStorage.setItem("referenceUrl", window.location.href);
}
return window.location.replace(redirectPath);
// return (
// <Redirect

View File

@ -97,7 +97,7 @@ function Editor({
useEffect(() => {
if (error && mfReady) {
if (error?.unAuthorized) {
localStorage.setItem("redirectPath", window.location.href);
sessionStorage.setItem("referenceUrl", window.location.href);
window.open(
combineUrl(window.DocSpaceConfig?.proxy?.url, "/login"),
"_self"

View File

@ -70,10 +70,10 @@ const LoginForm: React.FC<ILoginFormProps> = ({
if (!response || !response.token) throw new Error("Empty API response");
setWithCredentialsStatus(true);
const redirectPath = localStorage.getItem("redirectPath");
const redirectPath = sessionStorage.getItem("referenceUrl");
if (redirectPath) {
localStorage.removeItem("redirectPath");
sessionStorage.removeItem("referenceUrl");
window.location.href = redirectPath;
}
})
@ -153,9 +153,9 @@ const LoginForm: React.FC<ILoginFormProps> = ({
const session = !isChecked;
login(user, hash, session)
.then((res: string | object) => {
const redirectPath = localStorage.getItem("redirectPath");
const redirectPath = sessionStorage.getItem("referenceUrl");
if (redirectPath) {
localStorage.removeItem("redirectPath");
sessionStorage.removeItem("referenceUrl");
window.location.href = redirectPath;
return;
}