added refresh token
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { useState, useCallback } from "react";
|
||||
import { API_URL } from "../config/authConstants";
|
||||
import { apiFetch } from "../api/apiClient";
|
||||
|
||||
/**
|
||||
* useDeletePost — хук для удаления объявления.
|
||||
*
|
||||
*
|
||||
* @returns {Object} { deletePost, loading, error }
|
||||
*/
|
||||
export function useDeletePost() {
|
||||
@@ -13,14 +14,10 @@ export function useDeletePost() {
|
||||
const deletePost = useCallback(async (postId) => {
|
||||
setLoading(true);
|
||||
setError("");
|
||||
|
||||
|
||||
try {
|
||||
const token = localStorage.getItem("token");
|
||||
const res = await fetch(`${API_URL}/api/v1/posts/${postId}`, {
|
||||
const res = await apiFetch(`${API_URL}/api/v1/posts/${postId}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
||||
},
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
@@ -37,4 +34,4 @@ export function useDeletePost() {
|
||||
}, []);
|
||||
|
||||
return { deletePost, loading, error };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user