Created
June 13, 2017 08:10
-
-
Save tricoder42/98a25bc9133946516b3baa9e9b08ad6b to your computer and use it in GitHub Desktop.
2017/06/13 [Medium] redux-saga factories and decorators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just an example of `isAuthenticated` selector | |
const selector = { | |
isAuthenticated: state => state.auth.isAuthenticated | |
} | |
export const authRequired = (saga) => function* (action) { | |
const isAuthenticated = yield select(selector.isAuthenticated) | |
// If user isn't authenticated, redirect him to /login | |
if (!isAuthenticated) { | |
yield call(to => window.location = to, `/login`) | |
// Otherwise, proceed to original saga | |
} else { | |
yield* saga(action) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment