From f0cd46b339bebed013069818c77aa4428f7113e2 Mon Sep 17 00:00:00 2001 From: MgenGlder Date: Sat, 27 Dec 2025 15:37:34 -0500 Subject: [PATCH] fix: Introduce authorization headers to Notes requests --- src/pages/Notes.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pages/Notes.tsx b/src/pages/Notes.tsx index f65af1c..2ed373e 100644 --- a/src/pages/Notes.tsx +++ b/src/pages/Notes.tsx @@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react" import { useNavigate } from "react-router-dom" import "../css/theme.css" import { CircleArrowLeft } from "lucide-react" +import { useAuthServiceProvider } from "../providers/AuthServiceProvider" interface ServerResponse { message: string @@ -14,6 +15,7 @@ const Notes: React.FC = () => { const [message, setMessage] = useState("") const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState(null) + const { token } = useAuthServiceProvider() const handleGoBack = (): void => { navigate("/") @@ -33,7 +35,8 @@ const Notes: React.FC = () => { method: "POST", body: JSON.stringify({title: title, content: notes}), headers: { - "Content-type": "application/json; charset=UTF-8" + "Content-type": "application/json; charset=UTF-8", + "Authorization": `bearer ${token || ""}`, } } ) @@ -54,7 +57,13 @@ const Notes: React.FC = () => { const fetchMessage = async (): Promise => { try { const response = await fetch( - "https://api.dearborncodingclub.com/notes/" + "https://api.dearborncodingclub.com/notes/", { + method: "GET", + headers: { + "Content-type": "application/json; charset=UTF-8", + "Authorization": `bearer ${token || ""}`, + }, + } ) if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`)