fix(auth): redirect to splash after logout

This commit is contained in:
2026-06-17 15:07:16 +08:00
parent 0d2a515e51
commit bda1605ce7
7 changed files with 48 additions and 5 deletions
+14 -4
View File
@@ -1,7 +1,8 @@
"use client";
import { useEffect } from "react";
import { useEffect, useRef } from "react";
import { useRouter } from "next/navigation";
import { signOut } from "next-auth/react";
import { MobileShell, SettingsSection } from "@/app/_components/core";
import { ROUTES } from "@/router/routes";
@@ -36,15 +37,24 @@ export function SidebarScreen() {
const auth = useAuthState();
const authDispatch = useAuthDispatch();
const router = useRouter();
const isLogoutRedirectPendingRef = useRef(false);
useEffect(() => {
userDispatch({ type: "UserInit" });
}, [userDispatch]);
const handleLogoutClick = () => {
authDispatch({ type: "AuthReset" });
userDispatch({ type: "UserLogout" });
useEffect(() => {
if (!isLogoutRedirectPendingRef.current) return;
if (auth.isLoading || auth.loginStatus !== "notLoggedIn") return;
isLogoutRedirectPendingRef.current = false;
router.replace(ROUTES.splash);
}, [auth.isLoading, auth.loginStatus, router]);
const handleLogoutClick = () => {
isLogoutRedirectPendingRef.current = true;
userDispatch({ type: "UserClearLocal" });
authDispatch({ type: "AuthLogoutSubmitted" });
void signOut({ redirect: false });
};
// 状态派生:未登录 / 已登录未 VIP / 已登录 VIP