المشكلة تحدث حينما تحاول تعديل المهمة . وذلك بسبب عدم إرسال ال token .
في ملف app\libs\request.ts في دالة updateTodo يجب إضافة ال token :
export async function updateTodo(id: string ,title:string) {
const token = localStorage.getItem("token");
const res = await fetch(`http://localhost:3000/api/todos/${id}`, {
method: "PATCH",
headers: {
"Content-Type" : "application/json",
"Authorization": `Bearer ${token}`
},
body: JSON.stringify({title})
});
if(!res.ok) throw new Error("فشل في تحديث المهمة");
const data = await res.json();
return data.todo;
}
request.ts