category and logout fiexes
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -4,10 +4,9 @@ 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);
|
||||
@@ -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">
|
||||
|
||||
@@ -19,7 +19,7 @@ export function CategorySection({ notices, title }) {
|
||||
};
|
||||
|
||||
fetchCategories();
|
||||
});
|
||||
}, []);
|
||||
|
||||
const categories = Array.from(
|
||||
new Set(notices.map((notice) => notice.category))
|
||||
|
||||
@@ -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;
|
||||
// }
|
||||
// },
|
||||
};
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user