bjerkio/oidc-react

Possible interference with AuthProvider and react-router route loader

cscottrun opened this issue · 0 comments

It appears there may be some interference between my oidc-react AuthProvider and the use of the new route loader with react-router v.6.
To provide context, the loader provides data to the route element before it renders.
My AuthProvider works completely fine, redirecting to login, when i do not use the loader. But when I do use a loader (for example fetching data for my homepage), then no redirect to login occurs and my app of course fails to get the necessary credentials to render the homepage.
I'm wondering if anyone else has had this experience and what solution could be. Thanks.
Here's an abbreviated version of my code

App.js

`const router = createBrowserRouter([
  {
    id: "root",
    path: "/",
    errorElement: <FullPageError />,
    element: <Authentication />, // < --  this is just my <AuthProvider /> and all the necessary config props. 
    children: [
      {
        element: <LayoutWithProps />,
        children: [
          {
            index: true,
            element: <Applications />,
            loader: getApplications,  // <-- this is the line that messes things up. However it works great if i have an active session.
          }
        ],
      },
    ],
  },
]);

function App() {
  return <RouterProvider router={router} />;
}
`