refactor(router): introduce app navigation manager
This commit is contained in:
@@ -8,22 +8,14 @@
|
||||
* 不再承担全局状态同步职责。
|
||||
*/
|
||||
import { useEffect, useRef } from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
|
||||
import { AuthStorage } from "@/data/storage/auth";
|
||||
import { useAuthState } from "@/stores/auth/auth-context";
|
||||
import { useChatDispatch } from "@/stores/chat/chat-context";
|
||||
import { PROTECTED_ROUTES, ROUTES, type StaticRoute } from "@/router/routes";
|
||||
|
||||
function isProtectedPath(pathname: string): boolean {
|
||||
return PROTECTED_ROUTES.some((route: StaticRoute) => pathname === route);
|
||||
}
|
||||
|
||||
export function ChatAuthSync() {
|
||||
const authState = useAuthState();
|
||||
const chatDispatch = useChatDispatch();
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
const prevSessionKeyRef = useRef<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -35,9 +27,6 @@ export function ChatAuthSync() {
|
||||
|
||||
if (authState.loginStatus === "notLoggedIn") {
|
||||
chatDispatch({ type: "ChatLogout" });
|
||||
if (isProtectedPath(pathname)) {
|
||||
router.replace(ROUTES.splash);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,8 +54,6 @@ export function ChatAuthSync() {
|
||||
authState.isLoading,
|
||||
authState.loginStatus,
|
||||
chatDispatch,
|
||||
pathname,
|
||||
router,
|
||||
]);
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user