category and logout fiexes

This commit is contained in:
Patryk
2025-06-09 21:17:30 +02:00
parent 207f8f7161
commit c2d4f5fb79
5 changed files with 21 additions and 31 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -7,7 +7,6 @@ import { Text } from "@/components/ui/text";
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);
@@ -21,10 +20,9 @@ export default function Wishlist() {
const styles = {
container: {
margin: 10,
}
}
},
};
// console.log("Wishlist notices:", wishlistNotices);
if (wishlistNotices.length === 0) {
return (
<Box style={styles.container} className="flex-row flex-1 justify-center">

View File

@@ -19,7 +19,7 @@ export function CategorySection({ notices, title }) {
};
fetchCategories();
});
}, []);
const categories = Array.from(
new Set(notices.map((notice) => notice.category))

View File

@@ -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;
// }
// },
};
},
{