Need help implementing authorization with React Router
My repo https://gitlab.liu.se/josgi523/tddd27_2024_project/-/tree/main/myapp/src?ref_type=heads
To know if the current user is logged in or not a listener needs to be added to the firebase auth object. I've tried adding it as context for the router and let the loaders check, but the site crashes with the message .
"Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
throwInvalidHookError@http://localhost:5173/node_modules/.vite/deps/chunk-GZ55BCQ2.js?v=457e94c6:12124:17 useContext@http://localhost:5173/node_modules/.vite/deps/chunk-YZZKIYU7.js?v=457e94c6:1062:29 loader@http://localhost:5173/src/views/App.tsx?t=1713373364404:25:26 runHandler@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=457e94c6:2591:26 callLoaderOrAction@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=457e94c6:2642:22 createRouter/callLoadersAndMaybeResolveData/results<@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=457e94c6:1995:88 callLoadersAndMaybeResolveData@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=457e94c6:1995:55 handleLoaders@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=457e94c6:1644:15 startNavigation@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=457e94c6:1501:15 initialize@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=457e94c6:1213:22 createBrowserRouter@http://localhost:5173/node_modules/.vite/deps/react-router-dom.js?v=457e94c6:4378:6 @http://localhost:5173/src/main.tsx?t=1713373364404:36:35"
Been mainly using this as source: https://reactrouter.com/en/main/start/tutorial