Skip to content

Commit

Permalink
Only try to authenticate if apiKey exists (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
chennisden authored Jun 11, 2024
1 parent ecd8255 commit ffbaa21
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions frontend/src/pages/RobotDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit ffbaa21

Please sign in to comment.