added refresh token

This commit is contained in:
SlimusMinus
2026-08-03 02:44:57 +03:00
parent b6c61c72d9
commit abbcc330e7
16 changed files with 210 additions and 135 deletions

View File

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