为多个组件和API添加用户登录状态检查,确保只有在用户登录后才能查询和修改收藏状态

This commit is contained in:
yuchenglong
2026-01-16 18:02:08 +08:00
parent b5fd763c7e
commit 887d205f65
8 changed files with 107 additions and 50 deletions

View File

@@ -5,6 +5,7 @@ import { IconSymbol, IconSymbolName } from "@/components/ui/icon-symbol";
import { Colors } from "@/constants/theme";
import { useTheme } from "@/context/ThemeContext";
import { fetchFavorites, removeFavorite } from "@/lib/api";
import { storage } from "@/lib/storage";
import { FavoriteItem, Match } from "@/types/api";
import { Image } from "expo-image";
import { useRouter } from "expo-router";
@@ -67,6 +68,13 @@ export default function FavoriteScreen() {
if (loading) return;
setLoading(true);
try {
const token = await storage.getAccessToken();
if (!token) {
setFavorites([]);
setHasMore(false);
return;
}
const currentPage = isRefresh ? 1 : page;
const res = await fetchFavorites(activeTab, currentPage);
if (isRefresh) {