Skip to content

Instantly share code, notes, and snippets.

@tricoder42
Created June 13, 2017 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tricoder42/98a25bc9133946516b3baa9e9b08ad6b to your computer and use it in GitHub Desktop.
Save tricoder42/98a25bc9133946516b3baa9e9b08ad6b to your computer and use it in GitHub Desktop.
2017/06/13 [Medium] redux-saga factories and decorators
// 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