redux-auth-wrapper icon indicating copy to clipboard operation
redux-auth-wrapper copied to clipboard

React-router v6

Open Asher978 opened this issue 2 years ago • 9 comments

Hello,

Is this react-router v6 compatible?

Asher978 avatar Jan 17 '22 13:01 Asher978

Also wondering if this is v6 compatible

eleventhaus avatar Mar 19 '22 23:03 eleventhaus

Hi, unfortunately I'm not actively maintaining this repo any more. Looking at the react router v6 docs, it looks like there are some breaking changes so I wouldn't expect this to work without some modifications.

mjrussell avatar Mar 20 '22 04:03 mjrussell

I'm starting a fresh project and tried this and it seems to be working fine (with redux-first-history). What are the breaking changes in react-router v6 which affects redux-auth-wrapper?

import { connectedReduxRedirect } from 'redux-auth-wrapper/history4/redirect';
import { replace } from 'redux-first-history';

import LoadingPage from 'components/LoadingPage';

function redirectUser(state) {
  if (state.global.currentUser.id) {
    return '/test';
  }
  return '/login';
}

export const isAuthenticated = connectedReduxRedirect({
  redirectPath: state => redirectUser(state),
  authenticatedSelector: state => !!state.global.currentUser.id,
  authenticatingSelector: state => !state.global.checkedMeAuth,
  allowRedirectBack: false,
  AuthenticatingComponent: LoadingPage,
  wrapperDisplayName: 'IsAuthenticated',
  redirectAction: replace,
});

r3b311i0n avatar Mar 20 '22 07:03 r3b311i0n

That's good to hear! Do you know what version of history you are getting as a transitive dependency?

mjrussell avatar Mar 20 '22 14:03 mjrussell

Sure. It's history 5.3.0.

r3b311i0n avatar Mar 20 '22 18:03 r3b311i0n

Based on https://github.com/mjrussell/redux-auth-wrapper/issues/267 have you seen the query param populated properly?

mjrussell avatar Mar 20 '22 21:03 mjrussell

Seems to be working fine for me (with redirectPath as a string or a function). But I'm using connectedReduxRedirect with redux-first-history instead of connectedRouterRedirect. I think connected-react-router doesn't work well with history 5 and doesn't support react-router 6.

r3b311i0n avatar Mar 21 '22 06:03 r3b311i0n

in the react-router-dom official website said:

You'll also want to remove the history dependency from your package.json. The history library is a direct dependency of v6 (not a peer dep), so you won't ever import or use it directly. Instead, you'll use the useNavigate() hook for all navigation (see below).

so are you sure it's compatible with v6?

alibalouchi95 avatar Jul 28 '22 20:07 alibalouchi95

Just to chime in, in case it's helpful to anyone: My app was upgraded to redux-first-history and has been able to use this lib successfully, but I did have to set allowRedirectBack: false or else I got errors.

pinksynth avatar May 20 '23 20:05 pinksynth