为多个组件和API添加用户登录状态检查,确保只有在用户登录后才能查询和修改收藏状态
This commit is contained in:
10
lib/api.ts
10
lib/api.ts
@@ -431,6 +431,11 @@ export const fetchUserProfile = async (): Promise<UserProfile> => {
|
||||
|
||||
export const addFavorite = async (request: FavoriteRequest): Promise<any> => {
|
||||
try {
|
||||
const token = await storage.getAccessToken();
|
||||
if (!token) {
|
||||
// throw new Error("Please login first");
|
||||
return;
|
||||
}
|
||||
// console.log("Adding favorite with request:", request);
|
||||
const response = await apiClient.post<ApiResponse<any>>(
|
||||
API_ENDPOINTS.FAVORITES,
|
||||
@@ -451,6 +456,11 @@ export const removeFavorite = async (request: {
|
||||
typeId: string;
|
||||
}): Promise<any> => {
|
||||
try {
|
||||
const token = await storage.getAccessToken();
|
||||
if (!token) {
|
||||
// throw new Error("Please login first");
|
||||
return;
|
||||
}
|
||||
console.log("Removing favorite with request:", request);
|
||||
const response = await apiClient.delete<ApiResponse<any>>(
|
||||
API_ENDPOINTS.FAVORITES,
|
||||
|
||||
Reference in New Issue
Block a user