diff --git a/ArtisanConnect/api/categories.jsx b/ArtisanConnect/api/categories.jsx index 329bef6..8ebbebb 100644 --- a/ArtisanConnect/api/categories.jsx +++ b/ArtisanConnect/api/categories.jsx @@ -8,7 +8,9 @@ export async function listCategories() { const headers = token ? { Authorization: `Bearer ${token}` } : {}; try { - const response = await axios.get(`${API_URL}/vars/categories`, { headers: headers }); + const response = await axios.get(`${API_URL}/vars/categories`, { + headers: headers, + }); return response.data; } catch (err) { console.error("Nie udało się pobrać listy kategorii.", err.response.status); diff --git a/ArtisanConnect/api/wishlist.jsx b/ArtisanConnect/api/wishlist.jsx index b54a30a..ce59688 100644 --- a/ArtisanConnect/api/wishlist.jsx +++ b/ArtisanConnect/api/wishlist.jsx @@ -28,7 +28,6 @@ export async function getWishlist() { try { const response = await axios.get(`${API_URL}/`, { headers }); - console.log("Wishlist response:", response.data); return response.data; } catch (error) { console.error("Error fetching wishlist:", error); diff --git a/ArtisanConnect/app/(tabs)/wishlist.jsx b/ArtisanConnect/app/(tabs)/wishlist.jsx index e106281..88b8955 100644 --- a/ArtisanConnect/app/(tabs)/wishlist.jsx +++ b/ArtisanConnect/app/(tabs)/wishlist.jsx @@ -4,27 +4,25 @@ import { NoticeCard } from "@/components/NoticeCard"; import { Ionicons } from "@expo/vector-icons"; import { Box } from "@/components/ui/box"; import { Text } from "@/components/ui/text"; -import {useCallback} from "react"; +import { useCallback } from "react"; import { useFocusEffect } from "@react-navigation/native"; - export default function Wishlist() { const wishlistNotices = useWishlist((state) => state.wishlistNotices); const fetchWishlist = useWishlist((state) => state.fetchWishlist); useFocusEffect( - useCallback(() => { - fetchWishlist(); - }, [fetchWishlist]) + useCallback(() => { + fetchWishlist(); + }, [fetchWishlist]) ); const styles = { container: { margin: 10, - } - } + }, + }; - // console.log("Wishlist notices:", wishlistNotices); if (wishlistNotices.length === 0) { return ( diff --git a/ArtisanConnect/components/CategorySection.jsx b/ArtisanConnect/components/CategorySection.jsx index 2d9321e..cb82cd1 100644 --- a/ArtisanConnect/components/CategorySection.jsx +++ b/ArtisanConnect/components/CategorySection.jsx @@ -19,7 +19,7 @@ export function CategorySection({ notices, title }) { }; fetchCategories(); - }); + }, []); const categories = Array.from( new Set(notices.map((notice) => notice.category)) diff --git a/ArtisanConnect/store/authStore.jsx b/ArtisanConnect/store/authStore.jsx index 47d83dc..fd9a468 100644 --- a/ArtisanConnect/store/authStore.jsx +++ b/ArtisanConnect/store/authStore.jsx @@ -2,6 +2,7 @@ import { create } from "zustand"; import { createJSONStorage, persist } from "zustand/middleware"; import AsyncStorage from "@react-native-async-storage/async-storage"; import axios from "axios"; +import { router } from "expo-router"; const API_URL = "https://hopp.zikor.pl/api/v1"; @@ -104,34 +105,24 @@ export const useAuthStore = create( }, signOut: async () => { + const { token } = get(); + const headers = token ? { Authorization: `Bearer ${token}` } : {}; try { - await axios.post(`${API_URL}/auth/logout`); + await axios.post( + `${API_URL}/auth/logout`, + {}, + { + headers: headers, + } + ); } catch (error) { console.error("Logout error:", error); } finally { delete axios.defaults.headers.common["Authorization"]; set({ user_id: null, token: null }); + router.replace("/login"); } }, - - // checkAuth: async () => { - // const { token } = useAuthStore.getState(); - // if (!token) return null; - - // set({ isLoading: true }); - // try { - // axios.defaults.headers.common["Authorization"] = `Bearer ${token}`; - - // const response = await axios.get(`${API_URL}/auth/me`); - - // set({ user_id: response.data, isLoading: false }); - // return response.data; - // } catch (error) { - // delete axios.defaults.headers.common["Authorization"]; - // set({ user_id: null, token: null, isLoading: false }); - // return null; - // } - // }, }; }, {