From 8d618d09b802f19d28cd248c70d45a3c5dc27331 Mon Sep 17 00:00:00 2001 From: Leanstix Date: Thu, 12 Sep 2024 03:18:12 +0100 Subject: [PATCH 1/2] check --- app/my-resumes/components/resumes-dashboard.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/my-resumes/components/resumes-dashboard.js b/app/my-resumes/components/resumes-dashboard.js index 8861558..a20edd5 100644 --- a/app/my-resumes/components/resumes-dashboard.js +++ b/app/my-resumes/components/resumes-dashboard.js @@ -39,6 +39,8 @@ export default function Resumes() { } }; + console.log(fetchUserData) + if (loading) { return

Loading...

; // Display loading state } From 7fb8f26e3a40abb19cb24235d171bda2a5ee09b6 Mon Sep 17 00:00:00 2001 From: Leanstix Date: Thu, 12 Sep 2024 14:45:39 +0100 Subject: [PATCH 2/2] check --- .../components/resumes-dashboard.js | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/app/my-resumes/components/resumes-dashboard.js b/app/my-resumes/components/resumes-dashboard.js index a20edd5..9d995e2 100644 --- a/app/my-resumes/components/resumes-dashboard.js +++ b/app/my-resumes/components/resumes-dashboard.js @@ -3,41 +3,44 @@ import { useEffect, useState } from "react"; import Cookies from "js-cookie"; export default function Resumes() { - const [user, setUser] = useState(null); // State to store user information - const [loading, setLoading] = useState(true); // State to manage loading status + const [user, setUser] = useState(null); + const [loading, setLoading] = useState(true); useEffect(() => { const authToken = Cookies.get("analogueshifts"); // Retrieve the stored token + const fetchUserData = async (token) => { + try { + const res = await fetch("https://api.analogueshifts.app/api/user", { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + Authorization: `Bearer ${token}`, + }, + }); + + if (!res.ok) throw new Error("Failed to fetch user information"); + + const data = await res.json(); + setUser(data); // Store the user details in state + } catch (error) { + console.error("Error fetching user data:", error.message); + } finally { + setLoading(false); // Stop loading after the fetch is complete + } + }; + if (authToken) { // If token exists, fetch user data from the API + console.log("user token exists") fetchUserData(authToken); } else { setLoading(false); // No token, stop loading } }, []); - const fetchUserData = async (token) => { - try { - const res = await fetch("https://api.analogueshifts.app/api/user", { - method: "GET", - headers: { - "Content-Type": "application/json", - Accept: "application/json", - Authorization: `Bearer ${token}`, // Pass the token in the Authorization header - }, - }); - - if (!res.ok) throw new Error("Failed to fetch user information"); - - const data = await res.json(); - setUser(data); // Store the user details in state - } catch (error) { - console.error("Error fetching user data:", error.message); - } finally { - setLoading(false); // Stop loading after the fetch is complete - } - }; + console.log(fetchUserData)