refactor: remember path before login

This commit is contained in:
Tristan Yang
2023-08-01 18:17:27 +08:00
parent 7d75aeb643
commit b9b62bc3be
+5 -5
View File
@@ -26,11 +26,6 @@ const RequireAuth: FC<Props> = ({ children, redirectTo = "/login" }) => {
if (checkingInitialized || !loginConfigSuccess) return <Loading fullscreen={true} />; if (checkingInitialized || !loginConfigSuccess) return <Loading fullscreen={true} />;
// 未初始化 则先走setup 流程 // 未初始化 则先走setup 流程
if (!initialized) return <Navigate to={`/onboarding`} replace />; if (!initialized) return <Navigate to={`/onboarding`} replace />;
// 开启guest 并且没token 而且是允许guest访问的路由 则先去过渡页登录
if (loginConfig?.guest && !token && allowGuest) return <Navigate to={"/guest_login"} replace />;
// 登陆者是guest,并且不允许访问
if (token && guest && !allowGuest) return <Navigate to={"/"} replace />;
// console.log("authhhhh", allowGuest, token, guest);
if (!token) { if (!token) {
// 记录下当前的路径,登录后跳转回来 // 记录下当前的路径,登录后跳转回来
const ignorePath = `/setting/my_account`; const ignorePath = `/setting/my_account`;
@@ -40,6 +35,11 @@ const RequireAuth: FC<Props> = ({ children, redirectTo = "/login" }) => {
); );
return <Navigate to={redirectTo} replace />; return <Navigate to={redirectTo} replace />;
} }
// 开启guest 并且没token 而且是允许guest访问的路由 则先去过渡页登录
if (loginConfig?.guest && !token && allowGuest) return <Navigate to={"/guest_login"} replace />;
// 登陆者是guest,并且不允许访问
if (token && guest && !allowGuest) return <Navigate to={"/"} replace />;
// console.log("authhhhh", allowGuest, token, guest);
const tryPath = localStorage.getItem(KEY_LOCAL_TRY_PATH); const tryPath = localStorage.getItem(KEY_LOCAL_TRY_PATH);
if (tryPath) { if (tryPath) {
localStorage.removeItem(KEY_LOCAL_TRY_PATH); localStorage.removeItem(KEY_LOCAL_TRY_PATH);