added refresh token
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useState } from "react";
|
||||
import { API_URL } from "../config/authConstants";
|
||||
import {useState} from "react";
|
||||
import {API_URL} from "../config/authConstants";
|
||||
import {apiFetch} from "../api/apiClient";
|
||||
|
||||
/**
|
||||
* useUpdateProfile — хук для обновления профиля пользователя.
|
||||
@@ -14,8 +15,6 @@ export function useUpdateProfile() {
|
||||
setError("");
|
||||
|
||||
try {
|
||||
const token = localStorage.getItem("token");
|
||||
|
||||
// Используем FormData — чтобы отправить файл аватара вместе с текстовыми полями
|
||||
const formData = new FormData();
|
||||
formData.append("id", userId);
|
||||
@@ -30,11 +29,8 @@ export function useUpdateProfile() {
|
||||
formData.append("avatar", profileData.avatar);
|
||||
}
|
||||
|
||||
const res = await fetch(`${API_URL}/api/v1/users/${userId}`, {
|
||||
const res = await apiFetch(`${API_URL}/api/v1/users/${userId}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${token}`,
|
||||
},
|
||||
body: formData,
|
||||
});
|
||||
|
||||
@@ -43,8 +39,7 @@ export function useUpdateProfile() {
|
||||
throw new Error(data.message || `Ошибка ${res.status}`);
|
||||
}
|
||||
|
||||
const updatedUser = await res.json();
|
||||
return updatedUser;
|
||||
return await res.json();
|
||||
} catch (err) {
|
||||
setError(err.message || "Failed to save profile");
|
||||
return null;
|
||||
@@ -54,4 +49,4 @@ export function useUpdateProfile() {
|
||||
};
|
||||
|
||||
return { updateProfile, loading, error };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user