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

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