Guest User

Untitled

a guest
Feb 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. export const checkLoginCredentials = (username, password) => {
  2. let data = {username: username, password: password}
  3. fetch('/authenticate', {
  4. body: JSON.stringify(data),
  5. headers: {
  6. 'Content-Type': 'application/json'
  7. },
  8. method: 'POST'
  9. }).then(response => response.json()).then(responseJson => console.log(responseJson))}
  10.  
  11. export const checkLoginCredentials = (username, password) => {
  12. return (dispatch) => {
  13. dispatch({ type: 'FIND_USER'});
  14. let data = {username: username, password: password}
  15. return fetch('/authenticate', {
  16. body: JSON.stringify(data),
  17. headers: {
  18. 'Content-Type': 'application/json'
  19. },
  20. method: 'POST'
  21. }).then(response => response.json()).then(responseJson => dispatch({ type: 'AUTHENTICATE', payload: responseJson }))}}
  22.  
  23. import { combineReducers, createStore, applyMiddleware, compose } from 'redux'
  24. import userReducer from './userReducer'
  25. import gameReducer from './gameReducer'
  26. import thunk from 'redux-thunk';
  27.  
  28.  
  29. // we wrap store in a function for testing purposes
  30. const composeEnhancers =
  31. typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
  32. window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
  33. // Specify extension’s options like name, actionsBlacklist,
  34. actionsCreators, serialize...
  35. }) : compose;
  36.  
  37. const enhancer = composeEnhancers(
  38. applyMiddleware(thunk),
  39. // other store enhancers if any
  40. );
  41. const rootReducer = combineReducers({
  42. user: userReducer,
  43. game: gameReducer})
  44.  
  45. export const configureStore = () => {
  46. return createStore(rootReducer, enhancer);}
Add Comment
Please, Sign In to add comment