AxaFrance / oidc-client

Light, Secure, Pure Javascript OIDC (Open ID Connect) Client. We provide also a REACT wrapper (compatible NextJS, etc.).
MIT License
598 stars 161 forks source link

Problem with react-router-dom v6? #827

Closed furdzik closed 2 years ago

furdzik commented 2 years ago

Issue and Steps to Reproduce

I have a code, like this:

App.jsx:

import { OidcProvider } from '@axa-fr/react-oidc';

<OidcProvider configuration={oidcConfiguration}>
  // ...
  <RoutesConfig />
  //  ...
</OidcProvider>

RoutesConfig.jsx

<BrowserRouter basename="/somebase">
  <Routes>
    <Route
      path="/"
      element={(
        <OidcSecure>
          <MyComponent />
         </OidcSecure>
      )}
    />
  </Routes>
</BrowserRouter>

I got an error.

TypeError: Cannot read properties of null (reading 'hasChildNodes')

It is still doing what needs to be done, but my app crashes before redirect.
Fothermore when login is successful, It returns with no error
I don't want the app to crash before redirect.

When I don't have OidcSecure wrapped, and click login() funcion on some button I don't gent this error.
(But of course I need to be automatic).

const { login, logout, isAuthenticated } = useOidc();

// ...

<button onClick={() => login()}>login</button>

If I try to do login automatic i got the same error. Exacly like with OidcSecure. I have tried to use withOidcSecure, but in new reacr-router-dom it's needed to return a component like: <Component /> not as a function.

  import { useOidc } from '@axa-fr/react-oidc';

  // ...

  const { login, logout, isAuthenticated } = useOidc();
  login();
  // ...

It could be something with react-router-dom in 6.3.0 version? Or maybe my use case is wrong?

Versions

Screenshots

image

Expected

No error

Actual

Error as on screen

Additional Details

guillaume-chervet commented 2 years ago

Hi @furdzik ,

Thank you very much for your issue.

I cannot reproduce the error with beta 13 and :

Do you have a sample of code on git or something else where I can reproduce the error quickly ?

furdzik commented 2 years ago

Hi @guillaume-chervet,

Thank you for quick replay.

After your info, I had checked the whole app, and it was a problem not connected with my previous assumptions (redirect cased code from other package to break because it couldn't find a div with needed ref).

So sorry I didn't think of this sooner!

I am so sorry for the hassle 🙏

(Should I close this issue or should you?)

guillaume-chervet commented 2 years ago

Thank you for using reatc oidc @furdzik , I hope it will help you. Yes please, feel free to close the issue :)