diff --git a/src/pages/main.tsx b/src/pages/main.tsx index 7564e799dcd6a9c4cce713747937efd09892babb..be20e5bc7a73f7c0958eaf591f7535b82f5a02e4 100644 --- a/src/pages/main.tsx +++ b/src/pages/main.tsx @@ -21,25 +21,22 @@ const Main = () => { useEffect(() => { try { - alert(`${loginInfo?.token},${window.location.search}`); + const params = new URLSearchParams(window.location.search); + /** 不存在先直接跳转 */ - if (!loginInfo?.token && !window.location.search) { + if (!loginInfo?.token && !params.get("code")) { window.location.href = `${config.thirdPartyFrontEndPageUrl}/authorizedLogin.html?client_id=OM90JPKW&response_type=code&redirect_uri=${config.devAppUrl}`; return; } - if (!loginInfo?.token && window.location.search) { - const params = new URLSearchParams(window.location.search); - - if (params.get("code")) { - getToken(params.get("code") as string) - .then((res) => { - setLoginInfo(res.data); - }) - .catch((err) => { - alert(JSON.stringify(err)); - }); - } + if (!loginInfo?.token && params.get("code")) { + getToken(params.get("code") as string) + .then((res) => { + setLoginInfo(res.data); + }) + .catch((err) => { + alert(JSON.stringify(err)); + }); } } catch (error) { alert(error);