Skip to content

Instantly share code, notes, and snippets.

@AllGistsEqual
Created April 25, 2021 21:03
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 AllGistsEqual/9d2da1da9ec29354690790e2e496b4ce to your computer and use it in GitHub Desktop.
Save AllGistsEqual/9d2da1da9ec29354690790e2e496b4ce to your computer and use it in GitHub Desktop.
export const userMiddleware: Middleware = ({ dispatch }) => next => action => {
next(action)
if (attemptLogin.match(action)) {
const { email, password } = action.payload
login(email, password)
.then(() => dispatch(setLogin(email, false)))
.catch(err => dispatch(setLogout('denied', err.message)))
}
if (attemptSignUp.match(action)) {
const { email, password } = action.payload
createAccount(email, password)
.then(() => dispatch(setLogin(email, true)))
.catch(err => dispatch(setLogout('denied', err.message)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment