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