diff --git a/src/App.js b/src/App.js index 57ae74b..9d43fee 100644 --- a/src/App.js +++ b/src/App.js @@ -31,7 +31,8 @@ import { useCartStore } from './context/CartContext/CartContext'; const App = () => { const [cookies] = useCookies(['user']); - const user = cookies.user; + const user = cookies?.user; + const userId = user?.id; const [currentPage, setCurrentPage] = useState(''); // const { setContext } = useAppContext(); // Assuming useAppContext provides setContext const { fetchAllCollectionsForUser, selectedCollection } = @@ -48,7 +49,7 @@ const App = () => { useEffect(() => { if (user) { - fetchAllCollectionsForUser(user.id) + fetchAllCollectionsForUser() .then(() => { setIsLoading(false); }) @@ -57,7 +58,7 @@ const App = () => { setIsLoading(false); }); } - }, [user, fetchAllCollectionsForUser, setIsLoading, selectedCollection]); + }, [userId, fetchAllCollectionsForUser, setIsLoading, selectedCollection]); // useEffect(() => { // if (user) { // fetchAllDecksForUser(user?.id).catch((err) => diff --git a/src/context/CollectionContext/CollectionContext.jsx b/src/context/CollectionContext/CollectionContext.jsx index d4bf44b..327103d 100644 --- a/src/context/CollectionContext/CollectionContext.jsx +++ b/src/context/CollectionContext/CollectionContext.jsx @@ -72,6 +72,7 @@ export const CollectionProvider = ({ children }) => { const [openChooseCollectionDialog, setOpenChooseCollectionDialog] = useState(false); const userId = cookies?.user?.id; + console.log('USER ID:', userId); const lastFetchedTime = useRef(null); const fetchAndSetCollections = useCallback(async () => { @@ -87,6 +88,10 @@ export const CollectionProvider = ({ children }) => { if (!shouldFetch()) return; try { + if (!userId) { + console.error('No user ID found.'); + return; + } lastFetchedTime.current = Date.now(); const response = await fetchWrapper( createApiUrl(`${userId}/collections`),