oidc-react icon indicating copy to clipboard operation
oidc-react copied to clipboard

Possible interference with AuthProvider and react-router route loader

Open cscottrun opened this issue 1 year ago • 1 comments
trafficstars

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} />;
}
`

cscottrun avatar Feb 26 '24 21:02 cscottrun

Thank you for opening this issue. Have you found a solution for your problem, or are you still having issues?

simenandre avatar Oct 22 '24 14:10 simenandre

I am closing this now as stale. If this still is an issue, please let me know!

simenandre avatar Dec 09 '24 21:12 simenandre