From ffbaa21ee4bd87b8ca5bebf64b26eb8481db1fa1 Mon Sep 17 00:00:00 2001 From: Dennis Chen <41879777+chennisden@users.noreply.github.com> Date: Mon, 10 Jun 2024 23:32:35 -0700 Subject: [PATCH] Only try to authenticate if apiKey exists (#100) --- frontend/src/pages/RobotDetails.tsx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/RobotDetails.tsx b/frontend/src/pages/RobotDetails.tsx index 69e00745..440de2bd 100644 --- a/frontend/src/pages/RobotDetails.tsx +++ b/frontend/src/pages/RobotDetails.tsx @@ -82,12 +82,22 @@ const RobotDetails = () => { }, [id]); useEffect(() => { - const fetchUserId = async () => { - const user_id = await auth_api.currentUser(); - setUserId(user_id); - }; - fetchUserId(); - }, []); + if (auth.isAuthenticated) { + try { + const fetchUserId = async () => { + const user_id = await auth_api.currentUser(); + setUserId(user_id); + }; + fetchUserId(); + } catch (err) { + if (err instanceof Error) { + setError(err.message); + } else { + setError("An unexpected error occurred"); + } + } + } + }, [auth.isAuthenticated]); const navigate = useNavigate();