kaveeshadinamidu commented on issue #184: URL: https://github.com/apache/incubator-shenyu-dashboard/issues/184#issuecomment-1047149726
Hey, @JooKS-me I think I found the issue. When redirecting to the http://localhost:9095/#/home it executes the componentDidMount() function at Home/index.js ``` componentDidMount() { const { dispatch } = this.props; dispatch({ type: "global/fetchPlatform" }); } ``` When the user do not have a token the API call fetchPlatfrom responds with an error message. `{"code":600,"message":"token is error"}` And then the componentDidMount() method at layouts/BasicLayout.js executes. ``` componentDidMount() { const token = window.sessionStorage.getItem("token"); if (!token) { this.props.history.push({ pathname: "/user/login" }); return; } const { dispatch } = this.props; dispatch({ type: "global/fetchPlatform" }); dispatch({ type: "global/fetchPlugins", payload: { callback: () => { this.setState({ pluginsLoaded: true }); } } }); } ``` Here it checks the availability of token and redirects them back to the login page if there is no token. Therefore when the home page componentDidMount() method executes (When redirecting directly to http://localhost:9095/#/home ) it executes an unauthorized API call and returns it with an error. So we need to check whether the user is authorized or not before making that request on the home page. By working around the code I have found two ways to resolve this error, 1) Suggestion 1 - Check whether the user is validated before making the API request Changing the componentDidMount() on src/routes/Home/index.js Whenever the home page renders it always checks for the availability of token and made the request. on src/routes/Home/index.js ``` componentDidMount() { const token = window.sessionStorage.getItem("token"); if (token) { const { dispatch } = this.props; dispatch({ type: "global/fetchPlatform" }); } } ``` 2) Suggestion two - Simply removing the componentDidMount() method on src/routes/Home/index.js When the home page is rendering the BasicLayout is also rendered.So both componentDidMount() methods executes. And in the basic layout's componentDidMount() method contains the same logic which is on the home page's componentDidMount() method also. This method also works fine. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
