fix account
This commit is contained in:
@@ -7,7 +7,7 @@ const API_URL = "https://hopp.zikor.pl/api/v1";
|
||||
|
||||
export const useAuthStore = create(
|
||||
persist(
|
||||
(set) => {
|
||||
(set, get) => {
|
||||
// Dodaj interceptor tylko raz
|
||||
if (!axios.interceptors.response.handlers.length) {
|
||||
axios.interceptors.response.use(
|
||||
@@ -17,7 +17,7 @@ export const useAuthStore = create(
|
||||
(error.response && error.response.status === 401) ||
|
||||
error.response.status === 403
|
||||
) {
|
||||
set({ user_id: null, token: null, isLoading: false });
|
||||
set({ user: null, token: null, isLoading: false });
|
||||
delete axios.defaults.headers.common["Authorization"];
|
||||
}
|
||||
return Promise.reject(error);
|
||||
@@ -113,24 +113,24 @@ export const useAuthStore = create(
|
||||
}
|
||||
},
|
||||
|
||||
checkAuth: async () => {
|
||||
const { token } = useAuthStore.getState();
|
||||
if (!token) return null;
|
||||
// checkAuth: async () => {
|
||||
// const { token } = useAuthStore.getState();
|
||||
// if (!token) return null;
|
||||
|
||||
set({ isLoading: true });
|
||||
try {
|
||||
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||
// set({ isLoading: true });
|
||||
// try {
|
||||
// axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
||||
|
||||
const response = await axios.get(`${API_URL}/auth/me`);
|
||||
// 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;
|
||||
}
|
||||
},
|
||||
// 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