From 3aab6c86879925e7c92baa8d28529e71fdbb4237 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sat, 12 Feb 2022 09:55:06 +0800 Subject: [PATCH] Support from link. --- web/src/App.js | 1 + web/src/Setting.js | 8 ++++++++ web/src/auth/AuthCallback.js | 4 +++- web/src/auth/LoginPage.js | 4 +++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/web/src/App.js b/web/src/App.js index dbb12e7f..d8ea1760 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -441,6 +441,7 @@ class App extends Component { renderLoginIfNotLoggedIn(component) { if (this.state.account === null) { + sessionStorage.setItem("from", window.location.pathname); return } else if (this.state.account === undefined) { return null; diff --git a/web/src/Setting.js b/web/src/Setting.js index 5b1a0b66..b03959dc 100644 --- a/web/src/Setting.js +++ b/web/src/Setting.js @@ -638,3 +638,11 @@ export function getRandomName() { export function getRandomNumber() { return Math.random().toString(10).slice(-11); } + +export function getFromLink() { + const from = sessionStorage.getItem("from"); + if (from === null) { + return "/"; + } + return from; +} diff --git a/web/src/auth/AuthCallback.js b/web/src/auth/AuthCallback.js index 5ef4b90c..e077a2de 100644 --- a/web/src/auth/AuthCallback.js +++ b/web/src/auth/AuthCallback.js @@ -104,7 +104,9 @@ class AuthCallback extends React.Component { if (responseType === "login") { Util.showMessage("success", `Logged in successfully`); // Setting.goToLinkSoft(this, "/"); - Setting.goToLink("/"); + + const link = Setting.getFromLink(); + Setting.goToLink(link); } else if (responseType === "code") { const code = res.data; Setting.goToLink(`${oAuthParams.redirectUri}?code=${code}&state=${oAuthParams.state}`); diff --git a/web/src/auth/LoginPage.js b/web/src/auth/LoginPage.js index c781d6e6..6e8dc08e 100644 --- a/web/src/auth/LoginPage.js +++ b/web/src/auth/LoginPage.js @@ -124,7 +124,9 @@ class LoginPage extends React.Component { const responseType = this.state.type; if (responseType === "login") { Util.showMessage("success", `Logged in successfully`); - Setting.goToLink("/"); + + const link = Setting.getFromLink(); + Setting.goToLink(link); } else if (responseType === "code") { const code = res.data;