refactor(auth): clean up user logout handling in SidebarScreen

This commit is contained in:
2026-06-17 11:11:25 +08:00
parent 67dcf97edc
commit ee760abdf5
2 changed files with 1 additions and 8 deletions
@@ -37,23 +37,16 @@ export function SidebarScreen() {
const authDispatch = useAuthDispatch();
const router = useRouter();
// 等价 Dart: UserBloc.init
useEffect(() => {
userDispatch({ type: "UserInit" });
}, [userDispatch]);
// 等价 Dart: BlocConsumer<UserBloc> 的 listenerprofile_view.dart:24-34
// 仅在 currentUser 由非 null 跳到 null 时触发清理
// 通过 `useAuthState()` 主动订阅 loginStatus;这里只需重置 auth + 跳 /chat
const prevUserRef = useRef<UserView | null>(user.currentUser);
useEffect(() => {
const wasLoggedIn = prevUserRef.current != null;
const isNowLoggedOut = user.currentUser == null;
prevUserRef.current = user.currentUser;
if (wasLoggedIn && isNowLoggedOut) {
// AuthReset:清场(context 回到 initialStateloginStatus="notLoggedIn"
// 不需要再 dispatch AuthInit 校验 storage —— userLogoutActor 已清空 storage
// AuthReset 直接写回 initialState 已与 storage 对齐。
authDispatch({ type: "AuthReset" });
router.replace(ROUTES.chat);
}