Skip to content
This repository has been archived by the owner on Sep 12, 2020. It is now read-only.

comparison to use of "onEnter" #6

Open
tony-kerz opened this issue Dec 14, 2015 · 5 comments
Open

comparison to use of "onEnter" #6

tony-kerz opened this issue Dec 14, 2015 · 5 comments
Labels

Comments

@tony-kerz
Copy link

hi josh,

thanks for the example!

wondering if you can contrast your approach to that suggested by the rackt guys:

http://stackoverflow.com/a/32905508/2371903
https://github.com/rackt/react-router/tree/master/examples/auth-flow

best,
tony.

@mjrussell
Copy link

@tony-kerz the example you link using onEnter will not work when you want to check some information against a redux store, hence the reason for using the willMount/willReceive lifecycle method approach.

React-Router is used in non-redux apps, so they dont offer up a way to take advantage of the store.

The only other way I know of to access the store in onEnter is with this type of approach: https://github.com/CrocoDillon/universal-react-redux-boilerplate/blob/master/src/routes.jsx

@weblancaster
Copy link

Hey @mjrussell I'm using onEnter and works fine, I just call isAuthenticated function on onEnter={isAuthenticated} and there I get the store state as so store.getState() then I check if not authenticated and redirect to login.

@mjrussell
Copy link

onEnter works fine provided you have access to the store. Typically components in redux do not have an instance of the store except through the react-redux connect function. Im sure you can do a number of different ways to pass down the store to your onEnter though

@tony-kerz
Copy link
Author

i had to use some closure trickery to have access to the store from the on-handler function,
it would be nice if there was a less involved way to accomplish that.

i'm also not thrilled about the flow around diverting from a protected route,
to the login, and back to the original target. i think i read somewhere that it
was bad form to dispatch actions from reducers, so i handle that final transition
to the original target
in a state observer. a bit convoluted for my taste, but i was
thinking that onEnter is idiomatic, so i was following through on that basis.

@mjrussell
Copy link

I included a section on contrasting the onEnter approach with a Higher Order Component approach in the motivation section of my utility library for HOC auth - https://github.com/mjrussell/redux-auth-wrapper#motivation

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants